gtsam
Loading...
Searching...
No Matches
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
18
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>
33
34namespace gtsam {
35
37using Sequence = std::map<double, double>;
39using Sample = std::pair<double, double>;
40
52template <class Basis>
53class FitBasis {
54 public:
55 using Parameters = typename Basis::Parameters;
56
57 private:
58 Parameters parameters_;
59
60 public:
63 const SharedNoiseModel& model,
64 size_t N) {
66 const auto noiseModel = noiseModel::validOrDefault(0.0, model);
67 for (const Sample sample : sequence) {
69 0, sample.second, noiseModel, N, sample.first);
70 }
71 return graph;
72 }
73
76 const Sequence& sequence, const SharedNoiseModel& model, size_t N) {
77 NonlinearFactorGraph graph = NonlinearGraph(sequence, model, N);
78 Values values;
79 values.insert<Parameters>(0, Parameters::Zero(N));
81 return gfg;
82 }
83
91 FitBasis(const Sequence& sequence, const SharedNoiseModel& model, size_t N) {
92 GaussianFactorGraph::shared_ptr gfg = LinearGraph(sequence, model, N);
93 VectorValues solution = gfg->optimize();
94 parameters_ = solution.at(0);
95 }
96
98 Parameters parameters() const { return parameters_; }
99};
100
101} // 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:37
std::pair< double, double > Sample
A sample is a key-value pair from a sequence.
Definition FitBasis.h:39
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
Base::shared_ptr validOrDefault(const T &value, const Base::shared_ptr &model)
Create.
Definition NoiseModel.h:833
Factor for enforcing the scalar value of the polynomial BASIS representation at x is the same as the ...
Definition BasisFactors.h:39
static NonlinearFactorGraph NonlinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create nonlinear FG from Sequence.
Definition FitBasis.h:62
Parameters parameters() const
Return Fourier coefficients.
Definition FitBasis.h:98
FitBasis(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Construct a new FitBasis object.
Definition FitBasis.h:91
static GaussianFactorGraph::shared_ptr LinearGraph(const Sequence &sequence, const SharedNoiseModel &model, size_t N)
Create linear FG from Sequence.
Definition FitBasis.h:75
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition FactorGraph.h:153
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition GaussianFactorGraph.h:83
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
Vector & at(Key j)
Read/write access to the vector value with key j, throws std::out_of_range if j does not exist,...
Definition VectorValues.h:141
Definition NonlinearFactorGraph.h:57
virtual std::shared_ptr< GaussianFactorGraph > linearize(const Values &linearizationPoint) const
Linearize a nonlinear factor graph.
Definition NonlinearFactorGraph.cpp:269
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
void insert(Key j, const Value &val)
Add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
Definition Values.cpp:170