parascan.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #ifndef _HPP_PARASCAN
  2. #define _HPP_PARASCAN
  3. #include <utility>
  4. #include <vector>
  5. #include <string>
  6. #include "libcsim.hpp"
  7. //#include "simmodules.hpp"
  8. using namespace std;
  9. // forward declarations
  10. class PictureSequenceInput;
  11. class TiXmlElement;
  12. class SimLoop;
  13. class VecConnection;
  14. class SimMod_CompetitiveInhibition;
  15. class Interval
  16. {
  17. public:
  18. Interval(float LowBound, float HighBound)
  19. :mValues(LowBound,HighBound)
  20. {};
  21. Interval(pair<float,float> LowAndHighBound): mValues(LowAndHighBound){}
  22. float LowBound(){return mValues.first;}
  23. float HighBound(){return mValues.second;}
  24. float Range(){return mValues.second-mValues.first;}
  25. bool isValid(){return mValues.second >= mValues.first;}
  26. private:
  27. pair<float,float> mValues;
  28. };
  29. class ParaScanValues
  30. {
  31. public:
  32. ParaScanValues(pair<float,float> Range, int NValues);
  33. ParaScanValues(vector<float> _Values);
  34. const vector<float>& Values();
  35. void print();
  36. private:
  37. vector<float> mValues;
  38. };
  39. vector<float> GenerateScanParaValues(float LowBound, float HighBound, int NValues);
  40. /**
  41. Interface-Klasse für Parameter-Scan-Hilfsklassen
  42. Benutzung:
  43. bool ChangeNextPara=para1->next();
  44. if (ChangeNextPara) {ChangeNextPara=para2->next();}
  45. if (ChangeNextPara) {ChangeNextPara=para3->next();}
  46. SingleValuePara::next() setzt den Parameter um einen Wert weiter.
  47. Noch unklar: Schreiben in Parameter-XML-Datei.
  48. SingleValuePara::next() gibt true zurück, wenn der aktuelle Parameter bei Null neu beginnt (rewind), und daher der darauf folgende um einen Wert weitergesetzt werden muss.
  49. Daher ist para1 analog zur Laufvariablen der innersten Schleife, wenn man es mit verschachtelten For-Schleifen implementieren würde.
  50. */
  51. class IScanPara
  52. {
  53. public:
  54. virtual bool Next()=0;
  55. virtual void SetPara()=0;
  56. virtual void WriteXmlAttribute(TiXmlElement* para)=0;
  57. virtual void Hello()=0;
  58. };
  59. /**
  60. Basis-Klasse für Parameter-Scan-Hilfsklassen mit einem Parameter-Wert
  61. */
  62. class SingleValuePara: public IScanPara
  63. {
  64. protected:
  65. string ParaName;
  66. vector<float> ValueList;
  67. size_t NValues, CurVal;
  68. public:
  69. SingleValuePara() {};
  70. SingleValuePara(string _ParaName, vector<float> _ValueList);
  71. virtual bool Next();
  72. virtual void SetPara()=0;
  73. virtual void WriteXmlAttribute(TiXmlElement* para);
  74. void Hello();
  75. };
  76. /**
  77. Basis-Klasse für Parameter-Scan-Hilfsklassen mit zwei Parameter-Werten
  78. */
  79. class TwoValuesPara: public IScanPara
  80. {
  81. protected:
  82. string Para1Name;
  83. string Para2Name;
  84. vector<float> Value1List;
  85. vector<float> Value2List;
  86. size_t NValues1, NValues2, CurVal1, CurVal2;
  87. public:
  88. TwoValuesPara() {};
  89. TwoValuesPara(string _Para1Name,
  90. string _Para2Name,
  91. vector<float> _Value1List,
  92. vector<float> _Value2List);
  93. virtual bool Next();
  94. virtual void SetPara()=0;
  95. virtual void WriteXmlAttribute(TiXmlElement* para);
  96. void Hello();
  97. };
  98. /** SimLoopPara: parameters which MainSimLoop can pass to the right SimObjects
  99. */
  100. class SimLoopPara: public SingleValuePara
  101. {
  102. private:
  103. SimLoop* MainSimLoop;
  104. ParaType ptype;
  105. public:
  106. SimLoopPara(SimLoop* _SimLoop,
  107. ParaType _ptype,
  108. vector<float> _ValueList,
  109. string _ParaName);
  110. void SetPara();
  111. };
  112. /** Input and Stimulus-Contrast of PictureSequenceInput
  113. */
  114. class ContrastInputPara: public TwoValuesPara
  115. {
  116. private:
  117. PictureSequenceInput* PInput;
  118. public:
  119. ContrastInputPara(PictureSequenceInput* _PInput,
  120. vector<float> _BackgroundStrength,
  121. vector<float> _StimContrast);
  122. void SetPara();
  123. void SetParaBackgroundOnly();
  124. };
  125. /** Strength of lateral Inhibition
  126. */
  127. class InhExStrengthPara: public SingleValuePara
  128. {
  129. private:
  130. SimMod_CompetitiveInhibition* CompInh;
  131. public:
  132. InhExStrengthPara(SimMod_CompetitiveInhibition* _CompInh,
  133. vector<float> _InhExStrength,
  134. string _ParaName="InhExStrength")
  135. :SingleValuePara(_ParaName, _InhExStrength), CompInh(_CompInh)
  136. {};
  137. void SetPara();
  138. };
  139. /** noise amplitude of provided layer
  140. */
  141. class NoiseAmplitudePara: public SingleValuePara
  142. {
  143. private:
  144. layer* mLayer;
  145. public:
  146. NoiseAmplitudePara( layer* _layer,
  147. vector<float> _NoiseAmplitude,
  148. string _ParaName="NoiseAmplitude")
  149. : mLayer(_layer), SingleValuePara(_ParaName, _NoiseAmplitude)
  150. {};
  151. void SetPara();
  152. };
  153. /** vary parameters of Gaussian connection profile
  154. e.g. range and strength of lateral excitation
  155. */
  156. class GaussConProfilePara: public TwoValuesPara
  157. {
  158. private:
  159. VecConnection* con;
  160. float MaxDelay, MinDelay, OldRangeVal, OldStrengthVal;
  161. public:
  162. GaussConProfilePara(VecConnection* _con, vector<float> Range, vector<float> Strength, float _MinDelay=0, float _MaxDelay=0);
  163. void SetPara();
  164. };
  165. //template<class T1, class T2>
  166. class ChangableTwoValuePara: public TwoValuesPara
  167. {
  168. private:
  169. Changable* mParaChangeTarget;
  170. float mValue1, mOldValue1;
  171. float mValue2, mOldValue2;
  172. public:
  173. ChangableTwoValuePara(const string& NameVal1,
  174. const string& NameVal2,
  175. vector<float> Values1,
  176. vector<float> Values2,
  177. Changable* ObjectToBeChanged);
  178. void SetPara();
  179. };
  180. typedef vector<IScanPara*>::iterator ScanParaIter;
  181. /**
  182. Helper class for parameter scan
  183. */
  184. class ParameterCollection
  185. {
  186. private:
  187. vector<IScanPara*> ScanParaList;
  188. public:
  189. ParameterCollection(){};
  190. void AddPara(IScanPara* para) {ScanParaList.push_back(para); para->Hello();};
  191. void AddContrastInputPara(PictureSequenceInput* _PInput,
  192. vector<float> _BackgroundStrength,
  193. vector<float> _StimContrast);
  194. bool NextPara();
  195. void SetPara();
  196. void WriteXmlAttributes(TiXmlElement* para);
  197. void testNetwork (const pair<float,float>& InputInterval,
  198. const float& SecondsPerParameter,
  199. input* TestInput );
  200. };
  201. bool TestParameterCollection();
  202. #endif // _HPP_PARASCAN