1 #include "GaussHelmert.hh"
3 #include <Base/Math/Vector.hh>
4 #include <Base/Math/Matrix.hh>
5 #include <MathAlgo/SVD.hh>
13 :
Debug(), MaxNumIter_(40), Precision_(1e-8)
25 const int N = (int)observations.
size();
27 double sigma_2_hat = 1.0;
36 A = GetA_(l_hat, x_hat);
37 B = GetB_(l_hat, x_hat);
47 const int R = G + Hn - U;
49 Matrix<double> Weight, WeightInverse, ATWeightInverse, ATWeightInverseA;
51 Vector<double> w_g, w_h, ATWeightInverse_w_g, normal_vector(Hn+U), x_mu;
58 A = GetA_(l_hat, x_hat);
59 B = GetB_(l_hat, x_hat);
62 ComputeNormalSystem_(A, B, H, Sigma_ll, x_hat, l_hat, v_hat,
63 normal_matrix, normal_vector);
66 if ((res = svd.
Solve(normal_matrix, normal_vector, x_mu))!=0){
67 BIASERR(
"error solving normal equation "<<res);
71 for (
int r=0; r<U; r++){
72 delta_x_hat[r] = x_mu[r];
74 for (
int r=U; r<U+Hn; r++){
79 lambda = WeightInverse * ( A * delta_x_hat - w_g );
82 v_hat = -1.0 * Sigma_ll * B * lambda;
88 sigma_2_hat = v_hat.
ScalarProduct(Sigma_ll_plus * v_hat) / (double)R;
90 Sigma_ll += sigma_2_hat * Sigma_ll;
91 Sigma_ll_plus = svd.
Invert(Sigma_ll);
95 }
while (num_iter<MaxNumIter_ && sigma_2_hat>Precision_);
98 ComputeNormalSystem_(A, B, H, Sigma_ll, x_hat, l_hat, v_hat,
99 normal_matrix, normal_vector);
101 for (
int r=0; r<U; r++){
102 for (
int c=0; c<U; c++){
103 cov[r][c] = tmp_cov[r][c] * sigma_2_hat;
107 observations = l_hat;
120 Matrix<double> Weight, WeightInverse, ATWeightInverse, ATWeightInverseA, HT;
130 WeightInverse = svd.
Invert(Weight);
132 ATWeightInverse = A.
Transpose() * WeightInverse;
133 ATWeightInverseA = ATWeightInverse * A;
136 w_g = -1.0 * g_(l_hat, x_hat) - B.Transpose() * v_hat;
137 w_h = -1.0 * h_(x_hat);
138 ATWeightInverse_w_g = ATWeightInverse * w_g;
143 for (
int r=0; r<U; r++){
144 normal_vec[r] = ATWeightInverse_w_g[r];
146 for (
int r=U; r<U+Hn; r++){
147 normal_vec[r] = w_h[r-U];
151 for (
int r=0; r<U; r++){
152 for (
int c=0; c<U; c++){
153 normal_matrix[r][c] = ATWeightInverseA[r][c];
156 for (
int r=0; r<U; r++){
157 for (
int c=U; c<U+Hn; c++){
158 normal_matrix[r][c] = H[r][c-U];
161 for (
int r=U; r<U+Hn; r++){
162 for (
int c=0; c<U; c++){
163 normal_matrix[r][c] = HT[r-U][c];
T ScalarProduct(const Vector< T > &argvec) const
scalar product (inner product) of two vectors returning a scalr
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Subscript num_cols() const
Vector< double > Solve(const Vector< double > &y) const
Matrix< T > Transpose() const
transpose function, storing data destination matrix
void SetZero()
equivalent to matrix call
void SetZero()
Sets all values to zero.
int Solve(BIAS::Vector< double > &observations, const BIAS::Matrix< double > &obs_cov, BIAS::Vector< double > &x, BIAS::Matrix< double > &cov)
Matrix< double > Invert()
returns pseudoinverse of A = U * S * V^T A^+ = V * S^+ * U^T
GaussHelmert()
protected constructor to prohibit instantiation of class
Subscript num_rows() const
void ComputeNormalSystem_(const Matrix< double > &A, const Matrix< double > &B, const Matrix< double > &H, const Matrix< double > &Sigma_ll, const Vector< double > &x_hat, const Vector< double > &l_hat, const Vector< double > &v_hat, Matrix< double > &normal_matrix, Vector< double > &normal_vector)