8000 Wrapper for basis functions by gchenfc · Pull Request #832 · borglab/gtsam · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Wrapper for basis functions #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gtsam/basis/FitBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ using Sequence = std::map<double, double>;
using Sample = std::pair<double, double>;

/**
* Class that does Fourier Decomposition via least squares
* Class that does regression via least squares
* Example usage:
* auto fit = FitBasis<Chebyshev2>(3, data_points, noise_model);
* Vector coefficients = fit.parameters();
*/
template <class Basis>
class FitBasis {
Expand Down
41 changes: 37 additions & 4 deletions gtsam/basis/basis.i
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// basis
//*************************************************************************

namespace gtsam {

// TODO(gerry): add all the Functors to the Basis interfaces, e.g. `EvaluationFunctor`

#include <gtsam/basis/Fourier.h>

class FourierBasis {
Expand Down Expand Up @@ -64,7 +68,7 @@ class ParameterMatrix {
#include <gtsam/basis/BasisFactors.h>

template <BASIS = {gtsam::Chebyshev2}>
class EvaluationFactor : gtsam::NoiseModelFactor {
virtual class EvaluationFactor : gtsam::NoiseModelFactor {
EvaluationFactor();
EvaluationFactor(gtsam::Key key, const double z,
const gtsam::noiseModel::Base* model, const size_t N,
Expand All @@ -75,7 +79,7 @@ class EvaluationFactor : gtsam::NoiseModelFactor {
};

template <BASIS, M>
class VectorEvaluationFactor : gtsam::NoiseModelFactor {
virtual class VectorEvaluationFactor : gtsam::NoiseModelFactor {
VectorEvaluationFactor();
VectorEvaluationFactor(gtsam::Key key, const Vector& z,
const gtsam::noiseModel::Base* model, const size_t N,
Expand All @@ -95,7 +99,7 @@ typedef gtsam::VectorEvaluationFactor<gtsam::Chebyshev2, 12>
VectorEvaluationFactorChebyshev2D12;

template <BASIS, P>
class VectorComponentFactor : gtsam::NoiseModelFactor {
virtual class VectorComponentFactor : gtsam::NoiseModelFactor {
VectorComponentFactor();
VectorComponentFactor(gtsam::Key key, const double z,
const gtsam::noiseModel::Base* model, const size_t N,
Expand All @@ -113,7 +117,7 @@ typedef gtsam::VectorComponentFactor<gtsam::Chebyshev2, 12>
VectorComponentFactorChebyshev2D12;

template <BASIS, T>
class ManifoldEvaluationFactor : gtsam::NoiseModelFactor {
virtual class ManifoldEvaluationFactor : gtsam::NoiseModelFactor {
ManifoldEvaluationFactor();
ManifoldEvaluationFactor(gtsam::Key key, const T& z,
const gtsam::noiseModel::Base* model, const size_t N,
Expand All @@ -122,3 +126,32 @@ class ManifoldEvaluationFactor : gtsam::NoiseModelFactor {
const gtsam::noiseModel::Base* model, const size_t N,
double x, double a, double b);
};

// TODO(gerry): Add `DerivativeFactor`, `VectorDerivativeFactor`, and
// `ComponentDerivativeFactor`

#include <gtsam/basis/FitBasis.h>
// We'll allow transparent binding of python dict to Sequence in this
// compilation unit using pybind11/stl.h.
// Another alternative would be making Sequence opaque in
// python/gtsam/{preamble, specializations}, but std::map<double, double> is
// common enough that it may cause collisions, and we don't need
// reference-access anyway.
#include <pybind11/stl.h>

template <BASIS = {gtsam::FourierBasis, gtsam::Chebyshev1Basis,
gtsam::Chebyshev2Basis, gtsam::Chebyshev2}>
class FitBasis {
FitBasis(size_t N, const gtsam::Sequence& sequence,
const gtsam::noiseModel::Base* model);

static gtsam::NonlinearFactorGraph NonlinearGraph(
const gtsam::Sequence& sequence, const gtsam::noiseModel::Base* model,
size_t N);
static gtsam::GaussianFactorGraph::shared_ptr LinearGraph(
const gtsam::Sequence& sequence, const gtsam::noiseModel::Base* model,
size_t N);
Parameters parameters() const;
};

} // namespace gtsam
2 changes: 1 addition & 1 deletion gtsam/basis/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gtsamAddTestsGlob(base "test*.cpp" "" "gtsam")
gtsamAddTestsGlob(basis "test*.cpp" "" "gtsam")
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(interface_headers
${PROJECT_SOURCE_DIR}/gtsam/slam/slam.i
${PROJECT_SOURCE_DIR}/gtsam/sfm/sfm.i
${PROJECT_SOURCE_DIR}/gtsam/navigation/navigation.i
${PROJECT_SOURCE_DIR}/gtsam/basis/basis.i
)


Expand Down
2 changes: 1 addition & 1 deletion python/gtsam/preamble/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* automatic STL binding, such that the raw objects can be accessed in Python.
* Without this they will be automatically converted to a Python object, and all
* mutations on Python side will not be reflected on C++.
*/
*/
2 changes: 1 addition & 1 deletion python/gtsam/specializations/basis.h
Original file line number Diff line number Diff line change
Expand Up < 46FD /td> @@ -9,4 +9,4 @@
* interface, but without the `<pybind11/stl.h>` copying mechanism. Combined
* with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python,
* and saves one copy operation.
*/
*/
0