Bayes Filters Library
UKFPrediction.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 bfl::sigma_point;
12 using namespace Eigen;
13 
14 
16 (
17  std::unique_ptr<StateModel> state_model,
18  const double alpha,
19  const double beta,
20  const double kappa
21 ) noexcept :
22  state_model_(std::move(state_model)),
23  type_(UKFPredictionType::Generic),
24  ut_weight_(state_model_->getInputDescription(), alpha, beta, kappa)
25 { }
26 
27 
29 (
30  std::unique_ptr<AdditiveStateModel> state_model,
31  const double alpha,
32  const double beta,
33  const double kappa
34 ) noexcept :
35  add_state_model_(std::move(state_model)),
36  type_(UKFPredictionType::Additive),
37  ut_weight_(add_state_model_->getInputDescription().noiseless_description(), alpha, beta, kappa)
38 { }
39 
40 
42  GaussianPrediction(std::move(prediction)),
43  state_model_(std::move(prediction.state_model_)),
44  add_state_model_(std::move(prediction.add_state_model_)),
45  type_(prediction.type_),
46  ut_weight_(std::move(prediction.ut_weight_))
47 { }
48 
49 
51 {
52  if (this == &prediction)
53  return *this;
54 
55  GaussianPrediction::operator=(std::move(prediction));
56 
57  state_model_ = std::move(prediction.state_model_);
58 
59  add_state_model_ = std::move(prediction.add_state_model_);
60 
61  type_ = prediction.type_;
62 
63  ut_weight_ = std::move(prediction.ut_weight_);
64 
65  return *this;
66 }
67 
68 
70 {
71  if (type_ == UKFPredictionType::Additive)
72  return *add_state_model_;
73 
74  return *state_model_;
75 }
76 
77 
78 void UKFPrediction::predictStep(const GaussianMixture& prev_state, GaussianMixture& pred_state)
79 {
80  if (getStateModel().is_skipping())
81  {
82  pred_state = prev_state;
83 
84  return;
85  }
86 
87 
88  /* Evaluate predicted mean and predicted covariance using unscented transform. */
89  if (type_ == UKFPredictionType::Generic)
90  {
91  /* Augment the previous state using process noise statistics. */
92  GaussianMixture prev_state_augmented = prev_state;
93  prev_state_augmented.augmentWithNoise(state_model_->getNoiseCovarianceMatrix());
94 
95  std::tie(pred_state, std::ignore) = unscented_transform(prev_state_augmented, ut_weight_, *state_model_);
96  }
97  else if (type_ == UKFPredictionType::Additive)
98  {
99  std::tie(pred_state, std::ignore) = unscented_transform(prev_state, ut_weight_, *add_state_model_);
100  }
101 }
bfl::UKFPrediction::getStateModel
StateModel & getStateModel() noexcept override
Definition: UKFPrediction.cpp:69
bfl::UKFPrediction
Definition: UKFPrediction.h:25
bfl
Port of boost::any for C++11 compilers.
Definition: AdditiveMeasurementModel.h:13
bfl::GaussianPrediction::operator=
GaussianPrediction & operator=(const GaussianPrediction &prediction) noexcept=delete
bfl::sigma_point::unscented_transform
std::tuple< bool, GaussianMixture, Eigen::MatrixXd > unscented_transform(const GaussianMixture &input, const UTWeight &weight, FunctionEvaluation function)
Definition: sigma_point.cpp:126
bfl::UKFPrediction::operator=
UKFPrediction & operator=(const UKFPrediction &prediction) noexcept=delete
bfl::UKFPrediction::UKFPrediction
UKFPrediction(std::unique_ptr< StateModel > state_model, const double alpha, const double beta, const double kappa) noexcept
Definition: UKFPrediction.cpp:16
bfl::GaussianPrediction
Definition: GaussianPrediction.h:23
UKFPrediction.h
bfl::UKFPrediction::predictStep
void predictStep(const GaussianMixture &prev_state, GaussianMixture &pred_state) override
Definition: UKFPrediction.cpp:78
bfl::sigma_point
Definition: sigma_point.h:27
bfl::StateModel
Definition: StateModel.h:22
bfl::GaussianMixture::augmentWithNoise
bool augmentWithNoise(const Eigen::Ref< const Eigen::MatrixXd > &noise_covariance_matrix)
Definition: GaussianMixture.cpp:190
bfl::GaussianMixture
Definition: GaussianMixture.h:20