gtsam
Loading...
Searching...
No Matches
Sampler.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#pragma once
20
21#include <gtsam/base/Manifold.h>
23
24#include <random>
25
26namespace gtsam {
27
32class GTSAM_EXPORT Sampler {
33 protected:
35 noiseModel::Diagonal::shared_ptr model_;
36
38 mutable std::mt19937_64 generator_;
39
41 mutable std::mt19937_64* externalGenerator_ = nullptr;
42
43 public:
44 typedef std::shared_ptr<Sampler> shared_ptr;
45
48
59 explicit Sampler(const noiseModel::Diagonal::shared_ptr& model,
60 uint_fast64_t seed = 42u);
61
67 explicit Sampler(const noiseModel::Diagonal::shared_ptr& model,
68 std::mt19937_64& rng);
69
80 explicit Sampler(const Vector& sigmas, uint_fast64_t seed = 42u);
81
88 explicit Sampler(const Vector& sigmas, std::mt19937_64& rng);
89
93
94 size_t dim() const { return model_->dim(); }
95
96 Vector sigmas() const { return model_->sigmas(); }
97
98 const noiseModel::Diagonal::shared_ptr& model() const { return model_; }
99
103
105 Vector sample() const;
106
112 template <typename T>
113 T perturb(const T& value) const {
114 return traits<T>::Retract(value, sample());
115 }
116
118 static Vector sampleDiagonal(const Vector& sigmas, std::mt19937_64* rng);
120
121 protected:
126 Vector sampleDiagonal(const Vector& sigmas) const;
127};
128
129} // namespace gtsam
Base class and basic functions for Manifold types.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Sampler(const noiseModel::Diagonal::shared_ptr &model, uint_fast64_t seed=42u)
Create a sampler for the distribution specified by a diagonal NoiseModel with a manually specified se...
Definition Sampler.cpp:26
std::mt19937_64 * externalGenerator_
Non-owning optional external generator. If non-null, sampling uses this.
Definition Sampler.h:41
Vector sample() const
sample from distribution
Definition Sampler.cpp:80
noiseModel::Diagonal::shared_ptr model_
noiseModel created at generation
Definition Sampler.h:35
T perturb(const T &value) const
Perturb a value by sampling in its tangent space and applying retract.
Definition Sampler.h:113
std::mt19937_64 generator_
generator
Definition Sampler.h:38