25 #pragma GCC diagnostic push 26 #pragma GCC diagnostic ignored "-Wunused-variable" 29 #pragma GCC diagnostic pop 45 GaussianConditional::GaussianConditional(
62 :
BaseFactor(key, R, parent1, S, parent2, T, d, sigmas),
70 const Matrix R = Matrix::Identity(mu.size(), mu.size());
80 const Matrix R = Matrix::Identity(b.size(), b.size());
92 const Matrix R = Matrix::Identity(b.size(), b.size());
104 cout << formatter(*it) << (nrFrontals() > 1 ?
" " :
"");
122 mean.print(
" mean", formatter);
125 model_->print(
" Noise model: ");
127 cout <<
" No noise model" << endl;
139 list<Vector> rows1, rows2;
141 rows2.push_back(
Vector(
c->R().row(
i)));
150 rows2.push_back(
row(
c->getA(it2),
i));
175 return diag.unaryExpr([](
double x) {
return log(x); }).sum();
177 return R().diagonal().unaryExpr([](
double x) {
return log(x); }).sum();
185 constexpr
double log2pi = 1.8378770664093454835606594728112;
186 size_t n =
d().size();
223 if (solution.hasNaN()) {
231 result.
emplace(*frontal, solution.segment(vectorPosition,
getDim(frontal)));
232 vectorPosition +=
getDim(frontal);
246 xS = rhsR -
S() * xS;
253 soln.array() *=
model_->sigmas().array();
259 result.
emplace(*frontal, soln.segment(vectorPosition,
getDim(frontal)));
260 vectorPosition +=
getDim(frontal);
275 gy[*it].noalias() += -1.0 *
getA(it).transpose() * frontalVec;
279 frontalVec.array() *=
model_->sigmas().array();
284 gy[*frontal] = frontalVec.segment(vectorPosition,
getDim(frontal));
285 vectorPosition +=
getDim(frontal);
308 auto last = newAb.matrix().cols() - 1;
310 newAb.matrix().col(
last) -= RR *
x;
318 return std::make_shared<JacobianFactor>(newKeys, newAb,
model_);
323 const Vector& frontal)
const {
325 throw std::invalid_argument(
326 "GaussianConditional Single value likelihood can only be invoked on " 327 "single-variable conditional");
335 std::mt19937_64*
rng)
const {
337 throw std::invalid_argument(
338 "GaussianConditional::sample can only be called on single variable " 353 throw std::invalid_argument(
354 "sample() can only be invoked on no-parent prior");
const gtsam::Symbol key('X', 0)
VectorValues sample() const
Sample, use default rng.
std::string formatMatrixIndented(const std::string &label, const Matrix &matrix, bool makeVectorHorizontal)
JacobianFactor::shared_ptr likelihood(const VectorValues &frontalValues) const
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
static std::mt19937 kRandomNumberGenerator(42)
static std::mt19937_64 kRandomNumberGenerator(42)
double error(const VectorValues &c) const override
Matrix diag(const std::vector< Matrix > &Hs)
void print(const std::string &="GaussianConditional", const KeyFormatter &formatter=DefaultKeyFormatter) const override
JacobianFactor ::const_iterator endFrontals() const
DenseIndex rows() const
Row size.
noiseModel::Diagonal::shared_ptr model_
VectorValues solve(const VectorValues &parents) const
Rot2 R(Rot2::fromAngle(0.1))
JacobianFactor ::const_iterator beginParents() const
static Vector sampleDiagonal(const Vector &sigmas, std::mt19937_64 *rng)
sample with given random number generator
KeyVector keys_
The keys involved in this factor.
iterator insert(const std::pair< Key, Vector > &key_value)
double evaluate(const VectorValues &x) const
size_t nrFrontals() const
const VectorValues & continuous() const
Return the multi-dimensional vector values.
const constBVector d() const
EIGEN_DEVICE_FUNC const LogReturnType log() const
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
ptrdiff_t DenseIndex
The index type for Eigen objects.
Point3 mean(const CONTAINER &points)
mean
const KeyFormatter & formatter
JacobianFactor ::const_iterator beginFrontals() const
std::pair< VectorValues::iterator, bool > emplace(Key j, Args &&... args)
bool linear_dependent(const Matrix &A, const Matrix &B, double tol)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
void solveTransposeInPlace(VectorValues &gy) const
JacobianFactor ::const_iterator endParents() const
const constBVector getb() const
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
DenseIndex getDim(const_iterator variable) const override
Conditional Gaussian Base class.
sampling from a NoiseModel
double logProbability(const VectorValues &x) const
std::shared_ptr< This > shared_ptr
shared_ptr to this class
static GaussianConditional FromMeanAndStddev(Key key, const Vector &mu, double sigma)
Construct from mean mu and standard deviation sigma.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Exceptions that may be thrown by linear solver components.
noiseModel::Diagonal::shared_ptr SharedDiagonal
double logDeterminant() const
Compute the log determinant of the R matrix.
Key front() const
First key.
VectorValues solveOtherRHS(const VectorValues &parents, const VectorValues &rhs) const
const KeyVector & keys() const
Access the factor's involved variable keys.
static const double sigma
const DenseIndex & firstBlock() const
Key firstFrontalKey() const
KeyVector::const_iterator const_iterator
Const iterator over keys.
bool equals(const GaussianFactor &cg, double tol=1e-9) const override
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
double logNormalizationConstant() const override
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
Vector concatVectors(const std::list< Vector > &vs)
std::uint64_t Key
Integer nonlinear key type.
const SharedDiagonal & get_model() const
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)