65 typedef typename std::shared_ptr<BetweenFactorEM>
shared_ptr;
74 const double prior_inlier,
const double prior_outlier,
75 const bool flag_bump_up_near_zero_probs =
false) :
79 flag_bump_up_near_zero_probs) {
90 std::cout << s <<
"BetweenFactorEM(" << keyFormatter(key1_) <<
"," 91 << keyFormatter(key2_) <<
")\n";
92 measured_.print(
" measured: ");
93 model_inlier_->print(
" noise model inlier: ");
94 model_outlier_->print(
" noise model outlier: ");
95 std::cout <<
"(prior_inlier, prior_outlier_) = (" << prior_inlier_ <<
"," 96 << prior_outlier_ <<
")\n";
102 const This *
t =
dynamic_cast<const This*
>(&
f);
105 return key1_ == t->key1_ && key2_ == t->key2_
109 prior_outlier_ == t->prior_outlier_
110 && prior_inlier_ == t->prior_inlier_ && measured_.
equals(t->measured_);
132 return std::shared_ptr<JacobianFactor>();
136 std::vector<Matrix>
A(this->
size());
157 T hx = p1.between(p2, H1, H2);
160 Vector err = measured_.localCoordinates(hx);
164 double p_inlier = p_inlier_outlier[0];
165 double p_outlier = p_inlier_outlier[1];
167 Vector err_wh_inlier = model_inlier_->whiten(err);
168 Vector err_wh_outlier = model_outlier_->whiten(err);
170 Matrix invCov_inlier = model_inlier_->R().transpose() * model_inlier_->R();
171 Matrix invCov_outlier = model_outlier_->R().transpose()
172 * model_outlier_->R();
175 err_wh_eq.resize(err_wh_inlier.rows() * 2);
176 err_wh_eq <<
sqrt(p_inlier) * err_wh_inlier.array(),
sqrt(p_outlier)
177 * err_wh_outlier.array();
182 Matrix H1_inlier =
sqrt(p_inlier) * model_inlier_->Whiten(H1);
183 Matrix H1_outlier =
sqrt(p_outlier) * model_outlier_->Whiten(H1);
186 Matrix H2_inlier =
sqrt(p_inlier) * model_inlier_->Whiten(H2);
187 Matrix H2_outlier =
sqrt(p_outlier) * model_outlier_->Whiten(H2);
190 (*H)[0].resize(H1_aug.rows(), H1_aug.cols());
191 (*H)[1].resize(H2_aug.rows(), H2_aug.cols());
245 Vector err_wh_inlier = model_inlier_->whiten(err);
246 Vector err_wh_outlier = model_outlier_->whiten(err);
248 Matrix invCov_inlier = model_inlier_->R().transpose() * model_inlier_->R();
249 Matrix invCov_outlier = model_outlier_->R().transpose()
250 * model_outlier_->R();
252 double p_inlier = prior_inlier_ *
std::sqrt(invCov_inlier.determinant())
253 *
exp(-0.5 * err_wh_inlier.dot(err_wh_inlier));
254 double p_outlier = prior_outlier_ *
std::sqrt(invCov_outlier.determinant())
255 *
exp(-0.5 * err_wh_outlier.dot(err_wh_outlier));
258 std::cout <<
"in calcIndicatorProb. err_unwh: " << err[0] <<
", " 259 << err[1] <<
", " << err[2] << std::endl;
260 std::cout <<
"in calcIndicatorProb. err_wh_inlier: " << err_wh_inlier[0]
261 <<
", " << err_wh_inlier[1] <<
", " << err_wh_inlier[2] << std::endl;
262 std::cout <<
"in calcIndicatorProb. err_wh_inlier.dot(err_wh_inlier): " 263 << err_wh_inlier.dot(err_wh_inlier) << std::endl;
264 std::cout <<
"in calcIndicatorProb. err_wh_outlier.dot(err_wh_outlier): " 265 << err_wh_outlier.dot(err_wh_outlier) << std::endl;
268 <<
"in calcIndicatorProb. p_inlier, p_outlier before normalization: " 269 << p_inlier <<
", " << p_outlier << std::endl;
272 double sumP = p_inlier + p_outlier;
276 if (flag_bump_up_near_zero_probs_) {
279 if (p_inlier < minP || p_outlier < minP) {
282 if (p_outlier < minP)
284 sumP = p_inlier + p_outlier;
290 return (
Vector(2) << p_inlier, p_outlier).finished();
301 T hx = p1.between(p2, H1, H2);
303 return measured_.localCoordinates(hx);
308 flag_bump_up_near_zero_probs_ = flag;
328 return (model_inlier_->R().transpose() * model_inlier_->R()).
inverse();
333 return (model_outlier_->R().transpose() * model_outlier_->R()).
inverse();
350 Keys.push_back(key1_);
351 Keys.push_back(key2_);
354 Matrix cov1 = joint_marginal12(key1_, key1_);
355 Matrix cov2 = joint_marginal12(key2_, key2_);
356 Matrix cov12 = joint_marginal12(key1_, key2_);
377 p1.between(p2, H1, H2);
380 H.resize(H1.rows(), H1.rows() + H2.rows());
384 joint_cov.resize(cov1.rows() + cov2.rows(), cov1.cols() + cov2.cols());
385 joint_cov << cov1, cov12, cov12.transpose(), cov2;
387 Matrix cov_state = H * joint_cov * H.transpose();
393 (model_inlier_->R().transpose() * model_inlier_->R()).
inverse();
395 covRinlier + cov_state);
398 (model_outlier_->R().transpose() * model_outlier_->R()).
inverse();
400 covRoutlier + cov_state);
412 size_t dim()
const override {
413 return model_inlier_->R().rows() + model_inlier_->R().cols();
418 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 420 friend class boost::serialization::access;
421 template<
class ARCHIVE>
422 void serialize(ARCHIVE & ar,
const unsigned int ) {
424 & boost::serialization::make_nvp(
"NonlinearFactor",
425 boost::serialization::base_object<Base>(*
this));
426 ar & BOOST_SERIALIZATION_NVP(measured_);
433 template<
class VALUE>
SharedGaussian get_model_outlier() const
std::vector< Matrix > * OptionalMatrixVecType
Vector whitenedError(const Values &x, std::vector< Matrix > &H) const
bool get_flag_bump_up_near_zero_probs() const
SharedGaussian get_model_inlier() const
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
Concept check for values that can be used in unit tests.
std::string serialize(const T &input)
serializes to a string
const ValueType at(Key j) const
A factor with a quadratic error function - a Gaussian.
SharedGaussian model_outlier_
Matrix get_model_inlier_cov() const
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
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
const VALUE & measured() const
NonlinearFactorGraph graph
void set_flag_bump_up_near_zero_probs(bool flag)
static const KeyFormatter DefaultKeyFormatter
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
static constexpr bool debug
static shared_ptr Create(size_t dim)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
JointMarginal jointMarginalCovariance(const KeyVector &variables) const
void updateNoiseModels_givenCovs(const Values &values, const Matrix &cov1, const Matrix &cov2, const Matrix &cov12)
const Symbol key1('v', 1)
Matrix get_model_outlier_cov() const
Vector whitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const
Matrix stack(size_t nrMatrices,...)
SharedGaussian model_inlier_
BetweenFactorEM(Key key1, Key key2, const VALUE &measured, const SharedGaussian &model_inlier, const SharedGaussian &model_outlier, const double prior_inlier, const double prior_outlier, const bool flag_bump_up_near_zero_probs=false)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
~BetweenFactorEM() override
bool flag_bump_up_near_zero_probs_
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Base class and basic functions for Lie types.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
void updateNoiseModels(const Values &values, const NonlinearFactorGraph &graph)
#define GTSAM_CONCEPT_LIE_TYPE(T)
Non-linear factor base classes.
virtual bool active(const Values &) const
size_t dim() const override
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
BetweenFactorEM< VALUE > This
A class for computing marginals in a NonlinearFactorGraph.
Jet< T, N > sqrt(const Jet< T, N > &f)
Vector unwhitenedError(const Values &x) const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
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
std::uint64_t Key
Integer nonlinear key type.
std::shared_ptr< BetweenFactorEM > shared_ptr
Marginals marginals(graph, result)
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
std::shared_ptr< GaussianFactor > linearize(const Values &x) const override
noiseModel::Gaussian::shared_ptr SharedGaussian
double error(const Values &x) const override
const Symbol key2('v', 2)
bool equals(const This &other, double tol=1e-9) const
check equality
Vector calcIndicatorProb(const Values &x) const