25 #include "LeastSquares.hh"
27 #include <Base/Common/BIASpragma.hh>
38 _ReduceToATA=ReduceToATA;
39 _SolutionSize=SolutionSize;
40 _ATA.newsize(_SolutionSize, _SolutionSize);
41 _Weight.newsize(_SolutionSize, _SolutionSize);
42 _ATb.newsize(_SolutionSize);
49 BIASERR(
"only the overloaded function in the derived class can be used");
55 BIASERR(
"only the overloaded function in the derived class can be used");
62 BIASERR(
"only the overloaded function in the derived class can be used");
69 BIASERR(
"only the overloaded function in the derived class can be used");
82 BIASDOUT(D_LS_MATRIXES,
"A: "<<A<<
"\nb: "<<b);
88 BIASDOUT(D_LS_RED_MATRIXES,
"_ATA: "<<_ATA<<
"\n_ATb: "<<_ATb);
99 BIASERR(
"unfinished");
107 BIASDOUT(D_LS_MATRIXES,
"A: "<<A<<
"\nb: "<<b);
112 for (
unsigned i=0; i<_SolutionSize; i++){
119 BIASDOUT(D_LS_RED_MATRIXES,
"_ATA: "<<_ATA<<
"\n_ATb: "<<_ATb);
124 _Weight[i][i]=1.0/weights[i];
135 BIASERR(
"unfinished");
175 BIASDOUT(D_LS_MATRIXES,
"A: "<<A<<
"\nb: "<<b);
179 BIASDOUT(D_LS_RED_MATRIXES,
"_ATA: "<<_ATA<<
"\n_ATb: "<<_ATb);
180 if (_svd.Compute(_ATA)!=0){
185 d=_svd.GetVT() * _ATb;
186 BIASDOUT(D_LS_SVD,
"_ATA: "<<_ATA<<
"\nd: "<<d<<
"\nS: "<<S);
188 z[i]=(fabs(S[i])>DEFAULT_DOUBLE_ZERO_THRESHOLD)?d[i]/S[i]:0.0;
197 BIASDOUT(D_LS_MATRIXES,
"A: "<<A);
198 if (x.
size()!=(int)_SolutionSize)
204 BIASDOUT(D_LS_RED_MATRIXES,
"_ATA: "<<_ATA);
206 BIASERR(
"error in svd");
209 for (
unsigned i=0; i<_SolutionSize; i++){
210 x[i]=_VT[_SolutionSize-1][i];
214 BIASERR(
"error in svd");
217 for (
unsigned i=0; i<_SolutionSize; i++){
218 x[i]=_VT[_SolutionSize-1][i];
228 BIASERR(
"unfinished");
235 BIASDOUT(D_LS_MATRIXES,
"A: "<<A<<
"\nweights: "<<weights);
236 if (x.
size()!=(int)_SolutionSize)
240 for (
unsigned i=0; i<_SolutionSize; i++){
247 BIASDOUT(D_LS_RED_MATRIXES,
"_ATA: "<<_ATA);
249 BIASERR(
"error in svd");
252 for (
unsigned i=0; i<_SolutionSize; i++){
253 x[i]=_VT[_SolutionSize-1][i];
257 BIASERR(
"error in svd");
260 for (
unsigned i=0; i<_SolutionSize; i++){
261 x[i]=_VT[_SolutionSize-1][i];
BIAS::Vector< double > Lapack_LLS_QR_linear_solve(const BIAS::Matrix< double > &A, const BIAS::Vector< double > &b, int &res)
linear least squares solves |Ax-b|=min res=0 on success, anything else rudimentary tested (woelk) ...
virtual int Solve(Matrix< double > &A, Vector< double > &b, Vector< double > &x)
Solve linear equation system A*x = b using linear least squares, i.e.
virtual int WeightedSolve(Matrix< double > &A, Vector< double > &b, Vector< double > &weights, Vector< double > &x)
Solve linear equation system A*x = b using weighted linear least squares, i.e.
Subscript num_cols() const
Matrix< T > Transpose() const
transpose function, storing data destination matrix
virtual int WeightedSolve(Matrix< double > &A, Vector< double > &b, Vector< double > &weights, Vector< double > &x)
Solve linear equation system A*x = b using weighted linear least squares, i.e.
BIAS::Vector< double > Lapack_WLLS_solve(const BIAS::Matrix< double > &A, const BIAS::Vector< double > &b, const BIAS::Matrix< double > &B, int &res)
weighted linear least squares solves |B^-1(b-Ax)|=min res=0 on success, anything else rudimentary tes...
Vector< T > & newsize(Subscript N)
virtual int WeightedSolve(Matrix< double > &A, Vector< double > &b, Vector< double > &weights, Vector< double > &x)
Solve linear equation system A*x = b using weighted linear least squares, i.e.
virtual int Solve(Matrix< double > &A, Vector< double > &b, Vector< double > &x)
LeastSquaresSVD.
int General_singular_value_decomposition(char jobu, char jobvt, const BIAS::Matrix< double > &A, BIAS::Vector< double > &ret_S, BIAS::Matrix< double > &ret_U, BIAS::Matrix< double > &ret_VT)
solve general eigenproblem.
void Mult(const Matrix< T > &arg, Matrix< T > &result) const
matrix multiplication, result is not allocated
Subscript num_rows() const
virtual int Solve(Matrix< double > &A, Vector< double > &b, Vector< double > &x)
LeastSquaresLapack.
int Init(unsigned SolutionSize, bool ReduceToATA=true)
Initialize least squares solver.
void ScaleRow(int NoRow, T scale)
Scales row NoRow with scale.