28 #ifndef TOON_INCLUDE_WLS_H 29 #define TOON_INCLUDE_WLS_H 31 #include <TooN/TooN.h> 32 #include <TooN/Cholesky.h> 33 #include <TooN/helpers.h> 45 template<
int DecompSize,
class DecompPrecision>
class Decomposition = Cholesky>
53 my_decomposition(size),
69 for(
int i=0; i<my_C_inv.num_rows(); i++){
80 for(
int i=0; i<my_C_inv.num_rows(); i++){
97 template<
class B2,
class P2>
101 for(
int r=0; r < my_C_inv.num_rows(); r++)
103 double Jw = weight * J[r];
104 my_vector[r] += m * Jw;
105 for(
int c=r; c < my_C_inv.num_rows(); c++)
106 my_C_inv[r][c] += Jw * J[c];
114 template<
class VB,
int S2,
class B2>
118 for(
int r=0; r < J.num_rows(); r++)
119 add_mJ(m[r], J[r], weight);
127 template<
int N,
class B1,
class B2,
class B3>
132 my_C_inv += temp * J.T();
133 my_vector += temp * m;
140 template<
int N,
class B1,
class B2,
class B3>
145 my_C_inv += temp * J;
146 my_vector += temp * m;
154 template<
int N,
typename B1>
157 const Precision weight = 1){
159 for(
int r=0; r < J1.size(); r++)
161 double Jw = weight * J1[r];
162 my_vector[r+index1] += m * Jw;
163 for(
int c = r; c < J1.size(); c++)
164 my_C_inv[r+index1][c+index1] += Jw * J1[c];
173 template<
int N,
int S1,
class P1,
class P2,
class P3,
class B1,
class B2,
class B3>
178 const int size1 = J1.num_cols();
179 my_C_inv.slice(index1, index1, size1, size1) += temp1 * J1;
180 my_vector.slice(index1, size1) += temp1 * m;
190 template<
int N,
int S1,
int S2,
class B1,
class B2,
class B3,
class B4>
198 const int size1 = J1.num_cols();
199 const int size2 = J2.num_cols();
200 my_C_inv.slice(index1, index1, size1, size1) += temp1 * J1;
201 my_C_inv.slice(index2, index2, size2, size2) += temp2 * J2;
202 my_C_inv.slice(index1, index2, size1, size2) += mixed;
203 my_C_inv.slice(index2, index1, size2, size1) += mixed.T();
204 my_vector.slice(index1, size1) += temp1 * m;
205 my_vector.slice(index2, size2) += temp2 * m;
213 for(
int r=1; r < my_C_inv.num_rows(); r++)
214 for(
int c=0; c < r; c++)
215 my_C_inv[r][c] = my_C_inv[c][r];
217 my_decomposition.compute(my_C_inv);
218 my_mu=my_decomposition.backsub(my_vector);
224 my_vector+=meas.my_vector;
225 my_C_inv += meas.my_C_inv;
243 Decomposition<Size,Precision> my_decomposition;
void add_prior(const Vector< Size, Precision, B2 > &v)
Applies a regularisation term with a different strength for each parameter value. ...
Definition: wls.h:78
void add_sparse_mJ_rows(const Vector< N, Precision, B1 > &m, const Matrix< N, S1, Precision, B2 > &J1, const int index1, const Matrix< N, S2, Precision, B3 > &J2, const int index2, const Matrix< N, N, Precision, B4 > &invcov)
Add multiple measurements at once with a sparse Jacobian (much, much more efficiently) ...
Definition: wls.h:191
Decomposition< Size, Precision > & get_decomposition()
Return the decomposition object used to compute .
Definition: wls.h:236
Matrix< Size, Size, Precision > & get_C_inv()
Returns the inverse covariance matrix.
Definition: wls.h:229
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
A vector.
Definition: vector.hh:126
Vector< Size, Precision > & get_vector()
Returns the vector .
Definition: wls.h:234
void add_prior(Precision val)
Applies a constant regularisation term.
Definition: wls.h:68
A matrix.
Definition: matrix.hh:105
void operator+=(const WLS &meas)
Combine measurements from two WLS systems.
Definition: wls.h:223
Vector< Size, Precision > & get_mu()
Returns the update. With no prior, this is the result of .
Definition: wls.h:232
const Vector< Size, Precision > & get_vector() const
Returns the vector .
Definition: wls.h:235
void add_mJ_rows(const Vector< N, Precision, B1 > &m, const Matrix< N, Size, Precision, B2 > &J, const Matrix< N, N, Precision, B3 > &invcov)
Add multiple measurements at once (much more efficiently)
Definition: wls.h:141
const Decomposition< Size, Precision > & get_decomposition() const
Return the decomposition object used to compute .
Definition: wls.h:237
void add_sparse_mJ(const Precision m, const Vector< N, Precision, B1 > &J1, const int index1, const Precision weight=1)
Add a single measurement at once with a sparse Jacobian (much, much more efficiently) ...
Definition: wls.h:155
WLS(int size=0)
Default constructor or construct with the number of dimensions for the Dynamic case.
Definition: wls.h:50
void clear()
Clear all the measurements and apply a constant regularisation term.
Definition: wls.h:60
void add_sparse_mJ_rows(const Vector< N, P1, B1 > &m, const Matrix< N, S1, P2, B2 > &J1, const int index1, const Matrix< N, N, P3, B3 > &invcov)
Add multiple measurements at once with a sparse Jacobian (much, much more efficiently) ...
Definition: wls.h:174
void add_mJ(Precision m, const Vector< Size, P2, B2 > &J, Precision weight=1)
Add a single measurement.
Definition: wls.h:98
void add_mJ(const Vector< N, Precision, B1 > &m, const Matrix< Size, N, Precision, B2 > &J, const Matrix< N, N, Precision, B3 > &invcov)
Add multiple measurements at once (much more efficiently)
Definition: wls.h:128
void compute()
Process all the measurements and compute the weighted least squares set of parameter values stores th...
Definition: wls.h:210
const Matrix< Size, Size, Precision > & get_C_inv() const
Returns the inverse covariance matrix.
Definition: wls.h:231
const Vector< Size, Precision > & get_mu() const
Returns the update. With no prior, this is the result of .
Definition: wls.h:233
Definition: size_mismatch.hh:103
double DefaultPrecision
All TooN classes default to using this precision for computations and storage.
Definition: TooN.h:315
void add_mJ(const Vector< S2, Precision, VB > &m, const Matrix< S2, Size, Precision, B2 > &J, Precision weight=1)
Add a several measurements measurement.
Definition: wls.h:115
void add_prior(const Matrix< Size, Size, Precision, B2 > &m)
Applies a whole-matrix regularisation term.
Definition: wls.h:89
Performs Gauss-Newton weighted least squares computation.
Definition: wls.h:46