indii/ml/filter/RegularisedParticleResampler.hpp

00001 #ifndef INDII_ML_FILTER_REGULARISEDPARTICLERESAMPLER_HPP
00002 #define INDII_ML_FILTER_REGULARISEDPARTICLERESAMPLER_HPP
00003 
00004 #include "ParticleResampler.hpp"
00005 #include "../aux/Almost2Norm.hpp"
00006 #include "../aux/AlmostGaussianKernel.hpp"
00007 
00008 namespace indii {
00009   namespace ml {
00010     namespace filter {
00011 /**
00012  * Regularised particle resampler.
00013  *
00014  * @author Lawrence Murray <lawrence@indii.org>
00015  * @version $Rev: 576 $
00016  * @date $Date: 2008-11-16 15:24:50 +0000 (Sun, 16 Nov 2008) $
00017  *
00018  * Adds standardised kernel noise to each particle. Another resampler, such
00019  * as DeterministicParticleResampler, should usually be applied first.
00020  *
00021  * @param NT Norm type.
00022  * @param KT Kernel type.
00023  */
00024 template <class NT = indii::ml::aux::Almost2Norm,
00025     class KT = indii::ml::aux::AlmostGaussianKernel>
00026 class RegularisedParticleResampler : public ParticleResampler {
00027 public:
00028   /**
00029    * Constructor.
00030    *
00031    * @param N The kernel density norm.
00032    * @param K The kernel density kernel.
00033    */
00034   RegularisedParticleResampler(const NT& N, const KT& K);
00035 
00036   /**
00037    * Destructor.
00038    */
00039   virtual ~RegularisedParticleResampler();
00040 
00041   /**
00042    * Set the kernel density norm.
00043    *
00044    * @param N The kernel density norm.
00045    */
00046   void setNorm(const NT& N);
00047 
00048   /**
00049    * Set the kernel density kernel.
00050    *
00051    * @param K The kernel density kernel.
00052    */
00053   void setKernel(const KT& K);
00054 
00055   /**
00056    * Resample the distribution.
00057    *
00058    * @return The resampled distribution.
00059    */
00060   virtual indii::ml::aux::DiracMixturePdf resample(
00061       indii::ml::aux::DiracMixturePdf& p);
00062 
00063 private:
00064   /**
00065    * \f$\|\mathbf{x}\|_p\f$; the norm.
00066    */
00067   NT N;
00068   
00069   /**
00070    * \f$K(\|\mathbf{x}\|_p) \f$; the density kernel.
00071    */
00072   KT K;
00073 
00074 };
00075 
00076     }
00077   }
00078 }
00079 
00080 #include "../aux/KernelDensityMixturePdf.hpp"
00081 #include "../aux/KDTree.hpp"
00082 
00083 template <class NT, class KT>
00084 indii::ml::filter::RegularisedParticleResampler<NT,KT>::RegularisedParticleResampler(
00085     const NT& N, const KT& K) : N(N), K(K) {
00086   //
00087 }
00088 
00089 template <class NT, class KT>
00090 indii::ml::filter::RegularisedParticleResampler<NT,KT>::~RegularisedParticleResampler() {
00091   //
00092 }
00093 
00094 template <class NT, class KT>
00095 void indii::ml::filter::RegularisedParticleResampler<NT,KT>::setNorm(const NT& N) {
00096   this->N = N;
00097 }
00098 
00099 template <class NT, class KT>
00100 void indii::ml::filter::RegularisedParticleResampler<NT,KT>::setKernel(const KT& K) {
00101   this->K = K;
00102 }
00103 
00104 template <class NT, class KT>
00105 indii::ml::aux::DiracMixturePdf
00106     indii::ml::filter::RegularisedParticleResampler<NT,KT>::resample(
00107     indii::ml::aux::DiracMixturePdf& p) {
00108   namespace aux = indii::ml::aux;
00109 
00110   unsigned int i;
00111   aux::DiracMixturePdf r(p.getDimensions());
00112   aux::vector x(p.getDimensions());
00113 
00114   /* standardise particles */
00115   aux::lower_triangular_matrix sd(p.getDistributedStandardDeviation());
00116 
00117   /* rebuild distribution with kernel noise */
00118   for (i = 0; i < p.getSize(); i++) {
00119     noalias(x) = p.get(i) + prod(sd, K.sample() * N.sample(
00120         p.getDimensions()));
00121     r.add(x, p.getWeight(i));
00122   }
00123 
00124   return r;
00125 }
00126 
00127 #endif
00128 
00129 

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3