Go to the documentation of this file.
32 namespace noiseModel {
40 template<
class MATRIX>
42 size_t n =
Ab.cols()-1;
43 Ab.middleCols(
j+1,
n-
j) -=
a * rd.segment(
j+1,
n-
j).transpose();
49 size_t m =
M.rows(),
n =
M.cols();
54 for (
i = 0;
i <
m;
i++)
56 for (
j =
i + 1;
j <
n;
j++)
65 for (
j = 0;
j <
n;
j++)
73 throw(
"Base::sigmas: sigmas() not implemented for this noise model");
77 double Base::squaredMahalanobisDistance(
const Vector&
v)
const {
85 size_t m =
R.rows(),
n =
R.cols();
87 throw invalid_argument(
"Gaussian::SqrtInformation: R not square");
91 return Diagonal::Sigmas(
diagonal->array().inverse(),
true);
94 return std::make_shared<Gaussian>(
R.rows(),
R);
99 size_t m = information.rows(),
n = information.cols();
101 throw invalid_argument(
"Gaussian::Information: R not square");
102 std::optional<Vector>
diagonal = {};
106 return Diagonal::Precisions(*
diagonal,
true);
110 return std::make_shared<Gaussian>(
n,
R);
117 size_t m = covariance.rows(),
n = covariance.cols();
119 throw invalid_argument(
"Gaussian::Covariance: covariance not square");
120 std::optional<Vector> variances = {};
124 return Diagonal::Variances(*variances,
true);
130 return Information(covariance.inverse(),
false);
142 if (
p ==
nullptr)
return false;
143 if (
typeid(*
this) !=
typeid(*p))
return false;
151 Matrix I = Matrix::Identity(
R.rows(),
R.cols());
155 return Rinv * Rinv.transpose();
179 void Gaussian::WhitenInPlace(
Matrix&
H)
const {
192 gttic(Gaussian_noise_model_QR);
196 size_t m =
Ab.rows(),
n =
Ab.cols()-1;
197 size_t maxRank =
min(
m,
n);
205 return noiseModel::Unit::Create(maxRank);
208 void Gaussian::WhitenSystem(vector<Matrix>& A,
Vector&
b)
const {
209 for(
Matrix& Aj:
A) { WhitenInPlace(Aj); }
231 Matrix Gaussian::information()
const {
return R().transpose() *
R(); }
234 double Gaussian::logDetR()
const {
236 R().diagonal().unaryExpr([](
double x) {
return log(
x); }).sum();
246 return -2.0 * logDetR();
250 double Gaussian::negLogConstant()
const {
256 constexpr
double log2pi = 1.8378770664093454835606594728112;
258 return 0.5 *
n * log2pi - logDetR();
277 return (smart && (variances.array() == variances(0)).
all())
286 if (
n == 0)
goto full;
289 if ((
sigmas.array() < 1
e-8).any()) {
393 assert (
b.size()==
a.size());
395 for(
size_t i = 0;
i <
n;
i++ ) {
396 const double& ai =
a(
i), bi =
b(
i);
397 c(
i) = (bi==0.0) ? ai : ai/bi;
413 const Vector& variances) {
421 const Vector& precisions) {
463 for (
size_t i=0;
i<
dim(); ++
i)
476 template <
typename VECTOR>
478 std::optional<size_t> constraint_row;
481 double max_element = 1
e-9;
482 for (
size_t i = 0;
i <
m;
i++) {
486 if (abs_ai > max_element) {
487 max_element = abs_ai;
491 return constraint_row;
495 static const double kInfinity = std::numeric_limits<double>::infinity();
498 size_t m =
Ab.rows();
499 const size_t n =
Ab.cols() - 1;
500 const size_t maxRank =
min(
m,
n);
503 typedef std::tuple<size_t, Matrix, double> Triple;
514 for (
size_t j = 0;
j <
n; ++
j) {
521 if (constraint_row) {
526 rd =
Ab.row(*constraint_row);
532 if (
Rd.size() >= maxRank)
538 if (*constraint_row !=
m) {
539 Ab.row(*constraint_row) =
Ab.row(
m);
540 weights(*constraint_row) = weights(
m);
546 a_reduced *= (1.0/rd(0,
j));
549 Ab.block(0,
j + 1,
m,
n -
j).noalias() -= a_reduced * rd.middleCols(
j + 1,
n -
j);
558 for (
size_t i = 0;
i <
m;
i++) {
561 pseudo[
i] = weights[
i] * ai;
572 rd.block(0,
j + 1, 1,
n -
j) = pseudo.transpose() *
Ab.block(0,
j + 1,
m,
n -
j);
584 if (
Rd.size() >= maxRank)
588 Ab.block(0,
j + 1,
m,
n -
j).noalias() -=
a * rd.middleCols(
j + 1,
n -
j);
599 for (
const Triple&
t:
Rd) {
600 const size_t&
j = std::get<0>(
t);
601 const Matrix& rd = std::get<1>(
t);
605 Ab.block(
i,
j, 1,
n + 1 -
j) = rd.block(0,
j, 1,
n + 1 -
j);
629 cout <<
"isotropic dim=" <<
dim() <<
" sigma=" <<
sigma_ << endl;
674 cout <<
name <<
"unit (" <<
dim_ <<
") " << endl;
696 if (
p ==
nullptr)
return false;
726 return noise_->unweightedWhiten(
v);
static shared_ptr MixedVariances(const Vector &mu, const Vector &variances)
Vector unwhiten(const Vector &v) const override
Unwhiten an error vector.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
static void fix(const Vector &sigmas, Vector &precisions, Vector &invsigmas)
Vector whiten(const Vector &v) const override
Whiten an error vector.
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Annotation for function names.
EIGEN_DONT_INLINE void llt(const Mat &A, const Mat &B, Mat &C)
Expression of a fixed-size or dynamic-size block.
const EIGEN_DEVICE_FUNC InverseReturnType inverse() const
const RobustModel::shared_ptr & robust() const
Return the contained robust error function.
Matrix Whiten(const Matrix &H) const override
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static shared_ptr MixedSigmas(const Vector &mu, const Vector &sigmas)
std::shared_ptr< Base > shared_ptr
Vector unweightedWhiten(const Vector &v) const override
static shared_ptr Precisions(const Vector &precisions, bool smart=true)
std::optional< size_t > check_if_constraint(VECTOR a, const Vector &invsigmas, size_t m)
static shared_ptr Create(const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
void print(const std::string &name) const override
const Vector & invsigmas() const
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
void print(const std::string &name) const override
void print(const std::string &name) const override
static shared_ptr Variance(size_t dim, double variance, bool smart=true)
const EIGEN_DEVICE_FUNC LogReturnType log() const
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
void updateAb(MATRIX &Ab, int j, const Vector &a, const Vector &rd)
void WhitenInPlace(Matrix &H) const override
size_t dim() const
Dimensionality.
Constrained(const Vector &mu, const Vector &sigmas)
virtual void WhitenSystem(Vector &b) const
std::shared_ptr< Gaussian > shared_ptr
Diagonal::shared_ptr QR(Matrix &Ab) const override
void diagonal(const MatrixType &m)
virtual double logDetR() const override
Compute the log of |R|. Used for computing log(|Σ|)
void whitenInPlace(Vector &v) const override
void print(const std::string &name) const override
static const double sigma
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
double squaredMahalanobisDistance(const Vector &v) const override
Squared Mahalanobis distance v'*R'*R*v = <R*v,R*v>
Vector sigmas() const override
Calculate standard deviations.
Vector mu_
Penalty function weight - needs to be large enough to dominate soft constraints.
const Vector & mu() const
Access mu as a vector.
void print(const Matrix &A, const string &s, ostream &stream)
Robust()
Default Constructor for serialization.
std::shared_ptr< Base > shared_ptr
void vector_scale_inplace(const Vector &v, Matrix &A, bool inf_mask)
double precision(size_t i) const
const EIGEN_DEVICE_FUNC SquareReturnType square() const
static const Eigen::internal::all_t all
double logDeterminant(const typename BAYESTREE::sharedClique &clique)
static shared_ptr Create(size_t dim)
noiseModel::Diagonal::shared_ptr SharedDiagonal
virtual double logDetR() const override
Compute the log of |R|. Used for computing log(|Σ|)
double squaredMahalanobisDistance(const Vector &v) const override
Squared Mahalanobis distance v'*R'*R*v = <R*v,R*v>
Matrix Whiten(const Matrix &H) const override
Vector whiten(const Vector &v) const override
Calculates error vector with weights applied.
const RobustModel::shared_ptr robust_
robust error function used
double squaredMahalanobisDistance(const Vector &v) const override
double weight(const Vector &v) const override
std::optional< Vector > checkIfDiagonal(const Matrix &M)
const Vector & precisions() const
const NoiseModel::shared_ptr noise_
noise model used
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
void inplace_QR(Matrix &A)
Vector whiten(const Vector &v) const override
Whiten an error vector.
Vector backSubstituteUpper(const Matrix &U, const Vector &b, bool unit)
void WhitenInPlace(Matrix &H) const override
Matrix vector_scale(const Vector &v, const Matrix &A, bool inf_mask)
virtual double logDetR() const override
Compute the log of |R|. Used for computing log(|Σ|)
ptrdiff_t DenseIndex
The index type for Eigen objects.
std::shared_ptr< Diagonal > shared_ptr
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
Matrix Whiten(const Matrix &H) const override
std::shared_ptr< Robust > shared_ptr
static shared_ptr MixedPrecisions(const Vector &mu, const Vector &precisions)
void print(const std::string &name) const override
Array< int, Dynamic, 1 > v
bool constrained(size_t i) const
Return true if a particular dimension is free or constrained.
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
std::shared_ptr< Isotropic > shared_ptr
const NoiseModel::shared_ptr & noise() const
Return the contained noise model.
void WhitenInPlace(Matrix &H) const override
std::shared_ptr< Constrained > shared_ptr
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Jet< T, N > sqrt(const Jet< T, N > &f)
bool equals(const Base &expected, double tol=1e-9) const override
Rot2 R(Rot2::fromAngle(0.1))
Vector unwhiten(const Vector &v) const override
Unwhiten an error vector.
static shared_ptr Variances(const Vector &variances, bool smart=true)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Matrix< RealScalar, Dynamic, Dynamic > M
gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:02:33