Bayes Filters Library
ParticleSet.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2019 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This software may be modified and distributed under the terms of the
5  * BSD 3-Clause license. See the accompanying LICENSE file for details.
6  */
7 
9 
10 using namespace bfl;
11 using namespace Eigen;
12 
14  ParticleSet(1, 1, 0, false)
15 { }
16 
17 
18 ParticleSet::ParticleSet(const std::size_t components, const std::size_t dim) noexcept:
19  ParticleSet(components, dim, 0, false)
20 { }
21 
22 
24 (
25  const std::size_t components,
26  const std::size_t dim_linear,
27  const std::size_t dim_circular,
28  const bool use_quaternion
29 ) noexcept :
30  GaussianMixture(components, dim_linear, dim_circular, use_quaternion),
31  state_(dim, components)
32 { }
33 
34 
35 void ParticleSet::resize(const std::size_t components, const std::size_t dim_linear, const std::size_t dim_circular)
36 {
37  std::size_t new_dim = dim_linear + dim_circular * dim_circular_component;
38 
39  if ((this->dim_linear == dim_linear) && (this->dim_circular = dim_circular) && (this->components == components))
40  return;
41  else if ((this->dim == new_dim) && (this->components != components))
42  state_.conservativeResize(NoChange, components);
43  else
44  {
45  // In any other case, it does not make sense to do conservative resize
46  // since either old data is truncated or new data is incomplete
47  state_.resize(new_dim, components);
48  }
49 
50  GaussianMixture::resize(components, dim_linear, dim_circular);
51 }
52 
53 
55 {
56  /* Should check whether (this->dim_linear == rhs.dim_linear) &&
57  (this->dim_circular == rhs.dim_circular). */
58  std::size_t new_components = components + rhs.components;
59 
60  state_.conservativeResize(NoChange, new_components);
61  state_.rightCols(rhs.components) = rhs.state_;
62 
63  mean_.conservativeResize(NoChange, new_components);
64  mean_.rightCols(rhs.components) = rhs.mean_;
65 
66  covariance_.conservativeResize(NoChange, dim_covariance * new_components);
67  covariance_.rightCols(dim_covariance * rhs.components) = rhs.covariance_;
68 
69  weight_.conservativeResize(new_components);
70  weight_.tail(rhs.components) = rhs.weight_;
71 
72  return *this;
73 }
74 
75 
77 {
78  lhs += rhs;
79 
80  return lhs;
81 }
82 
83 
84 Ref<MatrixXd> ParticleSet::state()
85 {
86  return state_;
87 }
88 
89 
90 Ref<MatrixXd> ParticleSet::state(const std::size_t i)
91 {
92  return state_.col(i);
93 }
94 
95 
96 double& ParticleSet::state(const std::size_t i, const std::size_t j)
97 {
98  return state_(j, i);
99 }
100 
101 
102 const Ref<const MatrixXd> ParticleSet::state() const
103 {
104  return state_;
105 }
106 
107 
108 const Ref<const MatrixXd> ParticleSet::state(const std::size_t i) const
109 {
110  return state_.col(i);
111 }
112 
113 
114 const double& ParticleSet::state(const std::size_t i, const std::size_t j) const
115 {
116  return state_(j, i);
117 }
bfl::GaussianMixture::covariance_
Eigen::MatrixXd covariance_
Definition: GaussianMixture.h:86
bfl::ParticleSet::ParticleSet
ParticleSet() noexcept
Definition: ParticleSet.cpp:13
bfl
Port of boost::any for C++11 compilers.
Definition: AdditiveMeasurementModel.h:13
bfl::GaussianMixture::components
std::size_t components
Definition: GaussianMixture.h:67
operator+
ParticleSet operator+(ParticleSet lhs, const ParticleSet &rhs)
Definition: ParticleSet.cpp:76
bfl::GaussianMixture::mean_
Eigen::MatrixXd mean_
Definition: GaussianMixture.h:84
bfl::ParticleSet::resize
void resize(const std::size_t components, const std::size_t dim_linear, const std::size_t dim_circular=0) override
Definition: ParticleSet.cpp:35
bfl::GaussianMixture::resize
virtual void resize(const std::size_t components, const std::size_t dim_linear, const std::size_t dim_circular=0)
Definition: GaussianMixture.cpp:64
bfl::ParticleSet::state_
Eigen::MatrixXd state_
Definition: ParticleSet.h:49
bfl::ParticleSet::state
Eigen::Ref< Eigen::MatrixXd > state()
Definition: ParticleSet.cpp:84
bfl::GaussianMixture::weight_
Eigen::VectorXd weight_
Definition: GaussianMixture.h:88
ParticleSet.h
bfl::ParticleSet
Definition: ParticleSet.h:20
bfl::GaussianMixture
Definition: GaussianMixture.h:20
bfl::ParticleSet::operator+=
ParticleSet & operator+=(const ParticleSet &rhs)
Definition: ParticleSet.cpp:54