57 using namespace StringUtils;
61 SRIleastSquares::SRIleastSquares() { defaults(); }
65 SRIleastSquares::SRIleastSquares(
const unsigned int N)
75 SRIleastSquares::SRIleastSquares(
const Namelist& NL)
97 MatrixException me(
"Invalid input dimensions: R is " +
98 asString<int>(Rin.
rows()) +
"x" +
99 asString<int>(Rin.
cols()) +
", Z has length " +
100 asString<int>(Zin.
size()) +
", and NL has length " +
101 asString<int>(NLin.
size()));
271 int SRIleastSquares::dataUpdate(
275 const int M = D.
size();
276 const int N = R.rows();
279 cout <<
"\nSRIleastSquares::leastSquaresUpdate : M,N are " << M <<
","
286 MatrixException me(
"Called with zero-sized SRIleastSquares");
289 if (doLinearize && M < N)
292 string(
"When linearizing, problem must not be underdetermined:\n") +
293 string(
" data dimension is ") +
asString(M) +
294 string(
" while state dimension is ") +
asString(N));
297 if (doSequential && R.rows() != X.
size())
300 "Sequential problem has inconsistent dimensions:\n SRI is " +
301 asString<int>(R.rows()) +
"x" + asString<int>(R.cols()) +
302 " while X has length " + asString<int>(X.
size()));
305 if (doWeight && doRobust)
307 MatrixException me(
"Cannot have doWeight and doRobust both true.");
336 if (doSequential && numberBatches != 0)
344 if ((
int)X.
size() != N)
354 rmsConvergence = 0.0;
355 numberIterations = 0;
364 LSF(NominalX, f, Partials);
370 cout <<
"\nSRIleastSquares::leastSquaresUpdate :";
371 if (doLinearize || doRobust)
373 cout <<
" Iteration " << numberIterations;
379 cout <<
" Pre-fit data residuals: " << fixed << setprecision(6)
387 for (i = 0; i < M; i++)
388 MeasCov(i, i) = 1.0 / (Wts(i) * Wts(i));
392 if (numberIterations > 1)
401 cout <<
" Meas Cov:";
402 for (i = 0; i < M; i++)
403 cout <<
" " << MeasCov(i, i);
405 cout <<
" Partials:\n" << Partials << endl;
414 if (doRobust || doWeight)
426 if (doRobust || doWeight)
434 cout <<
" Updated information matrix\n"
436 cout <<
" Updated information vector\n"
443 getStateAndCovariance(Xsol, Cov, &small, &big);
445 catch (SingularMatrixException& sme)
450 conditionNum = big / small;
453 cout <<
" Condition number: " << scientific << conditionNum
455 cout <<
" Post-fit data residuals: " << fixed << setprecision(6)
468 cout << LXsol << endl;
472 if (!doLinearize && !doRobust)
480 rmsConvergence =
RMS(Xsol - NominalX);
483 cout <<
" RMS convergence : " << scientific << rmsConvergence
492 LSF(Xsol, f, Partials);
504 for (i = 0; i < M; i++)
521 rmsConvergence =
RMS(OldWts - Wts);
524 cout <<
" Convergence: " << scientific << setprecision(3)
525 << rmsConvergence << endl;
530 if (rmsConvergence > divergenceLimit)
534 if (numberIterations >= iterationsLimit)
549 if (numberIterations > 1 && rmsConvergence < convergenceLimit)
569 cout <<
"Return from SRIleastSquares::leastSquaresUpdate\n\n";
604 NL += string(
"State");
606 A = srif.
R || srif.
Z;
616 void SRIleastSquares::zeroAll()
628 void SRIleastSquares::reset(
const int N)
632 if (N > 0 && N != (
int)R.rows())