FitBasis.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
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 
33 namespace gtsam {
34 
36 using Sequence = std::map<double, double>;
38 using Sample = std::pair<double, double>;
39 
51 template <class Basis>
52 class FitBasis {
53  public:
54  using Parameters = typename Basis::Parameters;
55 
56  private:
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
static NonlinearFactorGraph NonlinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create nonlinear FG from Sequence.
Definition: FitBasis.h:61
static GaussianFactorGraph::shared_ptr LinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create linear FG from Sequence.
Definition: FitBasis.h:73
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition: FactorGraph.h:196
Factor Graph consisting of non-linear factors.
noiseModel::Diagonal::shared_ptr model
Factor definitions for various Basis functors.
leaf::MyValues values
typename Basis::Parameters Parameters
Definition: FitBasis.h:54
#define N
Definition: gksort.c:12
Vector & at(Key j)
Definition: VectorValues.h:139
NonlinearFactorGraph graph
Parameters parameters_
Definition: FitBasis.h:57
std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Factor Graph Values.
std::map< double, double > Sequence
Our sequence representation is a map of {x: y} values where y = f(x)
Definition: FitBasis.h:36
Factor for enforcing the scalar value of the polynomial BASIS representation at x is the same as the ...
Definition: BasisFactors.h:39
Compute an interpolating basis.
Linear Factor Graph where all factors are Gaussians.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
traits
Definition: chartTesting.h:28
FitBasis(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Construct a new FitBasis object.
Definition: FitBasis.h:89
void insert(Key j, const Value &val)
Definition: Values.cpp:155
Parameters parameters() const
Return Fourier coefficients.
Definition: FitBasis.h:96
std::pair< double, double > Sample
A sample is a key-value pair from a sequence.
Definition: FitBasis.h:38
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:13