iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticlePDF.H
Go to the documentation of this file.
1 /*! @file
2  @author Lior Elazary
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_PROBABILISTIC_TYPES_PARTICLEPDF_H
37 #define INCLUDE_NRT_PROBABILISTIC_TYPES_PARTICLEPDF_H
38 
39 #include <nrt/Eigen/Eigen.H>
40 #include <iostream>
41 #include <memory>
42 
43 #include <nrt/External/cereal/types/vector.hpp>
44 
45 // Include some definitions of no interest to the user
48 
49 namespace nrt
50 {
51  //! Particle representation of a variable
52  /*! This class holds the memory for Particle variables */
53  template <class PDFDef, class WeightDef=double>
55  {
56  public:
57 
58  //! Define a particle width a weight
59  struct Particle
60  {
61  Eigen::Matrix<double, PDFDef::size, 1> data; //The data for the particle
62  WeightDef weight; //The weight of the particle
63 
64  //! Serialization
65  template<class Archive> void serialize(Archive & ar)
66  {
67  ar( data, weight );
68  }
69  };
70 
71  //! Construct an empty particle PDF
72  explicit ParticlePDF();
73 
74  //! Construct a particle PDF with n particles
75  explicit ParticlePDF(int const n);
76 
77  //! Construct a particle PDF by sampling a gaussian PDF at the sigma locations
78  explicit ParticlePDF(GaussianPDF<PDFDef> const & gauss);
79 
80  //! Copy constructor
82 
83  virtual ~ParticlePDF();
84 
85  //! Set/Get the value of any variable
86  double & at(int const idx, double & addr);
87 
88  //! Set/Get the value of any variable (const version)
89  double const at(int const idx, double & addr) const;
90 
91  //! Set/Get the weight of any particle
92  WeightDef & at(int const idx);
93 
94  //! Set/Get the weight of any particle (const version)
95  WeightDef const at(int const idx) const;
96 
97  //! Return the number of particles
98  const size_t size() const;
99 
100  //! Return the size of the state
101  const size_t stateSize() const;
102 
103  //! Assign a ParticlePDF to another
105 
106  public:
107  std::vector<Particle> itsParticles; //The particles
108  Eigen::Matrix<double, PDFDef::size, 1> itsElemMem; //Memory to access the elements
109  std::shared_ptr<PDFDef> elem; //Raw access to the elements (this needs to be after)
110  typedef PDFDef ElemType;
111 
112  protected:
113  friend class cereal::access;
114  template<class Archive> void save(Archive & ar) const
115  {
116  ar( itsParticles, itsElemMem );
117  }
118  template<class Archive> void load(Archive & ar)
119  {
120  ar( itsParticles, itsElemMem );
121  elem = std::shared_ptr<PDFDef>(new PDFDef(itsElemMem));
122  }
123  };
124 }
125 
127 
128 #endif // INCLUDE_NRT_PROBABILISTIC_TYPES_PARTICLEPDF_H