FairRoot/PandaRoot
PndMvaSOMTrainer.h
Go to the documentation of this file.
1 /* ****************************************
2  * Self Organizing Map Training functions *
3  * Author: M.Babai@rug.nl *
4  * Version: *
5  * LICENSE: *
6  * ****************************************
7  */
8 //#pragma once
9 #ifndef PND_SOM_TRAINER_H
10 #define PND_SOM_TRAINER_H
11 
12 //________________________
13 #include <vector>
14 
15 //________________________
16 class PndSomNode;
17 
18 //________________________
19 class TRandom3;
20 
24 typedef std::vector< std::pair<std::string, std::vector<float>*> > DataPoints;
25 
29 typedef enum MapNodeInitType{
30  SOM_RAND_FROM_DATA = 0, // Select randomly from data vector.
31  SOM_RANDOM = 1 // Use random numbers
33 
34 /*
35  * Scheme for the shape of the grid.
36 */
37 typedef enum GridInitType{
38  RECTANGULAR = 0, // Init rectangular grid
39  HEXAGONAL = 1 // Init hexagonal grid
40 } GridInitType;
41 
42 // Debug constants, 0 = no DEBUG, 1 = DEBUG info
43 #define PRINT_PND_SOM_TRAIN_DEBUG_INFO 1
44 
46 {
47  //----------------------------------------
48  //================== public ==============
49  public:
50 
59  explicit PndMvaSomTrainer( DataPoints const* const InputData,
60  size_t mapWidth, size_t mapHeight, size_t numIter,
62  GridInitType gridInitType = RECTANGULAR);
66  virtual ~PndMvaSomTrainer();
67 
71  virtual void InitMap();
72 
77  virtual void TrainBatch();
78 
83  virtual void TrainOnline();
84 
91  virtual void Calibrate();
92 
93  //____________ Getters and Setters ______
94  //________________________________________
98  inline std::vector<PndSomNode*> const& GetTheMap() const;
99 
104  inline DataPoints const& GetInputDataSet() const;
105 
109  inline size_t GetNumNodes() const;
110 
114  inline void SetSigmaZero(double val);
115  inline double GetSigmaZero() const;
116 
120  inline void SetLambda(double val);
121  inline double GetLambda() const;
122 
127  inline MapNodeInitType GetNodeInitType() const;
128 
132  inline size_t GetMapHeight() const;
133  inline void SetMapHeight(size_t val);
134 
135  inline size_t GetMapWidth() const;
136  inline void SetMapWidth(size_t val);
137 
141  inline size_t GetNumIterations() const;
142  inline void SetNumIterations(size_t val);
143 
144  //--------------------------------------------
145  //================= protected ================
146  protected:
147 
148  //_____________ DEBUG _________________
149 #if (PRINT_PND_SOM_TRAIN_DEBUG_INFO > 0)
150  void printMapGrid() const;
151 #endif
152 
153  //--------------------------------------------
154  //================= private ==================
155 
156  private:
157  //_______________ Functions ____________________
158  // To avoid mistakes, :).
159  PndMvaSomTrainer(PndMvaSomTrainer const& oth);/* Copy */
160  PndMvaSomTrainer& operator=(PndMvaSomTrainer const& oth);/*Assign*/
161 
162  /*
163  * Init a rectangular grid.
164  */
165  void InitGridRectAngular();
166 
167  /*
168  * Init a hexagonal grid.
169  */
170  void InitGridHexagonal();
171 
172  /*
173  * Initialize map nodes using random vectors fetched from the data
174  * set.
175  */
177 
178  /*
179  * Initialize map nodes using vectors with random numbers.
180  */
181  void InitMapnodes_Random();
182 
183  /*
184  * Returns the index of the BMU map node.
185  *
186  *@param vector vector containing the coordinates of the current
187  * data point.
188  */
189  size_t FindBestMatchingNode(std::vector<float> const& vector);
190 
191  //___________________ Variables ___________________
192  double m_sigmaZero;//the width of the lattice at time t0
193  double m_lambda;// A time constant, determine neighborhood
194  double m_neighbourhoodRadius; //the current width of area of influence
195 
196  size_t m_MapWidth;// Width of the map
197  size_t m_MapHeight;// Height of the map
198  size_t m_NumModelVectors;// Number of map nodes
199  size_t m_NumIterations;//Number of iterations for learning.
200 
202  GridInitType m_GridType;// Shape of the map grid.
203  std::vector<PndSomNode*> m_TheMap;// The actual map container
204  DataPoints const* m_DataSet;// Data points used to train the map.
205 };// End of class definition
206 
207 //---------------------- INLINE functions ____________
208 inline std::vector<PndSomNode*> const& PndMvaSomTrainer::GetTheMap() const
209 {
210  return this->m_TheMap;
211 };
212 
214 {
215  return (*(this->m_DataSet));
216 };
217 
219 {
220  this->m_sigmaZero = val;
221 };
222 
223 inline void PndMvaSomTrainer::SetLambda(double val)
224 {
225  this->m_lambda = val;
226 };
227 
229 {
230  this->m_InitMode = val;
231 };
232 
233 inline double PndMvaSomTrainer::GetSigmaZero() const
234 {
235  return this->m_sigmaZero;
236 };
237 
238 inline double PndMvaSomTrainer::GetLambda() const
239 {
240  return this->m_lambda;
241 };
242 
244 {
245  return this->m_InitMode;
246 };
247 
248 inline size_t PndMvaSomTrainer::GetMapHeight() const
249 {
250  return this->m_MapHeight;
251 };
252 
254 {
255  this->m_MapHeight = val;
256 };
257 
258 inline size_t PndMvaSomTrainer::GetMapWidth() const
259 {
260  return this->m_MapWidth;
261 };
262 
264 {
265  this->m_MapWidth = val;
266 };
267 
268 inline size_t PndMvaSomTrainer::GetNumNodes() const
269 {
270  return (this->m_MapWidth * this->m_MapHeight);
271 };
272 
274 {
275  return this->m_NumIterations;
276 };
277 
279 {
280  this->m_NumIterations = val;
281 };
282 #endif// End of interface
void InitMapnodes_Random()
void SetSigmaZero(double val)
size_t GetNumIterations() const
double GetLambda() const
virtual ~PndMvaSomTrainer()
void printMapGrid() const
virtual void InitMap()
MapNodeInitType m_InitMode
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
void InitMapnodes_RandomFromData()
MapNodeInitType
virtual void Calibrate()
void SetMapHeight(size_t val)
double GetSigmaZero() const
void InitGridRectAngular()
GridInitType m_GridType
std::vector< PndSomNode * > const & GetTheMap() const
size_t GetMapHeight() const
virtual void TrainOnline()
void SetMapWidth(size_t val)
size_t GetMapWidth() const
void SetNumIterations(size_t val)
PndMvaSomTrainer(DataPoints const *const InputData, size_t mapWidth, size_t mapHeight, size_t numIter, MapNodeInitType initType=SOM_RAND_FROM_DATA, GridInitType gridInitType=RECTANGULAR)
void SetNodeInitType(MapNodeInitType val=SOM_RAND_FROM_DATA)
MapNodeInitType GetNodeInitType() const
DataPoints const & GetInputDataSet() const
void SetLambda(double val)
void InitGridHexagonal()
GridInitType
DataPoints const * m_DataSet
std::vector< PndSomNode * > m_TheMap
std::vector< std::pair< std::string, std::vector< float > * > > DataPoints
virtual void TrainBatch()
std::vector< std::pair< std::string, std::vector< float > * > > DataPoints
Data structure of the space points and the cluster centers.
Definition: PndMvaCluster.h:24
size_t FindBestMatchingNode(std::vector< float > const &vector)
size_t GetNumNodes() const
PndMvaSomTrainer & operator=(PndMvaSomTrainer const &oth)