learn.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef _HPP_LEARN
  2. #define _HPP_LEARN
  3. #include "simelement.hpp"
  4. #include "connection.hpp"
  5. #include "libcsim.hpp"
  6. #include "layer.hpp"
  7. class learning : public SimElement
  8. {
  9. protected:
  10. layer *TargetLayer, *SourceLayer;
  11. int ns, nt; // target and source layer dimensions
  12. int maxN_pre;
  13. int M; // number of postsynaptic connections per presynaptic neuron
  14. connection *con;
  15. float maxWeight, minWeight;
  16. int Dmax;
  17. int maximumDelay;
  18. short **delays_length;
  19. short ***delays;
  20. int **post;
  21. int **I_pre, **D_pre;
  22. int *N_pre;
  23. int **m_pre;
  24. pfloat **s_pre, **sd_pre;
  25. public:
  26. learning(connection*, float _maxWeight=1);
  27. ~learning();
  28. virtual int proceede(int);
  29. virtual int prepare(int =0);
  30. // virtual void learning::SetMinWeight(float value);
  31. virtual void SetMinWeight(float value); // removed extra qualification learning::
  32. virtual void SetMaxWeight(float value);
  33. float **sd, **s;
  34. };
  35. class levylearning: public learning
  36. {
  37. protected:
  38. float **LTP1, **LTP2;
  39. float TauA, TauB, decA, decB; // decay and raise time constant for presynaptic potential
  40. float LearnRate;
  41. // float DeLearnFac;
  42. float LtpInc;
  43. public:
  44. levylearning(connection*, float =1, float =0.1, float =150, float =1.785, float _LtpInc=1);
  45. ~levylearning();
  46. virtual int proceede(int);
  47. virtual int prepare(int =0);
  48. };
  49. class izhlearning: public learning
  50. {
  51. protected:
  52. float **LTP;
  53. float *LTD;
  54. float dec_pre, dec_post; // decay of presynaptic and postsynaptic learning potential
  55. public:
  56. izhlearning(connection* con, float _maxWeight=1);
  57. ~izhlearning();
  58. virtual int proceede(int =0);
  59. virtual int prepare(int =0);
  60. };
  61. class LearnRossum1: public learning
  62. {
  63. protected:
  64. float **SourceLearnPot;
  65. float *TargetLearnPot;
  66. float dec_pre, dec_post; // decay of presynaptic and postsynaptic learning potential
  67. float Cp, Cd, SynNoiseSigma;
  68. public:
  69. LearnRossum1(connection* con, float _Cp=0.1, float _Cd=0.003, float _SynNoiseSigma=0.015, float _maxWeight=1);
  70. ~LearnRossum1();
  71. virtual int proceede(int =0);
  72. virtual int prepare(int =0);
  73. };
  74. class LearnAntiRossum1: public LearnRossum1
  75. {
  76. protected:
  77. public:
  78. LearnAntiRossum1(connection* con, float _Cp=0.1, float _Cd=0.003, float _SynNoiseSigma=0.015, float _maxWeight=1);
  79. virtual int proceede(int =0);
  80. };
  81. class LearnHebbLP2: public learning
  82. {
  83. protected:
  84. float **LTP;
  85. float LtpDecFac;
  86. float LtpInc;
  87. bool Accumulate;
  88. float LearnSpeed;
  89. float BaseLine;
  90. public:
  91. LearnHebbLP2(connection* con, float _MaxWeight=1, float TauDec=20, float BaseLine=0.1, float _LearnSpeed=0.001, bool _Accumulate=true);
  92. ~LearnHebbLP2();
  93. virtual int proceede(int =0);
  94. virtual int prepare(int =0);
  95. virtual int WriteSimInfo(fstream &fw);
  96. };
  97. class LearnHebbLP2_norm: public learning
  98. {
  99. protected:
  100. float **LTP;
  101. float LtpDecFac;
  102. float LtpInc;
  103. float LearnSpeed;
  104. float BaseLine;
  105. bool Normalize;
  106. float WeightSum;
  107. public:
  108. LearnHebbLP2_norm(connection* con, float _MaxWeight=1, float TauDec=20, float BaseLine=0.1, float _LearnSpeed=0.001, float _WeightSum=0);
  109. ~LearnHebbLP2_norm();
  110. virtual int proceede(int =0);
  111. virtual int prepare(int =0);
  112. int NormalizeWeights();
  113. };
  114. class LearnPrePost: public learning
  115. {
  116. protected:
  117. float **LPpre; //presynaptic potentials
  118. float *LPpost; // postsynaptic potentials
  119. float dec_pre, dec_post; // decay of presynaptic and postsynaptic learning potential
  120. public:
  121. LearnPrePost(connection* con, float _maxWeight=1, float TauLearnPre=30, float TauLearnPost=30);
  122. ~LearnPrePost();
  123. virtual int proceede(int =0);
  124. virtual int prepare(int =0);
  125. };
  126. class LearnFBInh: public LearnPrePost
  127. {
  128. protected:
  129. float Cpre, Cdep;
  130. public:
  131. LearnFBInh(connection* con, float _maxWeight=1, float TauLearnPre=30, float TauLearnPost=30, float _Cpre=1, float _Cdep=0.03);
  132. virtual int proceede(int =0);
  133. };
  134. class LearnFWInh: public LearnPrePost
  135. {
  136. protected:
  137. float Cpre, Cdep;
  138. public:
  139. LearnFWInh(connection* con, float _maxWeight=1, float TauLearnPre=30, float TauLearnPost=30, float _Cpre=1, float _Cdep=0.03);
  140. virtual int proceede(int =0);
  141. };
  142. // wie LearnHebbLP2, aber mit st�rkerer Gewichts�nderung bei hoher
  143. // postsynaptischer Rate (d.h. Multiplikation der lernrate mit dem Postsynaptischen Spike Trace)
  144. // daher auch von LearnPrePost abgeleitet
  145. class LearnHebbLP3: public LearnPrePost
  146. {
  147. protected:
  148. float LearnRate, BaseLine;
  149. float LtpInc;
  150. bool Accumulate;
  151. public:
  152. LearnHebbLP3(connection* con, float _maxWeight=1, float TauLearnPre=30, float TauLearnPost=30, float _BaseLine=0.2, float _LearnRate=0.0001, bool _Accumulate=false);
  153. virtual int proceede(int =0);
  154. };
  155. class LearnAntiHebb: public LearnPrePost
  156. {
  157. protected:
  158. float Cpre, Cdep;
  159. public:
  160. LearnAntiHebb(connection* con, float _maxWeight=1, float TauLearnPre=30, float TauLearnPost=30, float _Cpre=1, float _Cdep=0.03);
  161. virtual int proceede(int =0);
  162. };
  163. // Learning rule according to Bi&Poo 1998, implemented as in Shon, Rao, Sejnowski 2004
  164. // using alpha functions for positive and negative part of learning window
  165. // calculate alpha function in constructor and save in lookup table
  166. // save spike times for every neuron
  167. // every pre and postsynaptic spike is a learning event
  168. class LearnBiPoo: public learning
  169. {
  170. protected:
  171. int** LastSpikesPre; // arrays for time of last spike at presynaptic site
  172. int* LastSpikesPost; // array for time of last spike of postsynaptic neurons
  173. float* PreLearnWindowLut; // lookup table for learning window
  174. float* PostLearnWindowLut; // lookup table for learning window
  175. float LearnRate, TauPeak1, TauPeak2, Amp1, Amp2;
  176. int PreLutN, PostLutN;
  177. public:
  178. LearnBiPoo(connection* con, float _maxWeight=1, float LearnRate=0.001, float TauPeak1=10, float TauPeak2=10, float Amp1=-1.25, float Amp2=1);
  179. ~LearnBiPoo();
  180. virtual int proceede(int TotalTime);
  181. virtual int prepare(int step);
  182. };
  183. // Learning rule according to Froemke & Dan 2002
  184. // similar to Bi&Poo but additionally for each spike a spike efficacy is calculated
  185. // 0<=Eff<=1
  186. // after each spike Eff is set to zero and then falls back to 1 exponentially
  187. // TauPre=28ms
  188. // TauPost=88ms
  189. // ERROR: not correctly implemented
  190. // because only neares neighbor interactions are used
  191. // but Froemke/Dan did not limit the interactions to neares neighbors
  192. // should be implemented using decaying potentials
  193. class LearnFroemkeDan: public learning
  194. {
  195. protected:
  196. int** LastSpikesPre; // arrays for time of last spike at presynaptic site
  197. int* LastSpikesPost; // array for time of last spike of postsynaptic neurons
  198. int** SecondLastSpikesPre; // time of second last spike at presynaptic site
  199. int* SecondLastSpikesPost; // time of second last spike of postsynaptic neurons
  200. float* PreLearnWindowLut; // lookup table for learning window
  201. float* PostLearnWindowLut; // lookup table for learning window
  202. int PreLutN, PostLutN;
  203. float LearnRate, TauPeak1, TauPeak2, Amp1, Amp2;
  204. float* PreEfficacyLut; // lookup table for spike efficacy
  205. float* PostEfficacyLut; // lookup table for spike efficacy
  206. float TauPreEff, TauPostEff;
  207. int PreEffLutN, PostEffLutN;
  208. public:
  209. LearnFroemkeDan(connection* con, float _maxWeight=1, float LearnRate=0.001,
  210. float PreEffTau=28, float PostEffTau=88,
  211. float TauPeak1=35, float TauPeak2=15, float Amp1=-.5, float Amp2=1);
  212. ~LearnFroemkeDan();
  213. virtual int proceede(int TotalTime);
  214. virtual int prepare(int step);
  215. };
  216. // Learning rule inspired by Sj�str�m, Turrigiano, Nelson 2001
  217. // only nearest neighbor interactions as in LearnFroemkeDan and LearnBiPoo
  218. // frequency dependence (??)
  219. // LTP "winns" over LTD
  220. // Dependence of LTP on initial synaptic strength (stronger synapse, smaller relative change
  221. // --> additive weight change as in LearnRossum1?? see Rossum, Bi, turrigano 2000)
  222. class LearnSjoestroem: public learning
  223. {
  224. protected:
  225. int** LastSpikesPre; // arrays for time of last spike at presynaptic site
  226. int** LastSpikesPost; // array for time of last spike of postsynaptic neurons
  227. float* LTPotLearnWindowLut; // lookup table for learning window
  228. float* LTDepLearnWindowLut; // lookup table for learning window
  229. int LTPotLutN, LTDepLutN;
  230. float LearnRate, TauLTDep, TauLTPot, Amp1, Amp2;
  231. public:
  232. LearnSjoestroem(connection* con, float _maxWeight=1, float LearnRate=0.001,
  233. float TauLTDep=35, float TauLTPot=15, float AmpLTDep=-.5, float AmpLTPot=0.2);
  234. ~LearnSjoestroem();
  235. virtual int proceede(int TotalTime);
  236. virtual int prepare(int step);
  237. };
  238. #endif /*_HPP_LEARN */