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 
20 class PndSomNode {
21  public:
25  PndSomNode();
26 
31  explicit PndSomNode(size_t WeightsDim);
32 
37  explicit PndSomNode(std::vector<float> const &weight);
38 
44  PndSomNode(std::string const &label, std::vector<float> const &weight);
45 
54  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim = 0);
55 
65  PndSomNode(int lft, int top, int rgt, int bot, size_t WeightsDim, std::string const &label);
66 
76  PndSomNode(int lft, int top, int rgt, int bot, std::string const &label, std::vector<float> const &weight);
77 
78  // Copy Constructor
79  PndSomNode(PndSomNode const &oth);
80 
81  // Destructor
82  virtual ~PndSomNode();
83 
84  // Operators
85  // Assignment
86  PndSomNode &operator=(PndSomNode const &oth);
87 
88  /*
89  * Init the node.
90  * Currently only on a rectangular grid.
91  */
92  virtual void InitNode();
93 
94  // Modifiers:
98  inline int GetLeft() const;
99  inline void SetLeft(int val);
100 
101  inline int GetRight() const;
102  inline void SetRight(int val);
103 
104  inline int GetTop() const;
105  inline void SetTop(int val);
106 
107  inline int GetBottom() const;
108  inline void SetBottom(int val);
109 
113  inline size_t GetNodeDimension() const;
114  inline void SetNodeDimension(size_t val);
115 
119  inline std::string const &GetLabel() const;
120  inline void SetLabel(std::string const &val);
121 
126  inline std::vector<float> const &GetWeight() const;
127 
132  void SetWeight(std::vector<float> const &val);
133 
138  void SetNeighbours(std::vector<std::pair<size_t, double>> const &val);
139 
144  inline std::vector<std::pair<size_t, double>> const &GetNeighbours() const;
145 
150  inline double GetXPos() const;
151  inline void SetXPos(double xp);
152 
153  inline double GetYPos() const;
154  inline void SetYPos(double yp);
155 
159  void ResetRespList();
160 
164  void AddToRespList(size_t idx);
165  void SetRespList(std::vector<size_t> const &val);
166  std::vector<size_t> const &GetRespoList() const;
167 
172  void SetLabelMap(std::map<std::string, size_t> const &val);
173  std::map<std::string, size_t> const &GetLabelMap() const;
174 
178 #if (PRINT_PND_SOM_NODE_DEBUG > 0)
179  void PrintNode() const;
180 #endif
181 
182  protected:
183  private:
184  //_______________ Functions ____________________
185  // Clear the internal data structure (reset).
186  void ClearInternalStructures();
187 
188  /*
189  * Adjust the weights for the current node (not used in the batch
190  * mode).
191  */
192  void AdjustWeights(std::vector<double> const &target, double LearningRate, double Influence);
193 
194  //___________________ Variables ___________________
195  // Neighbour indices (2D for visualization)
196  int m_iLeft;
197  int m_iTop;
198  int m_iRight;
199  int m_iBottom;
200 
201  // Position of the node in the grid cell
202  double m_xPos;
203  double m_yPos;
204 
205  // Dimension of the weights
206  size_t m_weightDim;
207 
208  // Label of the current node.
209  std::string m_label;
210 
211  // Weight vector of the current node.
212  std::vector<float> m_Weights;
213 
214  /*
215  * Indices of the actual data point which are under the
216  * responsibility of the current node.
217  */
218  std::vector<size_t> m_RespNodeIndex;
219 
220  // <Index, distance> of the neighbours for the current map node.
221  std::vector<std::pair<size_t, double>> m_NeighbourList;
222 
223  // Map holding counts per label
224  std::map<std::string, size_t> m_labelCnts;
225 }; // End of class definition
226 
227 //______________ Inline functions ____________________
228 inline int PndSomNode::GetLeft() const
229 {
230  return this->m_iLeft;
231 };
232 
233 inline void PndSomNode::SetLeft(int val)
234 {
235  this->m_iLeft = val;
236 };
237 
238 inline int PndSomNode::GetRight() const
239 {
240  return this->m_iRight;
241 };
242 
243 inline void PndSomNode::SetRight(int val)
244 {
245  this->m_iRight = val;
246 };
247 
248 inline int PndSomNode::GetTop() const
249 {
250  return this->m_iTop;
251 };
252 
253 inline void PndSomNode::SetTop(int val)
254 {
255  this->m_iTop = val;
256 };
257 
258 inline int PndSomNode::GetBottom() const
259 {
260  return this->m_iBottom;
261 };
262 
263 inline void PndSomNode::SetBottom(int val)
264 {
265  this->m_iBottom = val;
266 };
267 
268 inline size_t PndSomNode::GetNodeDimension() const
269 {
270  return this->m_weightDim;
271 };
272 
273 inline void PndSomNode::SetNodeDimension(size_t val)
274 {
275  this->m_weightDim = val;
276 };
277 
278 inline std::string const &PndSomNode::GetLabel() const
279 {
280  return this->m_label;
281 };
282 
283 inline void PndSomNode::SetLabel(std::string const &val)
284 {
285  this->m_label = val;
286 };
287 
288 inline std::vector<float> const &PndSomNode::GetWeight() const
289 {
290  return this->m_Weights;
291 };
292 
293 inline double PndSomNode::GetXPos() const
294 {
295  return this->m_xPos;
296 };
297 
298 inline void PndSomNode::SetXPos(double xp)
299 {
300  this->m_xPos = xp;
301 };
302 
303 inline double PndSomNode::GetYPos() const
304 {
305  return this->m_yPos;
306 };
307 
308 inline void PndSomNode::SetYPos(double yp)
309 {
310  this->m_yPos = yp;
311 };
312 
313 inline std::vector<std::pair<size_t, double>> const &PndSomNode::GetNeighbours() const
314 {
315  return this->m_NeighbourList;
316 };
317 #endif // End of interface
double GetYPos() const
Definition: PndSomNode.h:303
void AddToRespList(size_t idx)
void SetBottom(int val)
Definition: PndSomNode.h:263
PndSomNode & operator=(PndSomNode const &oth)
void SetXPos(double xp)
Definition: PndSomNode.h:298
int GetLeft() const
Definition: PndSomNode.h:228
int GetRight() const
Definition: PndSomNode.h:238
void SetLabelMap(std::map< std::string, size_t > const &val)
int GetBottom() const
Definition: PndSomNode.h:258
std::string const & GetLabel() const
Definition: PndSomNode.h:278
void SetRight(int val)
Definition: PndSomNode.h:243
void SetYPos(double yp)
Definition: PndSomNode.h:308
void SetTop(int val)
Definition: PndSomNode.h:253
void SetWeight(std::vector< float > const &val)
double GetXPos() const
Definition: PndSomNode.h:293
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:288
void SetLabel(std::string const &val)
Definition: PndSomNode.h:283
virtual ~PndSomNode()
size_t GetNodeDimension() const
Definition: PndSomNode.h:268
std::vector< std::pair< size_t, double > > const & GetNeighbours() const
Definition: PndSomNode.h:313
std::map< std::string, size_t > const & GetLabelMap() const
int GetTop() const
Definition: PndSomNode.h:248
void SetNodeDimension(size_t val)
Definition: PndSomNode.h:273
std::vector< size_t > const & GetRespoList() const
void SetLeft(int val)
Definition: PndSomNode.h:233
void ResetRespList()