// %pacpus:license{ // This file is part of the PACPUS framework distributed under the // CECILL-C License, Version 1.0. // %pacpus:license} /// @file /// @author Firstname Surname /// @date Month, Year /// @version $Id: gaussian_sum_filtering.hpp 76 2013-01-10 17:05:10Z kurdejma $ /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved. /// @brief Brief description. /// /// Detailed description. #ifndef __GAUSSIAN_FILTERING_BASE__ #define __GAUSSIAN_FILTERING_BASE__ #include "kalman_filtering.hpp" #include "../math/pdf.hpp" #include namespace filter{ namespace gaussiansum{ using namespace math; // using namespace rng; using namespace ublas; /*! * \class Gaussian * \brief This class describes a basic weighted kalman state */ class Gaussian : public filter::kalman::State{ public : /*! * \brief Constructor * \param state_size : Size of the state vector * \param weight_ : Initial weight */ Gaussian(const size_t &state_size, const double &weight_){ filter::kalman::State::Allocator(state_size); weight=weight_; } /** * \brief Constructor * \param state_size : Size of the state vector */ Gaussian(const size_t &state_size){ filter::kalman::State::Allocator(state_size); weight=0; } double weight; /*!< Weight of the Kalman state */ /* protected :*/ // Gaussian:weight(1){}; }; /*! * \class GaussianSet * \brief This method describes a set of gaussians \n * A set of gaussains is reprented by a vector of weighted kalman state \n * somes methods can be applied to the set of particles like :\n * estimate computation, resampling scheme or normalization method \n */ template class GaussianSet { public : /** Normalize the weights of gaussian states*/ void NormalizeWeights(); /*! * \brief Allocate the set of gaussians * \param ngaussian : number of gaussians in the set */ void Allocator(const size_t &ngaussian); /*! * \brief Compute the estimate * \return Vector */ Vector Estimate(); /*! * \brief Destructor */ ~GaussianSet(){} std::vector gaussians; /*!< gaussian states */ }; template void GaussianSet::NormalizeWeights(){ double sum=0; for(typename std::vector::iterator I=gaussians.begin();I!=gaussians.end();I++) sum+=(*I).weight; if(sum==0){throw filter_error("Gaussian set normalization weight sum =0");} for(typename std::vector::iterator I=gaussians.begin();I!=gaussians.end();I++) (*I).weight/=sum; } template void GaussianSet::Allocator(const size_t &ngaussian){ gaussians.reserve(ngaussian); } template Vector GaussianSet::Estimate(){ Vector estimate = ZeroVector(gaussians[0].X.size()); for(typename std::vector::iterator I=gaussians.begin();I!=gaussians.end();I++) estimate+=(*I).X*(*I).weight; return estimate; } /*! * \class LinearDynamicEquation * \brief This class describes a linear dynamic equation */ template