FunctionChi-square merit function.
Syntax C/C++#include <VFstd.h>
float VF_chi2( fVector X, fVector Y, fVector InvVar, ui size );
float VF_chi2wSaturation( fVector X, fVector Y, fVector InvVar, ui size );
C++ VecObj#include <OptiVec.h>
T vector<T>::chi2( const vector<T>& Y, const vector<T>& InvVar );
T vector<T>::chi2wSaturation( const vector<T>& Y, const vector<T>& InvVar );
Pascal/Delphiuses VFstd;
function VF_chi2( X, Y, InvVar:fVector; size:UIntSize ): Single;
function VF_chi2wSaturation( X, Y, InvVar:fVector; size:UIntSize ): Single;
CUDA function C/C++#include <cudaVFstd.h>
int cudaVF_chi2( float *h_RetVal, fVector d_X, fVector d_Y, fVector d_InvVar, ui size );
int cusdVF_chi2( float *d_RetVal, fVector d_X, fVector d_Y, fVector d_InvVar, ui size );
float VFcu_chi2( fVector h_X, fVector h_Y, fVector h_InvVar, ui size );
CUDA function Pascal/Delphiuses VFstd;
function cudaVF_chi2( var h_RetVal:Single; d_X, d_Y, d_InvVar:fVector; size:UIntSize ): IntBool;
function cusdVF_chi2( d_RetVal:PSingle; d_X, d_Y, d_InvVar:fVector; size:UIntSize ): IntBool;
function VFcu_chi2( h_X, h_Y, h_InvVar:fVector; size:UIntSize ): Single;
Descriptionc2 = sum( 1/si2 * (Xi - Yi)2 ).
The c2 (chi-square) merit function is most often used to judge the quality of a fit. One vector (either X or Y) represents experimental values that are obtained with individual standard deviations sigmai, the other contains the values predicted on the basis of a theory or a model. If the experimental data are "normally" distributed, and if s (sigma) is the correct measure for the quality of these data, then c2 is a measure for the quality of the fit. Rather than the standard deviations themselves, the routine needs the inverse of their squares (i.e., the inverse of the variances) to be passed as the vector InvVar.

V?_chi2wSaturation is almost identical to V?_chi2, except for the treatment of infinities and NAN values. While V?_chi2 may overflow to INF and will return NAN, if any input element is a NAN, V?_chi2wSaturation will saturate possible overflow into HUGE_VAL and treats input values of ±NAN as ±HUGE_VAL. Thereby, it becomes most suitable for use inside the nonlinear fitting routines. If the fitting routine needs the figure-of-merit for a parameter set, any bad parameter set should give the feedback that the guess was far off; you do not want to raise an exception or crash the programme here.

Error handlingnone
Return valuechi2 merit function.
See alsoVF_meanwW,   VF_varianceVwW,   VF_varianceV,   VF_varianceCwW,   VF_chiabs,   VF_square,   VF_inv,   VF_linregress

VectorLib Table of Contents  OptiVec home