40 vector<std::pair<size_t, size_t> > cache;
45 for (
const Key &
key : keys) {
47 cache.emplace_back(entry.
start, entry.
dim);
54 for (
const auto &
p : cache) {
55 result.segment(index,
p.second) = src.segment(
p.first,
p.second);
66 for (
const Key &
key : keys) {
68 const size_t keyDim = entry.
dim;
69 dst.segment(entry.
start, keyDim) = src.segment(index, keyDim);
80 for (
const auto &factor : gfg)
84 jf = std::make_shared<JacobianFactor>(*factor);
113 return 0.5 * (
dot(e, e) +
dot(e2,e2));
132 e.splice(e.end(), e2);
140 Errors::iterator ei = e.begin();
141 for(
const auto& key_value: y) {
142 *ei = key_value.second;
155 Errors::const_iterator it = e.begin();
157 for(
auto& key_value: y) {
158 key_value.second = *it;
170 Errors::const_iterator it = e.begin();
171 for(
auto& key_value: y) {
173 key_value.second += alpha * ei;
182 Errors::const_iterator it, Errors::const_iterator
end,
VectorValues& y)
const {
187 while (it != end) e2.push_back(*(it++));
202 assert(x.size() == y.size());
208 const KeyVector parentKeys(cg->beginParents(), cg->endParents());
209 const KeyVector frontalKeys(cg->beginFrontals(), cg->endFrontals());
215 rhsFrontal - cg->S() * xParent);
225 assert(x.size() == y.size());
226 std::copy(y.data(), y.data() + y.rows(), x.data());
229 for (
const auto &cg :
Rc1_) {
230 const KeyVector frontalKeys(cg->beginFrontals(), cg->endFrontals());
237 if (solFrontal.hasNaN())
244 for (
auto it = cg->beginParents(); it != cg->endParents(); it++) {
247 rhsParent -=
Matrix(cg->getA(it)).transpose() * solFrontal;
257 auto subgraph = builder(gfg);
265 Rc1_ = *gfg_subgraph.eliminateSequential();
const gtsam::Symbol key('X', 0)
void build(const GaussianFactorGraph &gfg, const KeyInfo &info, const std::map< Key, Vector > &lambda) override
build/factorize the preconditioner
VectorValues zero() const
Typedefs for easier changing of types.
double dot(const V1 &a, const V2 &b)
static void setSubvector(const Vector &src, const KeyInfo &keyInfo, const KeyVector &keys, Vector &dst)
A matrix or vector expression mapping an existing array of data.
Errors gaussianErrors(const VectorValues &x) const
void transposeMultiplyAdd(double alpha, const Errors &e, VectorValues &x) const
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
VectorValues operator^(const Errors &e) const
double error(const VectorValues &y) const
void transposeMultiplyAdd2(double alpha, Errors::const_iterator begin, Errors::const_iterator end, VectorValues &y) const
Errors operator*(const VectorValues &y) const
static Vector getSubvector(const Vector &src, const KeyInfo &keyInfo, const KeyVector &keys)
virtual void print(const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const
Print out graph to std::cout, with optional key formatter.
std::reverse_iterator< Iterator > make_reverse_iterator(Iterator i)
void transposeMultiplyAdd(double alpha, const Errors &e, VectorValues &y) const
SubgraphPreconditioner(const SubgraphPreconditionerParameters &p=SubgraphPreconditionerParameters())
const GaussianBayesNet & Rc1() const
const_iterator begin() const
void multiplyInPlace(const VectorValues &x, Errors &e) const
SubgraphPreconditionerParameters parameters_
static VectorValues Zero(const VectorValues &other)
Array< int, Dynamic, 1 > v
Array< double, 1, 3 > e(1./3., 0.5, 2.)
VectorValues backSubstituteTranspose(const VectorValues &gx) const
Linear Factor Graph where all factors are Gaussians.
void transposeSolve(const Vector &y, Vector &x) const override
implement x = R^{-T} y
GaussianFactorGraph buildFactorSubgraph(const GaussianFactorGraph &gfg, const Subgraph &subgraph, const bool clone)
const_iterator end() const
static GaussianFactorGraph convertToJacobianFactors(const GaussianFactorGraph &gfg)
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Errors createErrors(const VectorValues &V)
Break V into pieces according to its start indices.
typedef and functions to augment Eigen's VectorXd
static EIGEN_DEPRECATED const end_t end
SubgraphBuilderParameters builderParams
VectorValues xbar_
A1 \ b1.
Chordal Bayes Net, the result of eliminating a factor graph.
Errors b2bar_
A2*xbar - b2.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
VectorValues backSubstitute(const VectorValues &gx) const
void solve(const Vector &y, Vector &x) const override
implement x = R^{-1} y
VectorValues gradient(const VectorValues &y) const
std::uint64_t Key
Integer nonlinear key type.
void print(const std::string &s="SubgraphPreconditioner") const
VectorValues x(const VectorValues &y) const
const GaussianFactorGraph & Ab2() const
void multiplyInPlace(const VectorValues &y, Errors &e) const