84 const double prior_inlier,
const double prior_outlier,
85 const bool flag_bump_up_near_zero_probs =
false,
86 const bool start_with_M_step =
false) :
87 Base(cref_list_of<1>(key)), key_(key), measured_(measured), keyA_(keyA), keyB_(keyB),
88 model_inlier_(model_inlier), model_outlier_(model_outlier),
89 prior_inlier_(prior_inlier), prior_outlier_(prior_outlier), flag_bump_up_near_zero_probs_(flag_bump_up_near_zero_probs),
90 start_with_M_step_(false){
107 std::cout << s <<
"TransformBtwRobotsUnaryFactorEM(" 108 << keyFormatter(key_) <<
")\n";
109 std::cout <<
"MR between factor keys: " 110 << keyFormatter(keyA_) <<
"," 111 << keyFormatter(keyB_) <<
"\n";
112 measured_.print(
" measured: ");
113 model_inlier_->print(
" noise model inlier: ");
114 model_outlier_->print(
" noise model outlier: ");
115 std::cout <<
"(prior_inlier, prior_outlier_) = (" 116 << prior_inlier_ <<
"," 117 << prior_outlier_ <<
")\n";
123 const This *
t =
dynamic_cast<const This*
> (&
f);
126 return key_ == t->key_ && measured_.
equals(t->measured_) &&
129 prior_outlier_ == t->prior_outlier_ && prior_inlier_ == t->prior_inlier_;
139 throw(
"something is wrong!");
168 return boost::shared_ptr<JacobianFactor>();
172 std::vector<Matrix>
A(this->
size());
183 boost::optional<std::vector<Matrix>&>
H = boost::none)
const {
187 Matrix H_compose, H_between1, H_dummy;
189 T orgA_T_currA = valA_.
at<T>(
keyA_);
190 T orgB_T_currB = valB_.
at<T>(
keyB_);
192 T orgA_T_orgB = x.
at<T>(
key_);
194 T orgA_T_currB = orgA_T_orgB.compose(orgB_T_currB, H_compose, H_dummy);
196 T currA_T_currB_pred = orgA_T_currA.between(orgA_T_currB, H_dummy, H_between1);
200 Vector err = currA_T_currB_msr.localCoordinates(currA_T_currB_pred);
204 double p_inlier = p_inlier_outlier[0];
205 double p_outlier = p_inlier_outlier[1];
207 if (start_with_M_step_){
208 start_with_M_step_ =
false;
214 Vector err_wh_inlier = model_inlier_->whiten(err);
215 Vector err_wh_outlier = model_outlier_->whiten(err);
217 Matrix invCov_inlier = model_inlier_->R().transpose() * model_inlier_->R();
218 Matrix invCov_outlier = model_outlier_->R().transpose() * model_outlier_->R();
221 err_wh_eq.resize(err_wh_inlier.rows()*2);
222 err_wh_eq <<
sqrt(p_inlier) * err_wh_inlier.array() ,
sqrt(p_outlier) * err_wh_outlier.array();
224 Matrix H_unwh = H_compose * H_between1;
228 Matrix H_inlier =
sqrt(p_inlier)*model_inlier_->Whiten(H_unwh);
229 Matrix H_outlier =
sqrt(p_outlier)*model_outlier_->Whiten(H_unwh);
232 (*H)[0].resize(H_aug.rows(),H_aug.cols());
260 Vector err_wh_inlier = model_inlier_->whiten(err);
261 Vector err_wh_outlier = model_outlier_->whiten(err);
263 Matrix invCov_inlier = model_inlier_->R().transpose() * model_inlier_->R();
264 Matrix invCov_outlier = model_outlier_->R().transpose() * model_outlier_->R();
266 double p_inlier = prior_inlier_ *
sqrt(invCov_inlier.norm()) *
exp( -0.5 * err_wh_inlier.dot(err_wh_inlier) );
267 double p_outlier = prior_outlier_ *
sqrt(invCov_outlier.norm()) *
exp( -0.5 * err_wh_outlier.dot(err_wh_outlier) );
269 double sumP = p_inlier + p_outlier;
273 if (flag_bump_up_near_zero_probs_){
276 if (p_inlier < minP || p_outlier < minP){
279 if (p_outlier < minP)
281 sumP = p_inlier + p_outlier;
287 return (
Vector(2) << p_inlier, p_outlier).finished();
293 T orgA_T_currA = valA_.
at<T>(
keyA_);
294 T orgB_T_currB = valB_.
at<T>(
keyB_);
296 T orgA_T_orgB = x.
at<T>(
key_);
298 T orgA_T_currB = orgA_T_orgB.compose(orgB_T_currB);
300 T currA_T_currB_pred = orgA_T_currA.between(orgA_T_currB);
304 return currA_T_currB_msr.localCoordinates(currA_T_currB_pred);
319 return (model_inlier_->R().transpose()*model_inlier_->R()).
inverse();
324 return (model_outlier_->R().transpose()*model_outlier_->R()).
inverse();
332 Keys.push_back(keyA_);
333 Keys.push_back(keyB_);
335 Matrix cov1 = joint_marginal12(keyA_, keyA_);
336 Matrix cov2 = joint_marginal12(keyB_, keyB_);
337 Matrix cov12 = joint_marginal12(keyA_, keyB_);
375 p1.between(p2, H1, H2);
378 H.resize(H1.rows(), H1.rows()+H2.rows());
382 joint_cov.resize(cov1.rows()+cov2.rows(), cov1.cols()+cov2.cols());
383 joint_cov << cov1, cov12,
384 cov12.transpose(), cov2;
386 Matrix cov_state = H*joint_cov*H.transpose();
391 Matrix covRinlier = (model_inlier_->R().transpose()*model_inlier_->R()).
inverse();
394 Matrix covRoutlier = (model_outlier_->R().transpose()*model_outlier_->R()).
inverse();
404 size_t dim()
const override {
405 return model_inlier_->R().rows() + model_inlier_->R().cols();
412 template<
class ARCHIVE>
414 ar & boost::serialization::make_nvp(
"NonlinearFactor",
415 boost::serialization::base_object<Base>(*
this));
421 template<
class VALUE>
423 public Testable<TransformBtwRobotsUnaryFactorEM<VALUE> > {
bool equals(const This &other, double tol=1e-9) const
check equality
static shared_ptr Covariance(const Matrix &covariance, bool smart=true)
Concept check for values that can be used in unit tests.
Factor Graph consisting of non-linear factors.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
A factor with a quadratic error function - a Gaussian.
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
JointMarginal jointMarginalCovariance(const KeyVector &variables) 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)
NonlinearFactorGraph graph
static const KeyFormatter DefaultKeyFormatter
virtual bool active(const Values &) const
static shared_ptr Create(size_t dim)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
const ValueType at(Key j) const
boost::shared_ptr< This > shared_ptr
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Base class and basic functions for Lie types.
#define GTSAM_CONCEPT_LIE_TYPE(T)
boost::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
Non-linear factor base classes.
Matrix stack(size_t nrMatrices,...)
A class for computing marginals in a NonlinearFactorGraph.
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
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
std::uint64_t Key
Integer nonlinear key type.
Marginals marginals(graph, result)
noiseModel::Gaussian::shared_ptr SharedGaussian