27 #include <boost/algorithm/string.hpp> 28 #include <boost/range/adaptor/reversed.hpp> 43 vector<std::pair<size_t, size_t> > cache;
48 for (
const Key &
key : keys) {
50 cache.emplace_back(entry.
start, entry.
dim);
57 for (
const auto &
p : cache) {
58 result.segment(index,
p.second) = src.segment(
p.first,
p.second);
69 for (
const Key &
key : keys) {
71 const size_t keyDim = entry.
dim;
72 dst.segment(entry.
start, keyDim) = src.segment(index, keyDim);
82 auto result = boost::make_shared<GaussianFactorGraph>();
83 for (
const auto &factor : gfg)
87 jf = boost::make_shared<JacobianFactor>(*factor);
116 return 0.5 * (
dot(e, e) +
dot(e2,e2));
125 Ab2()->transposeMultiplyAdd(1.0, e, v);
126 return y +
Rc1()->backSubstituteTranspose(v);
135 e.splice(e.end(), e2);
143 Errors::iterator ei = e.begin();
144 for(
const auto& key_value: y) {
145 *ei = key_value.second;
151 Ab2()->multiplyInPlace(x, ei);
158 Errors::const_iterator it = e.begin();
160 for(
auto& key_value: y) {
161 key_value.second = *it;
173 Errors::const_iterator it = e.begin();
174 for(
auto& key_value: y) {
176 axpy(alpha, ei, key_value.second);
185 Errors::const_iterator it, Errors::const_iterator
end,
VectorValues& y)
const {
190 while (it != end) e2.push_back(*(it++));
193 Ab2_->transposeMultiplyAdd(1.0,e2,x);
194 axpy(alpha,
Rc1_->backSubstituteTranspose(x),
y);
205 assert(x.size() == y.size());
210 const KeyVector parentKeys(cg->beginParents(), cg->endParents());
211 const KeyVector frontalKeys(cg->beginFrontals(), cg->endFrontals());
217 rhsFrontal - cg->S() * xParent);
227 assert(x.size() == y.size());
228 std::copy(y.data(), y.data() + y.rows(), x.data());
231 for (
const auto &cg : *
Rc1_) {
232 const KeyVector frontalKeys(cg->beginFrontals(), cg->endFrontals());
239 if (solFrontal.hasNaN())
246 for (
auto it = cg->beginParents(); it != cg->endParents(); it++) {
249 rhsParent -=
Matrix(cg->getA(it)).transpose() * solFrontal;
259 auto subgraph = builder(gfg);
267 Rc1_ = gfg_subgraph->eliminateSequential();
GaussianFactorGraph::shared_ptr buildFactorSubgraph(const GaussianFactorGraph &gfg, const Subgraph &subgraph, const bool clone)
Errors operator*(const VectorValues &y) const
const sharedErrors b2bar() const
void build(const GaussianFactorGraph &gfg, const KeyInfo &info, const std::map< Key, Vector > &lambda) override
build/factorize the preconditioner
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)
VectorValues x(const VectorValues &y) const
double error(const VectorValues &y) const
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
A matrix or vector expression mapping an existing array of data.
boost::shared_ptr< const VectorValues > sharedValues
boost::shared_ptr< const GaussianBayesNet > sharedBayesNet
static Vector getSubvector(const Vector &src, const KeyInfo &keyInfo, const KeyVector &keys)
VectorValues gradient(const VectorValues &y) const
static VectorValues Zero(const VectorValues &other)
SubgraphPreconditioner(const SubgraphPreconditionerParameters &p=SubgraphPreconditionerParameters())
void transposeMultiplyAdd2(double alpha, Errors::const_iterator begin, Errors::const_iterator end, VectorValues &y) const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
SubgraphPreconditionerParameters parameters_
const sharedBayesNet & Rc1() const
static GaussianFactorGraph::shared_ptr convertToJacobianFactors(const GaussianFactorGraph &gfg)
VectorValues zero() const
sharedErrors b2bar_
A2*xbar - b2.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void axpy(double alpha, const V1 &x, V2 &y)
Linear Factor Graph where all factors are Gaussians.
VectorValues operator^(const Errors &e) const
sharedValues xbar_
A1 \ b1.
void transposeSolve(const Vector &y, Vector &x) const override
implement x = R^{-T} y
boost::shared_ptr< const GaussianFactorGraph > sharedFG
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
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
void transposeMultiplyAdd(double alpha, const Errors &e, VectorValues &y) const
typedef and functions to augment Eigen's VectorXd
void reverse(const MatrixType &m)
void multiplyInPlace(const VectorValues &y, Errors &e) const
SubgraphBuilderParameters builderParams
Chordal Bayes Net, the result of eliminating a factor graph.
const sharedFG & Ab2() const
void solve(const Vector &y, Vector &x) const override
implement x = R^{-1} y
void print(const std::string &s="SubgraphPreconditioner") const
std::uint64_t Key
Integer nonlinear key type.