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);
194 static const bool debug =
false;
198 size_t m =
Ab.rows(),
n =
Ab.cols()-1;
199 size_t maxRank =
min(
m,
n);
214 return noiseModel::Unit::Create(maxRank);
217 void Gaussian::WhitenSystem(vector<Matrix>& A,
Vector&
b)
const {
218 for(
Matrix& Aj:
A) { WhitenInPlace(Aj); }
240 Matrix Gaussian::information()
const {
return R().transpose() *
R(); }
243 double Gaussian::logDetR()
const {
245 R().diagonal().unaryExpr([](
double x) {
return log(
x); }).sum();
255 return -2.0 * logDetR();
259 double Gaussian::negLogConstant()
const {
265 constexpr
double log2pi = 1.8378770664093454835606594728112;
267 return 0.5 *
n * log2pi - logDetR();
286 return (smart && (variances.array() == variances(0)).
all())
295 if (
n == 0)
goto full;
298 if ((
sigmas.array() < 1
e-8).any()) {
402 assert (
b.size()==
a.size());
404 for(
size_t i = 0;
i <
n;
i++ ) {
405 const double& ai =
a(
i), bi =
b(
i);
406 c(
i) = (bi==0.0) ? ai : ai/bi;
422 const Vector& variances) {
430 const Vector& precisions) {
472 for (
size_t i=0;
i<
dim(); ++
i)
485 template <
typename VECTOR>
487 std::optional<size_t> constraint_row;
490 double max_element = 1
e-9;
491 for (
size_t i = 0;
i <
m;
i++) {
495 if (abs_ai > max_element) {
496 max_element = abs_ai;
500 return constraint_row;
504 static const double kInfinity = std::numeric_limits<double>::infinity();
507 size_t m =
Ab.rows();
508 const size_t n =
Ab.cols() - 1;
509 const size_t maxRank =
min(
m,
n);
512 typedef std::tuple<size_t, Matrix, double> Triple;
523 for (
size_t j = 0;
j <
n; ++
j) {
530 if (constraint_row) {
535 rd =
Ab.row(*constraint_row);
541 if (
Rd.size() >= maxRank)
547 if (*constraint_row !=
m) {
548 Ab.row(*constraint_row) =
Ab.row(
m);
549 weights(*constraint_row) = weights(
m);
555 a_reduced *= (1.0/rd(0,
j));
558 Ab.block(0,
j + 1,
m,
n -
j).noalias() -= a_reduced * rd.middleCols(
j + 1,
n -
j);
567 for (
size_t i = 0;
i <
m;
i++) {
570 pseudo[
i] = weights[
i] * ai;
581 rd.block(0,
j + 1, 1,
n -
j) = pseudo.transpose() *
Ab.block(0,
j + 1,
m,
n -
j);
593 if (
Rd.size() >= maxRank)
597 Ab.block(0,
j + 1,
m,
n -
j).noalias() -=
a * rd.middleCols(
j + 1,
n -
j);
608 for (
const Triple&
t:
Rd) {
609 const size_t&
j = std::get<0>(
t);
610 const Matrix& rd = std::get<1>(
t);
614 Ab.block(
i,
j, 1,
n + 1 -
j) = rd.block(0,
j, 1,
n + 1 -
j);
638 cout <<
"isotropic dim=" <<
dim() <<
" sigma=" <<
sigma_ << endl;
683 cout <<
name <<
"unit (" <<
dim_ <<
") " << endl;
705 if (
p ==
nullptr)
return false;
735 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 constexpr bool debug
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 Sun Dec 22 2024 04:12:23