GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
modelProperty.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard C++ includes
4 #include <memory>
5 #include <random>
6 #include <vector>
7 
8 // SpineML simulator includes
9 #include "stateVar.h"
10 
11 // Forward declarations
12 namespace pugi
13 {
14  class xml_node;
15 }
16 
17 namespace filesystem
18 {
19  class path;
20 }
21 
22 //------------------------------------------------------------------------
23 // SpineMLSimulator::ModelProperty::Base
24 //------------------------------------------------------------------------
25 namespace SpineMLSimulator
26 {
27 typedef float scalar; // **TODO** move this somewhere more sensible
28 namespace ModelProperty
29 {
30 class Base
31 {
32 public:
33  Base(const StateVar<scalar> &stateVar, unsigned int size)
34  : m_StateVar(stateVar), m_Size(size)
35  {
36  }
37 
38  virtual ~Base(){}
39 
40  //------------------------------------------------------------------------
41  // Public API
42  //------------------------------------------------------------------------
43  scalar *getHostStateVar()
44  {
45  return m_StateVar.get();
46  }
47 
48  const scalar *getHostStateVar() const
49  {
50  return m_StateVar.get();
51  }
52 
53  void pushToDevice() const
54  {
55  m_StateVar.push();
56  }
57  void pullFromDevice() const
58  {
59  m_StateVar.pull();
60  }
61 
62  unsigned int getSize() const
63  {
64  return m_Size;
65  }
66 
67 private:
68  //------------------------------------------------------------------------
69  // Private members
70  //------------------------------------------------------------------------
71  StateVar<scalar> m_StateVar;
72  unsigned int m_Size;
73 };
74 
75 //------------------------------------------------------------------------
76 // SpineMLSimulator::ModelProperty::Fixed
77 //------------------------------------------------------------------------
78 class Fixed : public Base
79 {
80 public:
81  Fixed(const pugi::xml_node &node, const StateVar<scalar> &stateVar, unsigned int size);
82  Fixed(double value, const StateVar<scalar> &stateVar, unsigned int size);
83 
84  //------------------------------------------------------------------------
85  // Public API
86  //------------------------------------------------------------------------
87  void setValue(scalar value);
88 
89 private:
90  //------------------------------------------------------------------------
91  // Members
92  //------------------------------------------------------------------------
93  scalar m_Value;
94 };
95 
96 //------------------------------------------------------------------------
97 // SpineMLSimulator::ModelProperty::ValueList
98 //------------------------------------------------------------------------
99 class ValueList : public Base
100 {
101 public:
102  ValueList(const pugi::xml_node &node, const filesystem::path &basePath, const std::vector<unsigned int> *remapIndices,
103  const StateVar<scalar> &stateVar, unsigned int size);
104 
105  //------------------------------------------------------------------------
106  // Public API
107  //------------------------------------------------------------------------
108  void setValue(const std::vector<scalar> &values, const std::vector<unsigned int> *remapIndices);
109 
110 private:
111  //------------------------------------------------------------------------
112  // Members
113  //------------------------------------------------------------------------
114  std::vector<scalar> m_Values;
115 };
116 
117 //------------------------------------------------------------------------
118 // SpineMLSimulator::ModelProperty::UniformDistribution
119 //------------------------------------------------------------------------
120 class UniformDistribution : public Base
121 {
122 public:
123  UniformDistribution(const pugi::xml_node &node, const StateVar<scalar> &stateVar, unsigned int size);
124 
125  //------------------------------------------------------------------------
126  // Public API
127  //------------------------------------------------------------------------
128  void setValue(scalar min, scalar max);
129 
130 private:
131  //------------------------------------------------------------------------
132  // Members
133  //------------------------------------------------------------------------
134  std::mt19937 m_RandomGenerator;
135  std::uniform_real_distribution<scalar> m_Distribution;
136 };
137 
138 //------------------------------------------------------------------------
139 // SpineMLSimulator::ModelProperty::NormalDistribution
140 //------------------------------------------------------------------------
141 class NormalDistribution : public Base
142 {
143 public:
144  NormalDistribution(const pugi::xml_node &node, const StateVar<scalar> &stateVar, unsigned int size);
145 
146  //------------------------------------------------------------------------
147  // Public API
148  //------------------------------------------------------------------------
149  void setValue(scalar mean, scalar variance);
150 
151 private:
152  //------------------------------------------------------------------------
153  // Members
154  //------------------------------------------------------------------------
155  std::mt19937 m_RandomGenerator;
156  std::normal_distribution<scalar> m_Distribution;
157 };
158 
159 //------------------------------------------------------------------------
160 // SpineMLSimulator::ModelProperty::ExponentialDistribution
161 //------------------------------------------------------------------------
163 {
164 public:
165  ExponentialDistribution(const pugi::xml_node &node, const StateVar<scalar> &stateVar, unsigned int size);
166 
167  //------------------------------------------------------------------------
168  // Public API
169  //------------------------------------------------------------------------
170  void setValue(scalar lambda);
171 
172 private:
173  //------------------------------------------------------------------------
174  // Members
175  //------------------------------------------------------------------------
176  std::mt19937 m_RandomGenerator;
177  std::exponential_distribution<scalar> m_Distribution;
178 };
179 
180 //----------------------------------------------------------------------------
181 // Functions
182 //----------------------------------------------------------------------------
183 std::unique_ptr<Base> create(const pugi::xml_node &node,
184  const StateVar<scalar> &stateVar, unsigned int size,
185  bool skipGeNNInitialised, const filesystem::path &basePath,
186  const std::string &valueNamespace, const std::vector<unsigned int> *remapIndices);
187 
188 } // namespace ModelProperty
189 } // namespace SpineMLSimulator
unsigned int getSize() const
Definition: modelProperty.h:62
scalar * getHostStateVar()
Definition: modelProperty.h:43
std::unique_ptr< Base > create(const pugi::xml_node &node, const StateVar< scalar > &stateVar, unsigned int size, bool skipGeNNInitialised, const filesystem::path &basePath, const std::string &valueNamespace, const std::vector< unsigned int > *remapIndices)
Definition: modelProperty.cc:226
Definition: modelProperty.h:78
void pullFromDevice() const
Definition: modelProperty.h:57
Definition: modelProperty.h:30
void pushToDevice() const
Definition: modelProperty.h:53
Definition: connectors.h:25
Definition: generateModules.h:16
Definition: connectors.h:12
virtual ~Base()
Definition: modelProperty.h:38
Definition: modelProperty.h:99
const scalar * getHostStateVar() const
Definition: modelProperty.h:48
Base(const StateVar< scalar > &stateVar, unsigned int size)
Definition: modelProperty.h:33
float scalar
Definition: modelProperty.h:27