2010-01-17 02:39:39 +08:00
|
|
|
/*
|
|
|
|
* NoiseModel.cpp
|
|
|
|
*
|
|
|
|
* Created on: Jan 13, 2010
|
2010-01-17 08:37:34 +08:00
|
|
|
* Author: Richard Roberts
|
|
|
|
* Author: Frank Dellaert
|
2010-01-17 02:39:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NoiseModel.h"
|
2010-01-17 08:37:34 +08:00
|
|
|
|
2010-01-17 09:28:15 +08:00
|
|
|
namespace ublas = boost::numeric::ublas;
|
|
|
|
typedef ublas::matrix_column<Matrix> column;
|
|
|
|
|
2010-01-17 08:37:34 +08:00
|
|
|
namespace gtsam {
|
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
Vector GaussianNoiseModel::whiten(const Vector& v) const {
|
|
|
|
return sqrt_information_ * v;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector GaussianNoiseModel::unwhiten(const Vector& v) const {
|
|
|
|
return backSubstituteUpper(sqrt_information_, v);
|
|
|
|
}
|
|
|
|
|
2010-01-17 23:10:10 +08:00
|
|
|
// functional
|
2010-01-17 11:29:23 +08:00
|
|
|
Matrix GaussianNoiseModel::Whiten(const Matrix& H) const {
|
2010-01-17 23:10:10 +08:00
|
|
|
size_t m = H.size1(), n = H.size2();
|
|
|
|
Matrix W(m, n);
|
2010-01-17 11:29:23 +08:00
|
|
|
for (int j = 0; j < n; j++) {
|
|
|
|
Vector wj = whiten(column(H, j));
|
|
|
|
for (int i = 0; i < m; i++)
|
|
|
|
W(i, j) = wj(i);
|
|
|
|
}
|
|
|
|
return W;
|
2010-01-17 09:28:15 +08:00
|
|
|
}
|
|
|
|
|
2010-01-17 23:10:10 +08:00
|
|
|
// in place
|
|
|
|
void GaussianNoiseModel::WhitenInPlace(Matrix& H) const {
|
|
|
|
size_t m = H.size1(), n = H.size2();
|
|
|
|
for (int j = 0; j < n; j++) {
|
|
|
|
Vector wj = whiten(column(H, j));
|
|
|
|
for (int i = 0; i < m; i++)
|
|
|
|
H(i, j) = wj(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
// TODO: can we avoid calling reciprocal twice ?
|
2010-01-17 08:37:34 +08:00
|
|
|
Diagonal::Diagonal(const Vector& sigmas) :
|
2010-01-18 01:47:23 +08:00
|
|
|
GaussianNoiseModel(diag(reciprocal(sigmas))),
|
|
|
|
invsigmas_(reciprocal(sigmas)), sigmas_(sigmas) {
|
2010-01-17 08:37:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector Diagonal::whiten(const Vector& v) const {
|
|
|
|
return emul(v, invsigmas_);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector Diagonal::unwhiten(const Vector& v) const {
|
|
|
|
return emul(v, sigmas_);
|
|
|
|
}
|
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
/* ************************************************************************* */
|
2010-01-17 08:37:34 +08:00
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
Vector Isotropic::whiten(const Vector& v) const {
|
|
|
|
return v * invsigma_;
|
2010-01-17 08:37:34 +08:00
|
|
|
}
|
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
Vector Isotropic::unwhiten(const Vector& v) const {
|
|
|
|
return v * sigma_;
|
2010-01-17 08:37:34 +08:00
|
|
|
}
|
|
|
|
|
2010-01-18 01:47:23 +08:00
|
|
|
/* ************************************************************************* */
|
2010-01-17 08:37:34 +08:00
|
|
|
} // gtsam
|