AnimatLab  2
Test
CsSynapseGroup.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 #include "CsSynapseGroup.h"
10 #include "CsNeuronGroup.h"
11 #include "CsNeuralModule.h"
12 
13 namespace AnimatCarlSim
14 {
15 
23 {
24  m_lpCsModule = NULL;
25 
26  m_lpFromNeuron = NULL;
27  m_lpToNeuron = NULL;
28 
29  m_bEnabled = true;
30  m_fltInitWt = 1;
31  m_fltMaxWt = 1;
32  m_fltPconnect = 1.0f;
33  m_iMinDelay = 1;
34  m_iMaxDelay = 20;
35  m_bPlastic = true;
37 }
38 
46 {
47 
48 try
49 {
50 }
51 catch(...)
52 {Std_TraceMsg(0, "Caught Error in desctructor of CsSynapseGroup\r\n", "", -1, false, true);}
53 }
54 
55 void CsSynapseGroup::InitWt(float fltVal)
56 {
57  Std_IsBelowMax(m_fltMaxWt, fltVal, true, "InitWt", true);
58  m_fltInitWt = fltVal;
59 }
60 
61 float CsSynapseGroup::InitWt() {return m_fltInitWt;}
62 
63 void CsSynapseGroup::MaxWt(float fltVal)
64 {
65  Std_IsAboveMin(m_fltInitWt, fltVal, true, "MaxWt", true);
66  m_fltMaxWt = fltVal;
67 }
68 
69 float CsSynapseGroup::MaxWt() {return m_fltMaxWt;}
70 
71 void CsSynapseGroup::Pconnect(float fltVal)
72 {
73  Std_IsAboveMin((float) 0, fltVal, true, "Pconnect", true);
74  Std_IsBelowMax((float) 1, fltVal, true, "Pconnect", true);
75  m_fltPconnect = fltVal;
76 }
77 
78 float CsSynapseGroup::Pconnect() {return m_fltPconnect;}
79 
80 void CsSynapseGroup::MinDelay(unsigned char iVal)
81 {
82  Std_IsBelowMax(m_iMaxDelay, iVal, true, "MinDelay", true);
83  m_iMinDelay = iVal;
84 }
85 
86 unsigned char CsSynapseGroup::MinDelay() {return m_iMinDelay;}
87 
88 void CsSynapseGroup::MaxDelay(unsigned char iVal)
89 {
90  Std_IsAboveMin(m_iMinDelay, iVal, true, "MaxDelay", true);
91  m_iMaxDelay = iVal;
92 }
93 
94 unsigned char CsSynapseGroup::MaxDelay() {return m_iMaxDelay;}
95 
96 void CsSynapseGroup::Plastic(bool bVal)
97 {
98  m_bPlastic = bVal;
99 }
100 
101 bool CsSynapseGroup::Plastic() {return m_bPlastic;}
102 
103 int CsSynapseGroup::SynapsesCreated() {return m_iSynapsesCreated;}
104 
105 std::string CsSynapseGroup::GeneratorKey()
106 {
108  if(m_bPlastic)
109  return (STR(m_lpFromNeuron->GroupID()) + "_" + STR(m_lpToNeuron->GroupID()) + "_Plastic");
110  else
111  return (STR(m_lpFromNeuron->GroupID()) + "_" + STR(m_lpToNeuron->GroupID()) + "_Fixed");
112  else
113  return "_";
114 }
115 
116 
117 void CsSynapseGroup::SetCARLSimulation()
118 {
119 }
120 
122 {
123  Link::Initialize();
124 
126  if(!m_lpFromNeuron)
127  THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound, "ID: ", m_strFromID);
128 
129  m_lpToNeuron = dynamic_cast<CsNeuronGroup *>(m_lpSim->FindByID(m_strToID));
130  if(!m_lpToNeuron)
131  THROW_PARAM_ERROR(Al_Err_lNodeNotFound, Al_Err_strNodeNotFound, "ID: ", m_strToID);
132 }
133 
134 void CsSynapseGroup::SetSystemPointers(Simulator *m_lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
135 {
136  Link::SetSystemPointers(m_lpSim, lpStructure, lpModule, lpNode, false);
137 
138  m_lpCsModule = dynamic_cast<CsNeuralModule *>(lpModule);
139 
140  if(bVerify) VerifySystemPointers();
141 }
142 
144 {
145  AnimatBase::VerifySystemPointers();
146 
147  if(!m_lpStructure)
148  THROW_PARAM_ERROR(Al_Err_lStructureNotDefined, Al_Err_strStructureNotDefined, "Link: ", m_strID);
149 
150  if(!m_lpOrganism)
151  THROW_PARAM_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Link: ", m_strID);
152 
153  if(!m_lpModule)
154  THROW_PARAM_ERROR(Al_Err_lNeuralModuleNotDefined, Al_Err_strNeuralModuleNotDefined, "Link: ", m_strID);
155 
156  if(!m_lpCsModule)
157  THROW_PARAM_ERROR(Al_Err_lUnableToCastNeuralModuleToDesiredType, Al_Err_strUnableToCastNeuralModuleToDesiredType, "ID: ", m_lpCsModule->ID());
158 }
159 
160 #pragma region DataAccesMethods
161 
162 bool CsSynapseGroup::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
163 {
164  std::string strType = Std_CheckString(strDataType);
165 
166  if(Link::SetData(strDataType, strValue, false))
167  return true;
168 
169  if(strType == "INITWT")
170  {
171  InitWt(atof(strValue.c_str()));
172  return true;
173  }
174 
175  if(strType == "MAXWT")
176  {
177  MaxWt(atof(strValue.c_str()));
178  return true;
179  }
180 
181  if(strType == "PCONNECT")
182  {
183  Pconnect(atof(strValue.c_str()));
184  return true;
185  }
186 
187  if(strType == "MINDELAY")
188  {
189  MinDelay((unsigned char) atoi(strValue.c_str()));
190  return true;
191  }
192 
193  if(strType == "MAXDELAY")
194  {
195  MaxDelay((unsigned char) atoi(strValue.c_str()));
196  return true;
197  }
198 
199  if(strType == "PLASTIC")
200  {
201  Plastic(Std_ToBool(strValue));
202  return true;
203  }
204 
205  //If it was not one of those above then we have a problem.
206  if(bThrowError)
207  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
208 
209  return false;
210 }
211 
212 void CsSynapseGroup::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
213 {
214  Link::QueryProperties(aryProperties);
215 
216  aryProperties.Add(new TypeProperty("InitWt", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
217  aryProperties.Add(new TypeProperty("MaxWt", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
218  aryProperties.Add(new TypeProperty("Pconnect", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
219  aryProperties.Add(new TypeProperty("MinDelay", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
220  aryProperties.Add(new TypeProperty("MaxDelay", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
221  aryProperties.Add(new TypeProperty("Plastic", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
222 }
223 
224 #pragma endregion
225 
226 void CsSynapseGroup::Load(CStdXml &oXml)
227 {
228  AnimatBase::Load(oXml);
229 
230  oXml.IntoElem(); //Into Synapse Element
231 
232  m_strFromID = oXml.GetChildString("FromID");
234  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, "Attribute: FromID");
235 
236  m_strToID = oXml.GetChildString("ToID");
237  if(Std_IsBlank(m_strToID))
238  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, "Attribute: ToID");
239 
240  InitWt(oXml.GetChildFloat("InitWt", m_fltInitWt));
241  MaxWt(oXml.GetChildFloat("MaxWt", m_fltMaxWt));
242  Pconnect(oXml.GetChildFloat("Pconnect", m_fltPconnect));
243  MinDelay(oXml.GetChildInt("MinDelay", m_iMinDelay));
244  MaxDelay(oXml.GetChildInt("MaxDelay", m_iMaxDelay));
245  Plastic(oXml.GetChildBool("Plastic", m_bPlastic));
246 
247  oXml.OutOfElem(); //OutOf Synapse Element
248 }
249 
250 
251 } //AnimatCarlSim
252 
253 
254 
255 
256 
257 
Contains the classes for a firing rate neural model.
Definition: CsAdapter.cpp:14
bool m_bPlastic
connection type, either SYN_FIXED or SYN_PLASTIC
float m_fltInitWt
initial weight strength (arbitrary units); should be negative for inhibitory connections ...
AnimatSim::Behavior::NeuralModule * m_lpModule
The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NU...
Definition: AnimatBase.h:49
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Declares the CsNeuronGroup class.
CsNeuronGroup * m_lpFromNeuron
The pointer to pre-synaptic neuron.
unsigned char m_iMinDelay
the minimum delay allowed (ms)
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
std::string m_strToID
GUID ID of the pre-synaptic neruon.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
std::string m_strFromID
GUID ID of the pre-synaptic neruon.
int m_iSynapsesCreated
The total number of synapses created.
Firing rate neural module.
virtual void Initialize()
Initializes this object.
Declares the synapse class.
Firing Rate Neuron model.
Definition: CsNeuronGroup.h:28
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
bool Std_ToBool(int iVal)
Converts a value toa bool.
bool Std_IsBelowMax(int iMaxVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is below a maximum value.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
CsNeuronGroup * m_lpToNeuron
The pointer to post-synaptic neuron.
float m_fltMaxWt
upper bound on weight strength (arbitrary units); should be negative for inhibitory connections ...
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual ~CsSynapseGroup()
Destructor.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
unsigned char m_iMaxDelay
the maximum delay allowed (ms)
CsNeuralModule * m_lpCsModule
Pointer to parent CsNeuralModule.
CsSynapseGroup()
Default constructor.
float m_fltPconnect
connection probability