Sampler.cpp
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 #include <gtsam/linear/Sampler.h>
20 namespace gtsam {
21 
22 /* ************************************************************************* */
24  uint_fast64_t seed)
25  : model_(model), generator_(seed) {
26  if (!model) {
27  throw std::invalid_argument("Sampler::Sampler needs a non-null model.");
28  }
29 }
30 
31 /* ************************************************************************* */
33  : model_(noiseModel::Diagonal::Sigmas(sigmas, true)), generator_(seed) {}
34 
35 /* ************************************************************************* */
36 Vector Sampler::sampleDiagonal(const Vector& sigmas, std::mt19937_64* rng) {
37  size_t d = sigmas.size();
38  Vector result(d);
39  for (size_t i = 0; i < d; i++) {
40  double sigma = sigmas(i);
41 
42  // handle constrained case separately
43  if (sigma == 0.0) {
44  result(i) = 0.0;
45  } else {
46  std::normal_distribution<double> dist(0.0, sigma);
47  result(i) = dist(*rng);
48  }
49  }
50  return result;
51 }
52 
53 /* ************************************************************************* */
55  return sampleDiagonal(sigmas, &generator_);
56 }
57 
58 /* ************************************************************************* */
60  assert(model_.get());
61  const Vector& sigmas = model_->sigmas();
62  return sampleDiagonal(sigmas);
63 }
64 
65 /* ************************************************************************* */
66 
67 } // namespace gtsam
std::mt19937_64 generator_
Definition: Sampler.h:37
Vector sample() const
sample from distribution
Definition: Sampler.cpp:59
noiseModel::Diagonal::shared_ptr model_
Definition: Sampler.h:34
noiseModel::Diagonal::shared_ptr model
static std::mt19937 rng
static Vector sampleDiagonal(const Vector &sigmas, std::mt19937_64 *rng)
sample with given random number generator
Definition: Sampler.cpp:36
Vector sigmas() const
Definition: Sampler.h:68
Eigen::VectorXd Vector
Definition: Vector.h:38
Values result
sampling from a NoiseModel
traits
Definition: chartTesting.h:28
uint64_t uint_fast64_t
Definition: ms_stdint.h:116
static noiseModel::Diagonal::shared_ptr Diagonal(const Matrix &covariance)
static const double sigma
Sampler(const noiseModel::Diagonal::shared_ptr &model, uint_fast64_t seed=42u)
Definition: Sampler.cpp:23
std::shared_ptr< Diagonal > shared_ptr
Definition: NoiseModel.h:307


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