MultiModelFilter.cpp
Go to the documentation of this file.
1 /************************************************************************
2  * Copyright (C) 2012 Eindhoven University of Technology (TU/e). *
3  * All rights reserved. *
4  ************************************************************************
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above *
10  * copyright notice, this list of conditions and the following *
11  * disclaimer. *
12  * *
13  * 2. Redistributions in binary form must reproduce the above *
14  * copyright notice, this list of conditions and the following *
15  * disclaimer in the documentation and/or other materials *
16  * provided with the distribution. *
17  * *
18  * THIS SOFTWARE IS PROVIDED BY TU/e "AS IS" AND ANY EXPRESS OR *
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21  * ARE DISCLAIMED. IN NO EVENT SHALL TU/e OR CONTRIBUTORS BE LIABLE *
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
28  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
29  * DAMAGE. *
30  * *
31  * The views and conclusions contained in the software and *
32  * documentation are those of the authors and should not be *
33  * interpreted as representing official policies, either expressed or *
34  * implied, of TU/e. *
35  ************************************************************************/
36 
37 #include "MultiModelFilter.h"
38 #include "KalmanFilter.h"
39 
40 #include "PositionFilter.h"
41 
42 MultiModelFilter::MultiModelFilter() : initialized_(false) {
43  PositionFilter* e1 = new PositionFilter();
44  e1->setParameter("max_acceleration", 0.0);
45 
46  PositionFilter* e2 = new PositionFilter();
47  e2->setParameter("max_acceleration", 8.0);
48 
49  addEstimator(e1);
50  addEstimator(e2);
51 }
52 
54  mixture_(orig.mixture_) {
55  for(unsigned int i = 0; i < orig.estimators_.size(); ++i) {
56  estimators_.push_back(orig.estimators_[i]->clone());
57  weights_.push_back(orig.weights_[i]);
58  }
59 }
60 
62  for(unsigned int i = 0; i < estimators_.size(); ++i) {
63  delete estimators_[i];
64  }
65 }
66 
68  return new MultiModelFilter(*this);
69 }
70 
72  estimators_.push_back(estimator);
73 
74  weights_.resize(estimators_.size());
75  for(unsigned int i = 0; i < estimators_.size(); ++i) {
76  weights_[i] = 1 / (double)estimators_.size();
77  }
78 }
79 
81  for(unsigned int i = 0; i < estimators_.size(); ++i) {
82  estimators_[i]->propagate(time);
83  }
84 
85  // propagate weights (TODO: use transition matrix here)
86  double w0 = 0.5 * weights_[0] + 0.5 * weights_[1];
87  double w1 = 0.5 * weights_[0] + 0.5 * weights_[1];
88 
89  weights_[0] = w0;
90  weights_[1] = w1;
91 }
92 
93 void MultiModelFilter::update(const pbl::PDF& z, const mhf::Time& time) {
94  if (!initialized_) {
95  for(unsigned int i = 0; i < estimators_.size(); ++i) {
96  estimators_[i]->update(z, time);
97  }
98  initialized_ = true;
99  return;
100  }
101 
102  // update weights based on likelihoods
103  double total_weight = 0;
104  for(unsigned int i = 0; i < estimators_.size(); ++i) {
105  weights_[i] = weights_[i] * estimators_[i]->getValue().getLikelihood(z);
106  total_weight += weights_[i];
107  }
108 
109  // normalize weights and find best estimator
110  unsigned int i_best = 0;
111  for(unsigned int i = 0; i < estimators_.size(); ++i) {
112  weights_[i] /= total_weight;
113  if (weights_[i] > weights_[i_best]) {
114  i_best = i;
115  }
116  }
117 
118  // update most probable estimator with the evidence, set others to 0 weight
119  for(unsigned int i = 0; i < estimators_.size(); ++i) {
120  if (i == i_best) {
121  weights_[i] = 1;
122  } else {
123  weights_[i] = 0;
124  estimators_[i]->reset();
125  }
126  estimators_[i]->update(z, time);
127  }
128 }
129 
131  for(unsigned int i = 0; i < estimators_.size(); ++i) {
132  estimators_[i]->reset();
133  }
134 }
135 
137  mixture_.clear();
138  for(unsigned int i = 0; i < estimators_.size(); ++i) {
140  }
142  return mixture_;
143 }
144 
146 
147 }
148 
149 bool MultiModelFilter::setParameter(const std::string& param, bool b) {
150  return false;
151 }
152 
153 bool MultiModelFilter::setParameter(const std::string &param, double v) {
154  return true;
155 }
156 
std::vector< mhf::IStateEstimator * > estimators_
virtual ~MultiModelFilter()
void normalizeWeights()
void addEstimator(mhf::IStateEstimator *estimator)
const pbl::PDF & getValue() const
Returns the current estimated state value.
void setValue(const pbl::PDF &pdf)
bool setParameter(const std::string &param, bool b)
Set a boolean parameter of this state estimator.
double Time
void addComponent(const PDF &pdf, double w)
virtual MultiModelFilter * clone() const
virtual void reset()
Resets the internal state of the estimator to its initial value.
Estimator specialized in estimating the position of a target. The estimator uses a Kalman filter with...
virtual void propagate(const mhf::Time &time)
Propagates the internal state to Time time.
void update(const pbl::PDF &z, const mhf::Time &time)
Updates the internal state based on measurement z.
bool setParameter(const std::string &param, bool b)
Set a boolean parameter of this state estimator.
pbl::Mixture mixture_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::vector< double > weights_


wire_state_estimators
Author(s): Sjoerd van den Dries, Jos Elfring
autogenerated on Fri Apr 16 2021 02:32:34