11 using namespace Eigen;
26 const std::size_t components,
27 const std::size_t dim_linear,
28 const std::size_t dim_circular,
29 const bool use_quaternion
31 components(components),
32 use_quaternion(use_quaternion),
33 dim_circular_component(use_quaternion ? 4 : 1),
34 dim(dim_linear + dim_circular * dim_circular_component),
35 dim_linear(dim_linear),
36 dim_circular(dim_circular),
38 dim_covariance(use_quaternion ? dim_linear + dim_circular * (dim_circular_component - 1) : dim),
39 mean_(dim, components),
40 covariance_(dim_covariance, dim_covariance * components),
43 for (
int i = 0; i < this->components; ++i)
44 weight_(i) = 1.0 / this->components;
66 std::size_t new_dim = dim_linear + dim_circular * dim_circular_component;
67 std::size_t new_dim_covariance = use_quaternion ? dim_linear + dim_circular * (dim_circular_component - 1) : new_dim;
69 if ((this->dim_linear == dim_linear) && (this->dim_circular == dim_circular) && (this->components == components))
71 else if ((this->dim == new_dim) && (this->components != components))
73 mean_.conservativeResize(NoChange, components);
74 covariance_.conservativeResize(NoChange, dim_covariance * components);
75 weight_.conservativeResize(components);
81 mean_.resize(new_dim, components);
82 covariance_.resize(new_dim_covariance, new_dim_covariance * components);
83 weight_.resize(components);
86 this->components = components;
88 this->dim_covariance = new_dim_covariance;
89 this->dim_linear = dim_linear;
90 this->dim_circular = dim_circular;
138 return covariance_.middleCols(this->dim_covariance * i, this->dim_covariance);
144 return covariance_(j, (this->dim_covariance * i) + k);
156 return covariance_.middleCols(this->dim_covariance * i, this->dim_covariance);
162 return covariance_(j, (this->dim_covariance * i) + k);
196 if (noise_covariance_matrix.rows() != noise_covariance_matrix.cols())
199 dim_noise = noise_covariance_matrix.rows();
201 dim_covariance += dim_noise;
204 mean_.conservativeResize(dim, NoChange);
205 mean_.bottomRows(dim_noise) = MatrixXd::Zero(dim_noise, components);
208 covariance_.conservativeResizeLike(MatrixXd::Zero(dim_covariance, dim_covariance * components));
216 std::size_t dim_old = use_quaternion ? dim_linear + dim_circular * (dim_circular_component - 1) : dim_linear + dim_circular;
217 for (std::size_t i = 0; i < (components - 1); i++)
219 std::size_t i_index = components - 1 - i;
221 Ref<MatrixXd> new_block = covariance_.block(0, i_index * dim_covariance, dim_old, dim_old);
222 Ref<MatrixXd> old_block = covariance_.block(0, i_index * dim_old, dim_old, dim_old);
225 for (std::size_t j = 0; j < dim_old; j++)
227 std::size_t j_index = dim_old - 1 - j;
229 new_block.col(j_index).swap(old_block.col(j_index));
233 for (std::size_t i = 0; i < components; i++)
236 covariance_.block(dim_old, i * dim_covariance + dim_old, dim_noise, dim_noise) = noise_covariance_matrix;
239 covariance_.block(0, i * dim_covariance + dim_old, dim_old, dim_noise) = MatrixXd::Zero(dim_old, dim_noise);