FairRoot/PandaRoot
PndSomNode.h
Go to the documentation of this file.
1 /* ********************************
2  * Self Organizing Map node class *
3  * Author: M.Babai@rug.nl *
4  * Version: *
5  * LICENSE: *
6  * ********************************
7  */
8 //#pragma once
9 #ifndef PND_SOM_NODE_H
10 #define PND_SOM_NODE_H
11 
12 //________________________
13 #include <vector>
14 #include <string>
15 #include <map>
16 
17 //________________________
18 #define PRINT_PND_SOM_NODE_DEBUG 0
19 
21 {
22  public:
26  PndSomNode();
27 
32  explicit PndSomNode(size_t WeightsDim);
33 
38  explicit PndSomNode(std::vector<float> const& weight);
39 
45  PndSomNode( std::string const& label, std::vector<float> const& weight);
46 
55  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim = 0);
56 
66  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim,
67  std::string const& label);
68 
78  PndSomNode(int lft, int top, int rgt, int bot,
79  std::string const& label, std::vector<float> const& weight);
80 
81  // Copy Constructor
82  PndSomNode(PndSomNode const &oth);
83 
84  // Destructor
85  virtual ~PndSomNode();
86 
87  // Operators
88  // Assignment
89  PndSomNode& operator=(PndSomNode const &oth);
90 
91  /*
92  * Init the node.
93  * Currently only on a rectangular grid.
94  */
95  virtual void InitNode();
96 
97  // Modifiers:
101  inline int GetLeft() const;
102  inline void SetLeft(int val);
103 
104  inline int GetRight() const;
105  inline void SetRight(int val);
106 
107  inline int GetTop() const;
108  inline void SetTop(int val);
109 
110  inline int GetBottom() const;
111  inline void SetBottom(int val);
112 
116  inline size_t GetNodeDimension() const;
117  inline void SetNodeDimension( size_t val);
118 
122  inline std::string const& GetLabel() const;
123  inline void SetLabel(std::string const& val);
124 
129  inline std::vector<float> const& GetWeight() const;
130 
135  void SetWeight(std::vector<float> const& val);
136 
141  void SetNeighbours(std::vector< std::pair<size_t, double> > const& val);
142 
147  inline std::vector< std::pair<size_t, double> > const& GetNeighbours() const;
148 
153  inline double GetXPos() const;
154  inline void SetXPos( double xp);
155 
156  inline double GetYPos() const;
157  inline void SetYPos( double yp);
158 
162  void ResetRespList();
163 
167  void AddToRespList(size_t idx);
168  void SetRespList(std::vector<size_t> const& val);
169  std::vector<size_t> const& GetRespoList() const;
170 
175  void SetLabelMap(std::map<std::string, size_t> const &val);
176  std::map<std::string, size_t> const& GetLabelMap() const;
177 
181 #if (PRINT_PND_SOM_NODE_DEBUG > 0)
182  void PrintNode() const;
183 #endif
184 
185  protected:
186 
187  private:
188  //_______________ Functions ____________________
189  // Clear the internal data structure (reset).
191 
192  /*
193  * Adjust the weights for the current node (not used in the batch
194  * mode).
195  */
196  void AdjustWeights( std::vector<double> const& target,
197  double LearningRate, double Influence);
198 
199  //___________________ Variables ___________________
200  // Neighbour indices (2D for visualization)
201  int m_iLeft;
202  int m_iTop;
203  int m_iRight;
205 
206  // Position of the node in the grid cell
207  double m_xPos;
208  double m_yPos;
209 
210  // Dimension of the weights
211  size_t m_weightDim;
212 
213  // Label of the current node.
214  std::string m_label;
215 
216  // Weight vector of the current node.
217  std::vector<float> m_Weights;
218 
219  /*
220  * Indices of the actual data point which are under the
221  * responsibility of the current node.
222  */
223  std::vector<size_t> m_RespNodeIndex;
224 
225  // <Index, distance> of the neighbours for the current map node.
226  std::vector< std::pair<size_t, double> > m_NeighbourList;
227 
228  // Map holding counts per label
229  std::map<std::string, size_t> m_labelCnts;
230 };// End of class definition
231 
232 //______________ Inline functions ____________________
233 inline int PndSomNode::GetLeft() const
234 {
235  return this->m_iLeft;
236 };
237 
238 inline void PndSomNode::SetLeft(int val)
239 {
240  this->m_iLeft = val;
241 };
242 
243 inline int PndSomNode::GetRight() const
244 {
245  return this->m_iRight;
246 };
247 
248 inline void PndSomNode::SetRight(int val)
249 {
250  this->m_iRight = val;
251 };
252 
253 inline int PndSomNode::GetTop() const
254 {
255  return this->m_iTop;
256 };
257 
258 inline void PndSomNode::SetTop(int val)
259 {
260  this->m_iTop = val;
261 };
262 
263 inline int PndSomNode::GetBottom() const
264 {
265  return this->m_iBottom;
266 };
267 
268 inline void PndSomNode::SetBottom(int val)
269 {
270  this->m_iBottom = val;
271 };
272 
273 inline size_t PndSomNode::GetNodeDimension() const
274 {
275  return this->m_weightDim;
276 };
277 
279 {
280  this->m_weightDim = val;
281 };
282 
283 inline std::string const& PndSomNode::GetLabel() const
284 {
285  return this->m_label;
286 };
287 
288 inline void PndSomNode::SetLabel(std::string const& val)
289 {
290  this->m_label = val;
291 };
292 
293 inline std::vector<float> const& PndSomNode::GetWeight() const
294 {
295  return this->m_Weights;
296 };
297 
298 inline double PndSomNode::GetXPos() const
299 {
300  return this->m_xPos;
301 };
302 
303 inline void PndSomNode::SetXPos( double xp)
304 {
305  this->m_xPos = xp;
306 };
307 
308 inline double PndSomNode::GetYPos() const
309 {
310  return this->m_yPos;
311 };
312 
313 inline void PndSomNode::SetYPos( double yp)
314 {
315  this->m_yPos = yp;
316 };
317 
318 inline std::vector< std::pair<size_t, double> > const& PndSomNode::GetNeighbours() const
319 {
320  return this->m_NeighbourList;
321 };
322 #endif// End of interface
size_t GetNodeDimension() const
Definition: PndSomNode.h:273
std::vector< float > m_Weights
Definition: PndSomNode.h:217
std::vector< float > const & GetWeight() const
Definition: PndSomNode.h:293
std::vector< size_t > const & GetRespoList() const
std::map< std::string, size_t > const & GetLabelMap() const
double m_yPos
Definition: PndSomNode.h:208
void AddToRespList(size_t idx)
void SetBottom(int val)
Definition: PndSomNode.h:268
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
int GetRight() const
Definition: PndSomNode.h:243
PndSomNode & operator=(PndSomNode const &oth)
void SetXPos(double xp)
Definition: PndSomNode.h:303
std::string m_label
Definition: PndSomNode.h:214
void SetLabelMap(std::map< std::string, size_t > const &val)
size_t m_weightDim
Definition: PndSomNode.h:211
TGeoVolume * top
int m_iRight
Definition: PndSomNode.h:203
int GetBottom() const
Definition: PndSomNode.h:263
double GetXPos() const
Definition: PndSomNode.h:298
void SetRight(int val)
Definition: PndSomNode.h:248
int m_iBottom
Definition: PndSomNode.h:204
int idx[MAX]
Definition: autocutx.C:38
void SetYPos(double yp)
Definition: PndSomNode.h:313
void SetNeighbours(std::vector< std::pair< size_t, double > > const &val)
void SetTop(int val)
Definition: PndSomNode.h:258
void SetWeight(std::vector< float > const &val)
std::vector< std::pair< size_t, double > > m_NeighbourList
Definition: PndSomNode.h:226
double m_xPos
Definition: PndSomNode.h:207
void SetRespList(std::vector< size_t > const &val)
virtual void InitNode()
void ClearInternalStructures()
int GetLeft() const
Definition: PndSomNode.h:233
void SetLabel(std::string const &val)
Definition: PndSomNode.h:288
std::vector< size_t > m_RespNodeIndex
Definition: PndSomNode.h:223
virtual ~PndSomNode()
std::map< std::string, size_t > m_labelCnts
Definition: PndSomNode.h:229
void AdjustWeights(std::vector< double > const &target, double LearningRate, double Influence)
int GetTop() const
Definition: PndSomNode.h:253
void SetNodeDimension(size_t val)
Definition: PndSomNode.h:278
std::string const & GetLabel() const
Definition: PndSomNode.h:283
std::vector< std::pair< size_t, double > > const & GetNeighbours() const
Definition: PndSomNode.h:318
void SetLeft(int val)
Definition: PndSomNode.h:238
double GetYPos() const
Definition: PndSomNode.h:308
void ResetRespList()