PandaRoot
PndSomNode.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /* ********************************
14  * Self Organizing Map node class *
15  * Author: M.Babai@rug.nl *
16  * Version: *
17  * LICENSE: *
18  * ********************************
19  */
20 //#pragma once
21 #ifndef PND_SOM_NODE_H
22 #define PND_SOM_NODE_H
23 
24 //________________________
25 #include <vector>
26 #include <string>
27 #include <map>
28 
29 //________________________
30 #define PRINT_PND_SOM_NODE_DEBUG 0
31 
32 class PndSomNode {
33  public:
37  PndSomNode();
38 
43  explicit PndSomNode(size_t WeightsDim);
44 
49  explicit PndSomNode(std::vector<float> const &weight);
50 
56  PndSomNode(std::string const &label, std::vector<float> const &weight);
57 
66  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim = 0);
67 
77  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim, std::string const &label);
78 
88  PndSomNode(int lft, int top, int rgt, int bot, std::string const &label, std::vector<float> const &weight);
89 
90  // Copy Constructor
91  PndSomNode(PndSomNode const &oth);
92 
93  // Destructor
94  virtual ~PndSomNode();
95 
96  // Operators
97  // Assignment
98  PndSomNode &operator=(PndSomNode const &oth);
99 
100  /*
101  * Init the node.
102  * Currently only on a rectangular grid.
103  */
104  virtual void InitNode();
105 
106  // Modifiers:
110  inline int GetLeft() const;
111  inline void SetLeft(int val);
112 
113  inline int GetRight() const;
114  inline void SetRight(int val);
115 
116  inline int GetTop() const;
117  inline void SetTop(int val);
118 
119  inline int GetBottom() const;
120  inline void SetBottom(int val);
121 
125  inline size_t GetNodeDimension() const;
126  inline void SetNodeDimension(size_t val);
127 
131  inline std::string const &GetLabel() const;
132  inline void SetLabel(std::string const &val);
133 
138  inline std::vector<float> const &GetWeight() const;
139 
144  void SetWeight(std::vector<float> const &val);
145 
150  void SetNeighbours(std::vector<std::pair<size_t, double>> const &val);
151 
156  inline std::vector<std::pair<size_t, double>> const &GetNeighbours() const;
157 
162  inline double GetXPos() const;
163  inline void SetXPos(double xp);
164 
165  inline double GetYPos() const;
166  inline void SetYPos(double yp);
167 
171  void ResetRespList();
172 
176  void AddToRespList(size_t idx);
177  void SetRespList(std::vector<size_t> const &val);
178  std::vector<size_t> const &GetRespoList() const;
179 
184  void SetLabelMap(std::map<std::string, size_t> const &val);
185  std::map<std::string, size_t> const &GetLabelMap() const;
186 
190 #if (PRINT_PND_SOM_NODE_DEBUG > 0)
191  void PrintNode() const;
192 #endif
193 
194  protected:
195  private:
196  //_______________ Functions ____________________
197  // Clear the internal data structure (reset).
198  void ClearInternalStructures();
199 
200  /*
201  * Adjust the weights for the current node (not used in the batch
202  * mode).
203  */
204  void AdjustWeights(std::vector<double> const &target, double LearningRate, double Influence);
205 
206  //___________________ Variables ___________________
207  // Neighbour indices (2D for visualization)
208  int m_iLeft;
209  int m_iTop;
210  int m_iRight;
211  int m_iBottom;
212 
213  // Position of the node in the grid cell
214  double m_xPos;
215  double m_yPos;
216 
217  // Dimension of the weights
218  size_t m_weightDim;
219 
220  // Label of the current node.
221  std::string m_label;
222 
223  // Weight vector of the current node.
224  std::vector<float> m_Weights;
225 
226  /*
227  * Indices of the actual data point which are under the
228  * responsibility of the current node.
229  */
230  std::vector<size_t> m_RespNodeIndex;
231 
232  // <Index, distance> of the neighbours for the current map node.
233  std::vector<std::pair<size_t, double>> m_NeighbourList;
234 
235  // Map holding counts per label
236  std::map<std::string, size_t> m_labelCnts;
237 }; // End of class definition
238 
239 //______________ Inline functions ____________________
240 inline int PndSomNode::GetLeft() const
241 {
242  return this->m_iLeft;
243 };
244 
245 inline void PndSomNode::SetLeft(int val)
246 {
247  this->m_iLeft = val;
248 };
249 
250 inline int PndSomNode::GetRight() const
251 {
252  return this->m_iRight;
253 };
254 
255 inline void PndSomNode::SetRight(int val)
256 {
257  this->m_iRight = val;
258 };
259 
260 inline int PndSomNode::GetTop() const
261 {
262  return this->m_iTop;
263 };
264 
265 inline void PndSomNode::SetTop(int val)
266 {
267  this->m_iTop = val;
268 };
269 
270 inline int PndSomNode::GetBottom() const
271 {
272  return this->m_iBottom;
273 };
274 
275 inline void PndSomNode::SetBottom(int val)
276 {
277  this->m_iBottom = val;
278 };
279 
280 inline size_t PndSomNode::GetNodeDimension() const
281 {
282  return this->m_weightDim;
283 };
284 
285 inline void PndSomNode::SetNodeDimension(size_t val)
286 {
287  this->m_weightDim = val;
288 };
289 
290 inline std::string const &PndSomNode::GetLabel() const
291 {
292  return this->m_label;
293 };
294 
295 inline void PndSomNode::SetLabel(std::string const &val)
296 {
297  this->m_label = val;
298 };
299 
300 inline std::vector<float> const &PndSomNode::GetWeight() const
301 {
302  return this->m_Weights;
303 };
304 
305 inline double PndSomNode::GetXPos() const
306 {
307  return this->m_xPos;
308 };
309 
310 inline void PndSomNode::SetXPos(double xp)
311 {
312  this->m_xPos = xp;
313 };
314 
315 inline double PndSomNode::GetYPos() const
316 {
317  return this->m_yPos;
318 };
319 
320 inline void PndSomNode::SetYPos(double yp)
321 {
322  this->m_yPos = yp;
323 };
324 
325 inline std::vector<std::pair<size_t, double>> const &PndSomNode::GetNeighbours() const
326 {
327  return this->m_NeighbourList;
328 };
329 #endif // End of interface
double GetYPos() const
Definition: PndSomNode.h:315
void AddToRespList(size_t idx)
void SetBottom(int val)
Definition: PndSomNode.h:275
PndSomNode & operator=(PndSomNode const &oth)
void SetXPos(double xp)
Definition: PndSomNode.h:310
int GetLeft() const
Definition: PndSomNode.h:240
int GetRight() const
Definition: PndSomNode.h:250
void SetLabelMap(std::map< std::string, size_t > const &val)
int GetBottom() const
Definition: PndSomNode.h:270
std::string const & GetLabel() const
Definition: PndSomNode.h:290
void SetRight(int val)
Definition: PndSomNode.h:255
void SetYPos(double yp)
Definition: PndSomNode.h:320
void SetTop(int val)
Definition: PndSomNode.h:265
void SetWeight(std::vector< float > const &val)
double GetXPos() const
Definition: PndSomNode.h:305
void SetRespList(std::vector< size_t > const &val)
virtual void InitNode()
void SetNeighbours(std::vector< std::pair< size_t, double >> const &val)
std::vector< float > const & GetWeight() const
Definition: PndSomNode.h:300
void SetLabel(std::string const &val)
Definition: PndSomNode.h:295
virtual ~PndSomNode()
size_t GetNodeDimension() const
Definition: PndSomNode.h:280
std::vector< std::pair< size_t, double > > const & GetNeighbours() const
Definition: PndSomNode.h:325
std::map< std::string, size_t > const & GetLabelMap() const
int GetTop() const
Definition: PndSomNode.h:260
void SetNodeDimension(size_t val)
Definition: PndSomNode.h:285
std::vector< size_t > const & GetRespoList() const
void SetLeft(int val)
Definition: PndSomNode.h:245
void ResetRespList()