AnimatLab  2
Test
RandomNeuron.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 #include "Synapse.h"
10 #include "Neuron.h"
11 #include "RandomNeuron.h"
12 #include "FiringRateModule.h"
13 
14 namespace FiringRateSim
15 {
16  namespace Neurons
17  {
18 
26 {
27  //decide randomly whether it starts high or low.
28  if(Std_IRand(0, 100) > 50)
29  m_iIntrinsicTypeDefault=IH_CURRENT;
30  else
31  m_iIntrinsicTypeDefault=IL_CURRENT;
32 
33  m_fltITime=0;
36  m_fltIl=0;
37  m_fltIlinit = 0;
38 
39  m_lpCurrentGraph = NULL;
40  m_lpBurstGraph = NULL;
41  m_lpIBurstGraph = NULL;
42 }
43 
51 {
52 
53 try
54 {
56  if(m_lpBurstGraph) delete m_lpBurstGraph;
58 }
59 catch(...)
60 {Std_TraceMsg(0, "Caught Error in desctructor of RandomNeuron\r\n", "", -1, false, true);}
61 }
62 
72 {return m_fltITime;}
73 
82 void RandomNeuron::ITime(float fltVal)
83 {
84  m_fltITime=fltVal;
85 }
86 
96 {return m_iIntrinsicType;}
97 
106 void RandomNeuron::IntrinsicType(unsigned char iVal)
107 {
108  m_iIntrinsicType=iVal;
109 }
110 
120 {return m_fltIntrinsic;}
121 
131 {
132  m_fltIntrinsic=fltVal;
133 }
134 
144 {return m_fltIl;}
145 
154 void RandomNeuron::Il(float fltVal)
155 {
156  m_fltIl=fltVal;
157 }
158 
168 {return m_fltIlinit;}
169 
178 void RandomNeuron::Ilinit(float fltVal)
179 {
180  m_fltIlinit=fltVal;
182 }
183 
193 {return RANDOM_NEURON;}
194 
195 void RandomNeuron::Copy(CStdSerialize *lpSource)
196 {
197  Neuron::Copy(lpSource);
198 
199  RandomNeuron *lpOrig = dynamic_cast<RandomNeuron *>(lpSource);
200 
201  m_fltITime = lpOrig->m_fltITime;
204  m_fltIntrinsic = lpOrig->m_fltIntrinsic;
205  m_fltIlinit = lpOrig->m_fltIlinit;
206  m_fltIl = lpOrig->m_fltIl;
207 
208  if(m_lpCurrentGraph)
209  {
210  delete m_lpCurrentGraph;
211  m_lpCurrentGraph = NULL;
212  }
213 
214  if(lpOrig->m_lpCurrentGraph)
215  m_lpCurrentGraph = dynamic_cast<AnimatSim::Gains::Gain *>(lpOrig->m_lpCurrentGraph->Clone());
216 
217  if(m_lpBurstGraph)
218  {
219  delete m_lpBurstGraph;
220  m_lpBurstGraph = NULL;
221  }
222 
223  if(lpOrig->m_lpBurstGraph)
224  m_lpBurstGraph = dynamic_cast<AnimatSim::Gains::Gain *>(lpOrig->m_lpBurstGraph->Clone());
225 
226  if(m_lpIBurstGraph)
227  {
228  delete m_lpIBurstGraph;
229  m_lpIBurstGraph = NULL;
230  }
231 
232  if(lpOrig->m_lpIBurstGraph)
233  m_lpIBurstGraph = dynamic_cast<AnimatSim::Gains::Gain *>(lpOrig->m_lpIBurstGraph->Clone());
234 }
235 
244 void RandomNeuron::CurrentDistribution(AnimatSim::Gains::Gain *lpGain)
245 {
246  if(lpGain)
247  {
248  if(m_lpCurrentGraph)
249  {delete m_lpCurrentGraph; m_lpCurrentGraph = NULL;}
250  m_lpCurrentGraph = lpGain;
251  }
252 }
253 
262 void RandomNeuron::CurrentDistribution(std::string strXml)
263 {
264  CStdXml oXml;
265  oXml.Deserialize(strXml);
266  oXml.FindElement("Root");
267  oXml.FindChildElement("CurrentGraph");
268  CurrentDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "CurrentGraph", oXml));
269 }
270 
279 void RandomNeuron::BurstLengthDistribution(AnimatSim::Gains::Gain *lpGain)
280 {
281  if(lpGain)
282  {
283  if(m_lpBurstGraph)
284  {delete m_lpBurstGraph; m_lpBurstGraph = NULL;}
285  m_lpBurstGraph = lpGain;
286  }
287 }
288 
297 void RandomNeuron::BurstLengthDistribution(std::string strXml)
298 {
299  CStdXml oXml;
300  oXml.Deserialize(strXml);
301  oXml.FindElement("Root");
302  oXml.FindChildElement("BurstGraph");
303  BurstLengthDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "BurstGraph", oXml));
304 }
305 
314 void RandomNeuron::InterbusrtLengthDistribution(AnimatSim::Gains::Gain *lpGain)
315 {
316  if(lpGain)
317  {
318  if(m_lpIBurstGraph)
319  {delete m_lpIBurstGraph; m_lpIBurstGraph = NULL;}
320  m_lpIBurstGraph = lpGain;
321  }
322 }
323 
332 void RandomNeuron::InterbusrtLengthDistribution(std::string strXml)
333 {
334  CStdXml oXml;
335  oXml.Deserialize(strXml);
336  oXml.FindElement("Root");
337  oXml.FindChildElement("InterBurstGraph");
338  InterbusrtLengthDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "InterBurstGraph", oXml));
339 }
340 
348 {
349  double dblRand;
350 
351  m_iIntrinsicType=IH_CURRENT;
352 
353  //Lets get a random number for the time it will be high.
354  dblRand = Std_DRand(0, 100);
355 
356  //Now run it through the random variable equation to get the actual value.
357  m_fltITime = m_lpBurstGraph->CalculateGain((float) dblRand);
358 
359  //Lets get a random number for the current to use.
360  dblRand = Std_DRand(0, 100);
361 
362  //Now run it through the random variable equation to get the actual value.
363  m_fltIntrinsic = m_lpCurrentGraph->CalculateGain((float) dblRand);
364 }
365 
373 {
374  double dblRand;
375 
376  m_iIntrinsicType=IL_CURRENT;
378 
379  //Lets get a random number for the time it will be low.
380  dblRand = Std_DRand(0, 100);
381 
382  //Now run it through the random variable equation to get the actual value.
383  m_fltITime = m_lpIBurstGraph->CalculateGain((float) dblRand);
384 }
385 
387 {
389 
390  m_fltITime=0;
392  m_fltIntrinsic=0;
394 }
395 
396 float RandomNeuron::CalculateIntrinsicCurrent(FiringRateModule *lpModule, float fltInputCurrent)
397 {
398 
399  m_fltITime-=lpModule->TimeStep();
400 
401  if(m_fltITime<0)
402  {
403  if(m_iIntrinsicType==IH_CURRENT)
404  LowCurrentOn();
405  else
406  HighCurrentOn();
407  }
408 
409  return m_fltIntrinsic;
410 }
411 
413 {
414  //We need bytes for the internal state variables for this neuron.
415  return (Neuron::CalculateSnapshotByteSize() + sizeof(m_fltITime) + sizeof(m_iIntrinsicType));
416 }
417 
418 void RandomNeuron::SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
419 {
420  Neuron::SaveKeyFrameSnapshot(aryBytes, lIndex);
421 
422  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltITime, sizeof(m_fltITime));
423  lIndex += sizeof(m_fltITime);
424 
425  memcpy((void *) (aryBytes+lIndex), (void *)&m_iIntrinsicType, sizeof(m_iIntrinsicType));
426  lIndex += sizeof(m_iIntrinsicType);
427 }
428 
429 void RandomNeuron::LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
430 {
431  Neuron::LoadKeyFrameSnapshot(aryBytes, lIndex);
432 
433  memcpy((void *)&m_fltITime, (void *) (aryBytes+lIndex), sizeof(m_fltITime));
434  lIndex += sizeof(m_fltITime);
435 
436  memcpy((void *)&m_iIntrinsicType, (void *) (aryBytes+lIndex), sizeof(m_iIntrinsicType));
437  lIndex += sizeof(m_iIntrinsicType);
438 }
439 
440 #pragma region DataAccesMethods
441 
442 bool RandomNeuron::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
443 {
444  std::string strType = Std_CheckString(strDataType);
445 
446  if(Neuron::SetData(strDataType, strValue, false))
447  return true;
448 
449  if(strType == "IL")
450  {
451  Ilinit(atof(strValue.c_str()));
452  return true;
453  }
454 
455  if(strType == "CURRENTDISTRIBUTION")
456  {
457  CurrentDistribution(strValue);
458  return true;
459  }
460 
461  if(strType == "BURSTLENGTHDISTRIBUTION")
462  {
463  BurstLengthDistribution(strValue);
464  return true;
465  }
466 
467  if(strType == "INTERBURSTLENGTHDISTRIBUTION")
468  {
469  InterbusrtLengthDistribution(strValue);
470  return true;
471  }
472 
473 
474  //If it was not one of those above then we have a problem.
475  if(bThrowError)
476  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
477 
478  return false;
479 }
480 
481 void RandomNeuron::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
482 {
483  Neuron::QueryProperties(aryProperties);
484 
485  aryProperties.Add(new TypeProperty("Il", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
486  aryProperties.Add(new TypeProperty("CurrentDistribution", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
487  aryProperties.Add(new TypeProperty("BurstLengthDistribution", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
488  aryProperties.Add(new TypeProperty("InterbusrtLengthDistribution", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
489 }
490 
491 #pragma endregion
492 
493 void RandomNeuron::Load(CStdXml &oXml)
494 {
495 
496  Neuron::Load(oXml);
497 
498  oXml.IntoElem(); //Into Neuron Element
499 
500  Ilinit(oXml.GetChildFloat("Il"));
501 
502  CurrentDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "CurrentGraph", oXml));
503  BurstLengthDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "BurstGraph", oXml));
504  InterbusrtLengthDistribution(AnimatSim::Gains::LoadGain(m_lpSim, "InterBurstGraph", oXml));
505 
506  oXml.OutOfElem(); //OutOf Neuron Element
507 }
508 
509  } //Neurons
510 } //FiringRateSim
511 
virtual void SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Saves a key frame snapshot.
Firing rate neural module.
AnimatSim::Gains::Gain * m_lpBurstGraph
The pointer to the graph used to calculate the hi current duration.
Definition: RandomNeuron.h:50
float m_fltIntrinsic
The active intrinsic current.
Definition: RandomNeuron.h:38
virtual float TimeStep()
Gets the time step for this moudle in time units.
Random firing rate neuron.
Definition: RandomNeuron.h:24
Declares the random neuron class.
float m_fltITime
Duration of the current mode (HI or LOW)
Definition: RandomNeuron.h:28
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
float Ilinit()
Gets the low current init value.
virtual void ResetSimulation()
Resets the simulation back to time 0.
unsigned char IntrinsicType()
Gets the active intrinsic type (HI or LOW).
The Gain base class.
Definition: Gain.h:35
virtual long CalculateSnapshotByteSize()
Calculates the snapshot byte size.
virtual float CalculateIntrinsicCurrent(FiringRateModule *lpModule, float fltInputCurrent)
Calculates the intrinsic current.
float m_fltIlinit
The low intrinsic current init value.
Definition: RandomNeuron.h:41
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
float m_fltIl
The low intrinsic current.
Definition: RandomNeuron.h:44
unsigned char m_iIntrinsicType
Type of the intrinsic current that is active (HI or LOW)
Definition: RandomNeuron.h:35
float Il()
Gets the low current.
int Std_IRand(int low, int high)
Generates a random number between two values.
void LowCurrentOn()
Turns the low current on.
virtual long CalculateSnapshotByteSize()
Calculates the snapshot byte size.
virtual void SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Saves a key frame snapshot.
Declares the synapse class.
float IntrinsicCurrent()
Gets the active intrinsic current.
virtual void LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Loads a key frame snapshot.
AnimatSim::Gains::Gain * m_lpIBurstGraph
The pointer to the graph used to calculate the low current duration.
Definition: RandomNeuron.h:53
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.
virtual ~RandomNeuron()
Destructor.
double Std_DRand(double low, double high)
Generates a random number between two values.
Declares the firing rate module class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual void LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Loads a key frame snapshot.
virtual unsigned char NeuronType()
Gets the neuron type.
Contains the classes for a firing rate neural model.
AnimatSim::Gains::Gain * m_lpCurrentGraph
Pointer to the graph used to calculate the hi current.
Definition: RandomNeuron.h:47
virtual float CalculateGain(float fltInput)=0
Calculates the gain.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
RandomNeuron()
Default constructor.
void HighCurrentOn()
Turns the high current on.
float ITime()
Gets the duration of the active current mode.
Gain * LoadGain(Simulator *lpSim, std::string strName, CStdXml &oXml)
Loads a gain object.
Definition: Gain.cpp:287