52 size_t n, std::function<
Key(
int)> keyFunc =
X,
53 std::function<
Key(
int)> dKeyFunc =
M) {
59 for (
size_t t = 1;
t <
n;
t++) {
61 {keyFunc(
t), keyFunc(
t + 1)}, {{dKeyFunc(
t), 2}},
62 {std::make_shared<JacobianFactor>(keyFunc(
t), I_3x3, keyFunc(
t + 1),
64 std::make_shared<JacobianFactor>(keyFunc(
t), I_3x3, keyFunc(
t + 1),
65 I_3x3, Vector3::Ones())}));
73 return std::make_shared<HybridGaussianFactorGraph>(std::move(hfg));
86 std::vector<Key> &input) {
89 std::vector<int> levels(input.size());
90 std::function<void(std::vector<Key>::iterator, std::vector<Key>::iterator,
92 bsg = [&bsg, &new_order, &levels, &input](
93 std::vector<Key>::iterator begin,
94 std::vector<Key>::iterator
end,
int lvl) {
96 std::vector<Key>::iterator pivot =
99 new_order.push_back(*pivot);
101 bsg(begin, pivot, lvl + 1);
102 bsg(pivot + 1, end, lvl + 1);
104 new_order.push_back(*begin);
109 bsg(input.begin(), input.end(), 0);
112 return {new_order, levels};
135 Switching(
size_t K,
double between_sigma = 1.0,
double prior_sigma = 0.1,
136 std::vector<double> measurements = {},
137 std::string discrete_transition_prob =
"1/2 3/2")
142 for (
size_t k = 0; k <
K; k++) {
143 modes.emplace_back(
M(k), 2);
147 if (measurements.size() == 0) {
148 for (
size_t k = 0; k <
K; k++) {
149 measurements.push_back(k);
156 X(0), measurements.at(0), Isotropic::Sigma(1, prior_sigma));
159 for (
size_t k = 0; k < K - 1; k++) {
162 std::vector<NonlinearFactor::shared_ptr> components;
163 for (
auto &&
f : motion_models) {
164 components.push_back(std::dynamic_pointer_cast<NonlinearFactor>(
f));
171 auto measurement_noise = Isotropic::Sigma(1, prior_sigma);
172 for (
size_t k = 1; k <
K; k++) {
174 X(k), measurements.at(k), measurement_noise);
178 addModeChain(&nonlinearFactorGraph, discrete_transition_prob);
181 for (
size_t k = 0; k <
K; k++) {
182 linearizationPoint.
insert<
double>(
X(k),
static_cast<double>(k + 1));
187 linearizedFactorGraph = *nonlinearFactorGraph.
linearize(linearizationPoint);
192 double sigma = 1.0) {
195 std::make_shared<MotionModel>(
X(k),
X(k + 1), 0.0, noise_model),
197 std::make_shared<MotionModel>(
X(k),
X(k + 1), 1.0, noise_model);
198 return {still, moving};
208 std::string discrete_transition_prob =
"1/2 3/2") {
210 for (
size_t k = 0; k < K - 2; k++) {
211 auto parents = {modes[k]};
213 discrete_transition_prob);
224 std::string discrete_transition_prob =
"1/2 3/2") {
226 for (
size_t k = 0; k < K - 2; k++) {
227 auto parents = {modes[k]};
229 discrete_transition_prob);
void addModeChain(HybridGaussianFactorGraph *fg, std::string discrete_transition_prob="1/2 3/2")
Add "mode chain" to HybridGaussianFactorGraph from M(0) to M(K-2). E.g. if K=4, we want M0...
HybridGaussianFactorGraph::shared_ptr makeSwitchingChain(size_t n, std::function< Key(int)> keyFunc=X, std::function< Key(int)> dKeyFunc=M)
Create a switching system chain. A switching system is a continuous system which depends on a discret...
A set of GaussianFactors, indexed by a set of discrete keys.
Matrix< RealScalar, Dynamic, Dynamic > M
std::pair< KeyVector, std::vector< int > > makeBinaryOrdering(std::vector< Key > &input)
Return the ordering as a binary tree such that all parent nodes are above their children.
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
Nonlinear hybrid factor graph that uses type erasure.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Switching(size_t K, double between_sigma=1.0, double prior_sigma=0.1, std::vector< double > measurements={}, std::string discrete_transition_prob="1/2 3/2")
Create with given number of time steps.
Implementation of a discrete conditional mixture factor. Implements a joint discrete-continuous facto...
Double_ distance(const OrientedPlane3_ &p)
Nonlinear Mixture factor of continuous and discrete.
IsDerived< DERIVEDFACTOR > add(std::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
void addModeChain(HybridNonlinearFactorGraph *fg, std::string discrete_transition_prob="1/2 3/2")
Add "mode chain" to HybridNonlinearFactorGraph from M(0) to M(K-2). E.g. if K=4, we want M0...
HybridGaussianFactorGraph linearizedFactorGraph
static std::vector< MotionModel::shared_ptr > motionModels(size_t k, double sigma=1.0)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
std::shared_ptr< This > shared_ptr
shared_ptr to This
Linearized Hybrid factor graph that uses type erasure.
Values linearizationPoint
HybridNonlinearFactorGraph nonlinearFactorGraph
void reverse(const MatrixType &m)
static EIGEN_DEPRECATED const end_t end
std::shared_ptr< HybridGaussianFactorGraph > linearize(const Values &continuousValues) const
Linearize all the continuous factors in the HybridNonlinearFactorGraph.
static const double sigma
void insert(Key j, const Value &val)
Implementation of a discrete conditional mixture factor.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
std::uint64_t Key
Integer nonlinear key type.
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
DiscreteKeys is a set of keys that can be assembled using the & operator.