38struct GTSAM_EXPORT PCGSolverParameters :
public ConjugateGradientParameters {
39 typedef ConjugateGradientParameters Base;
40 typedef std::shared_ptr<PCGSolverParameters> shared_ptr;
47 PCGSolverParameters() {}
50 const std::shared_ptr<PreconditionerParameters>& preconditioner)
51 : preconditioner(preconditioner) {}
53 void print(std::ostream& os)
const override;
54 void print(
const std::string& s)
const;
72class GTSAM_EXPORT
PCGSolver :
public IterativeSolver {
74 typedef IterativeSolver Base;
75 typedef std::shared_ptr<PCGSolver> shared_ptr;
79 std::shared_ptr<Preconditioner> preconditioner_;
90 using IterativeSolver::optimize;
102 const std::map<Key, Vector>& lambda,
114 bool collectResidualHistory =
true);
129 const std::map<Key, Vector>& lambda,
131 bool collectResidualHistory =
true);
149 std::shared_ptr<Impl> impl_;
151 const std::vector<Matrix>& hessianBlockDiagonal()
const;
153 friend class PCGSolver;
173 const std::map<Key, Vector>& lambda,
177 void residual(
const Vector& x, Vector& r)
const;
180 void multiply(
const Vector& x, Vector& y)
const;
189 void scal(
const double alpha, Vector& x)
const;
192 double dot(
const Vector& x,
const Vector& y)
const;
195 void axpy(
const double alpha,
const Vector& x, Vector& y)
const;
198 void getb(Vector& b)
const;
218 const std::map<Key, size_t>& dimensions);
typedef and functions to augment Eigen's MatrixXd
Implementation of Conjugate Gradient solver for a linear system.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
VectorValues buildVectorValues(const Vector &vector, const KeyInfo &keyInfo)
Split a flat vector into keyed blocks using KeyInfo offsets and dimensions.
Definition KeyInfo.cpp:107
Diagnostics collected during a conjugate-gradient solve.
Definition ConjugateGradientSolver.h:112
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:77
Ordered key dimensions and offsets in one flattened variable vector.
Definition KeyInfo.h:51
Parameters for Preconditioned Conjugate Gradient solver.
Definition PCGSolver.h:38
std::shared_ptr< PreconditionerParameters > preconditioner
Parameters used to construct the preconditioner for each solve.
Definition PCGSolver.h:43
size_t numThreads
Worker count (0 selects an automatic count).
Definition PCGSolver.h:45
bool parallel
Enable scheduler-backed parallel kernels.
Definition PCGSolver.h:44
Solution, convergence diagnostics, and phase timings from PCGSolver.
Definition PCGSolver.h:58
VectorValues solution
Final solution in keyed form.
Definition PCGSolver.h:59
ConjugateGradientStats stats
Convergence diagnostics for the PCG loop.
Definition PCGSolver.h:60
double solveSeconds
Time for PCG and conversion of its result to VectorValues.
Definition PCGSolver.h:65
double preconditionerSetupSeconds
Time to build and factorize the preconditioner.
Definition PCGSolver.h:63
double operatorSetupSeconds
Time to compile the flat matrix-free operator.
Definition PCGSolver.h:61
PCGSolverResult optimizeDetailed(const GaussianFactorGraph &gfg, bool collectResidualHistory=true)
Optimize from zero and return convergence diagnostics and phase timings.
Definition PCGSolver.cpp:624
PCGSolver(const PCGSolverParameters &p)
Construct a solver with the supplied iteration and preconditioner settings.
Definition PCGSolver.cpp:55
VectorValues optimize(const GaussianFactorGraph &gfg, const KeyInfo &keyInfo, const std::map< Key, Vector > &lambda, const VectorValues &initial) override
Solve using explicit key metadata, damping, and an initial estimate.
Definition PCGSolver.cpp:616
double dot(const Vector &x, const Vector &y) const
Return the Euclidean dot product of two flat vectors.
Definition PCGSolver.cpp:757
void residual(const Vector &x, Vector &r) const
Overwrite r with the residual b - H*x in flat KeyInfo ordering.
Definition PCGSolver.cpp:688
void getb(Vector &b) const
Overwrite b with the cached normal-equation right-hand side.
Definition PCGSolver.cpp:700
void leftPrecondition(const Vector &x, Vector &y) const
Overwrite y with the left split-preconditioner solve L^{-1}*x.
Definition PCGSolver.cpp:714
void multiply(const Vector &x, Vector &y) const
Overwrite y with the Hessian-vector product H*x.
Definition PCGSolver.cpp:695
GaussianFactorGraphSystem(const GaussianFactorGraph &gfg, const Preconditioner &preconditioner, const KeyInfo &info, const std::map< Key, Vector > &lambda, bool parallel=true, size_t numThreads=0)
Compile a Gaussian factor graph into a flat-vector PCG system.
Definition PCGSolver.cpp:678
size_t numThreads() const
Return the effective worker count, or one for serial execution.
Definition PCGSolver.cpp:703
void rightPrecondition(const Vector &x, Vector &y) const
Overwrite y with the right split-preconditioner solve L^{-T}*x.
Definition PCGSolver.cpp:734
void axpy(const double alpha, const Vector &x, Vector &y) const
Accumulate alpha*x into y.
Definition PCGSolver.cpp:760
void scal(const double alpha, Vector &x) const
Scale x in place by alpha.
Definition PCGSolver.cpp:754
Definition Preconditioner.h:27
Definition Preconditioner.h:67
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73