OpenCVcvSolve
可以解决这样的线性最小二乘问题:
// model: y = a1*x1 + a2*x2 + a3
CvMat *y = cvCreateMat(N, 1, CV_64FC1);
CvMat *X = cvCreateMat(N, 3, CV_64FC1);
CvMat *coeff = cvCreateMat(3, 1, CV_64FC1);
// fill vector y and matrix X
for (int i=0; i<N; ++i)
{
cvmSet(y, i, 0, my_y_value(i) );
cvmSet(X, i, 0, my_x1_value(i) );
cvmSet(X, i, 1, my_x2_value(i) );
cvmSet(X, i, 2, 1 );
}
cvSolve(X, y, coeff, CV_SVD);
// now coeff contains a1, a2, a3
但是,我想对我的数据点应用不同的权重。如何应用权重?