Advertisement
ktv6

WTANeuron.cpp

Dec 25th, 2019
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include "WTANeuron.hpp"
  2.  
  3. double WTANeuron::fRand(double Min, double Max) {
  4.     double tmp = (double)rand() / RAND_MAX;
  5.     return Min + tmp * (Max - Min);
  6. }
  7.  
  8. WTANeuron::WTANeuron(int ind) {
  9.     index = ind;
  10.     n = ind;
  11.     register int i;
  12.     w.push_back(fRand(-2., 8.));
  13.     w.push_back(fRand(-2., 2.));
  14. }
  15.  
  16. int WTANeuron::countEuclidMetric(point2 p) {
  17.     register int j;
  18.     double diff2X, diff2Y, diff2;
  19.     diff2X = pow((p.x - w[0]), 2);
  20.     diff2Y = pow((p.y - w[1]), 2);
  21.     diff2 = diff2X + diff2Y;
  22.     euclidMetric = sqrt(diff2);
  23.     return 0;
  24. }
  25.  
  26. int WTANeuron::ScaleMetric() {
  27.     scaledEuclidMetric = n_victories * euclidMetric;
  28.     return 0;
  29. }
  30.  
  31. double WTANeuron::NeighbourFunction() {
  32.     return exp(-n / sigma);
  33. }
  34.  
  35. int WTANeuron::GNGStudy(point2 p) {
  36.     register int i, j, k;
  37.     double diffX, diffY, diff;
  38.     diffX = p.x - w[0];
  39.     diffY = p.y - w[1];
  40.  
  41.     w[0] += etta * NeighbourFunction() * diffX;
  42.     w[1] += etta * NeighbourFunction() * diffY;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement