gtsam 4.1.1 gtsam
FitBasis.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
9
10 * -------------------------------------------------------------------------- */
11
19/*
20 * Concept needed for LS. Parameters = Coefficients | Values
21 * - Parameters, Jacobian
22 * - PredictFactor(double x)(Parameters p, OptionalJacobian<1,N> H)
23 */
24
25#pragma once
26
27#include <gtsam/basis/Basis.h>
32
33namespace gtsam {
34
36using Sequence = std::map<double, double>;
38using Sample = std::pair<double, double>;
39
51template <class Basis>
52class FitBasis {
53 public:
54 using Parameters = typename Basis::Parameters;
55
56 private:
57 Parameters parameters_;
58
59 public:
62 const SharedNoiseModel& model,
63 size_t N) {
65 for (const Sample sample : sequence) {
66 graph.emplace_shared<EvaluationFactor<Basis>>(0, sample.second, model, N,
67 sample.first);
68 }
69 return graph;
70 }
71
74 const Sequence& sequence, const SharedNoiseModel& model, size_t N) {
75 NonlinearFactorGraph graph = NonlinearGraph(sequence, model, N);
76 Values values;
77 values.insert<Parameters>(0, Parameters::Zero(N));
78 GaussianFactorGraph::shared_ptr gfg = graph.linearize(values);
79 return gfg;
80 }
81
89 FitBasis(const Sequence& sequence, const SharedNoiseModel& model, size_t N) {
90 GaussianFactorGraph::shared_ptr gfg = LinearGraph(sequence, model, N);
91 VectorValues solution = gfg->optimize();
92 parameters_ = solution.at(0);
93 }
94
96 Parameters parameters() const { return parameters_; }
97};
98
99} // namespace gtsam
Compute an interpolating basis.
Factor definitions for various Basis functors.
Linear Factor Graph where all factors are Gaussians.
Factor Graph Values.
Factor Graph consisting of non-linear factors.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::map< double, double > Sequence
Our sequence representation is a map of {x: y} values where y = f(x)
Definition: FitBasis.h:36
std::pair< double, double > Sample
A sample is a key-value pair from a sequence.
Definition: FitBasis.h:38
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:736
Factor for enforcing the scalar value of the polynomial BASIS representation at x is the same as the ...
Definition: BasisFactors.h:34
Class that does regression via least squares Example usage: size_t N = 3; auto fit = FitBasis<Chebysh...
Definition: FitBasis.h:52
static NonlinearFactorGraph NonlinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create nonlinear FG from Sequence.
Definition: FitBasis.h:61
Parameters parameters() const
Return Fourier coefficients.
Definition: FitBasis.h:96
FitBasis(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Construct a new FitBasis object.
Definition: FitBasis.h:89
static GaussianFactorGraph::shared_ptr LinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create linear FG from Sequence.
Definition: FitBasis.h:73
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactorGraph.h:75
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:74
Vector & at(Key j)