Additional unit test
parent
10d19c6832
commit
89e6e27301
|
|
@ -49,7 +49,7 @@ void updateAb(MATRIX& Ab, int j, const Vector& a, const Vector& rd) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// check *above the diagonal* for non-zero entries
|
// check *above the diagonal* for non-zero entries
|
||||||
static boost::optional<Vector> checkIfDiagonal(const Matrix M) {
|
boost::optional<Vector> checkIfDiagonal(const Matrix M) {
|
||||||
size_t m = M.rows(), n = M.cols();
|
size_t m = M.rows(), n = M.cols();
|
||||||
// check all non-diagonal entries
|
// check all non-diagonal entries
|
||||||
bool full = false;
|
bool full = false;
|
||||||
|
|
@ -82,6 +82,20 @@ Gaussian::shared_ptr Gaussian::SqrtInformation(const Matrix& R, bool smart) {
|
||||||
else return shared_ptr(new Gaussian(R.rows(),R));
|
else return shared_ptr(new Gaussian(R.rows(),R));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
Gaussian::shared_ptr Gaussian::Information(const Matrix& M, bool smart) {
|
||||||
|
size_t m = M.rows(), n = M.cols();
|
||||||
|
if (m != n) throw invalid_argument("Gaussian::Information: R not square");
|
||||||
|
boost::optional<Vector> diagonal = boost::none;
|
||||||
|
if (smart)
|
||||||
|
diagonal = checkIfDiagonal(M);
|
||||||
|
if (diagonal) return Diagonal::Precisions(*diagonal, true);
|
||||||
|
else {
|
||||||
|
Matrix R = RtR(M);
|
||||||
|
return shared_ptr(new Gaussian(R.rows(), R));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Gaussian::shared_ptr Gaussian::Covariance(const Matrix& covariance, bool smart) {
|
Gaussian::shared_ptr Gaussian::Covariance(const Matrix& covariance, bool smart) {
|
||||||
size_t m = covariance.rows(), n = covariance.cols();
|
size_t m = covariance.rows(), n = covariance.cols();
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,13 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
static shared_ptr SqrtInformation(const Matrix& R, bool smart = true);
|
static shared_ptr SqrtInformation(const Matrix& R, bool smart = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Gaussian noise model created by specifying an information matrix.
|
||||||
|
* @param M The information matrix
|
||||||
|
* @param smart check if can be simplified to derived class
|
||||||
|
*/
|
||||||
|
static shared_ptr Information(const Matrix& M, bool smart = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Gaussian noise model created by specifying a covariance matrix.
|
* A Gaussian noise model created by specifying a covariance matrix.
|
||||||
* @param covariance The square covariance Matrix
|
* @param covariance The square covariance Matrix
|
||||||
|
|
@ -865,6 +872,9 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function
|
||||||
|
boost::optional<Vector> checkIfDiagonal(const Matrix M);
|
||||||
|
|
||||||
} // namespace noiseModel
|
} // namespace noiseModel
|
||||||
|
|
||||||
/** Note, deliberately not in noiseModel namespace.
|
/** Note, deliberately not in noiseModel namespace.
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,17 @@ TEST(NoiseModel, SmartSqrtInformation2 )
|
||||||
EXPECT(assert_equal(*expected,*actual));
|
EXPECT(assert_equal(*expected,*actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(NoiseModel, SmartInformation )
|
||||||
|
{
|
||||||
|
bool smart = true;
|
||||||
|
gtsam::SharedGaussian expected = Unit::Isotropic::Variance(3,2);
|
||||||
|
Matrix M = 0.5*eye(3);
|
||||||
|
EXPECT(checkIfDiagonal(M));
|
||||||
|
gtsam::SharedGaussian actual = Gaussian::Information(M, smart);
|
||||||
|
EXPECT(assert_equal(*expected,*actual));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(NoiseModel, SmartCovariance )
|
TEST(NoiseModel, SmartCovariance )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue