AnimatLab  2
Test
FiringRateSim/Neuron.cpp
1 
7 #include "StdAfx.h"
8 
9 #include "Synapse.h"
10 #include "Neuron.h"
11 #include "FiringRateModule.h"
12 
13 namespace FiringRateSim
14 {
15  namespace Neurons
16  {
17 
25 {
26  m_lpFRModule = NULL;
27 
28  m_bEnabled = true;
29 
30  m_aryVn[0]=0.0;
31  m_aryVn[1]=0.0;
32  m_aryVth[0] = 0;
33  m_aryVth[1] = 0;
34 
35  m_fltCn = (float) 75e-6; //Membrane capacitance
36  m_fltInvCn = 1/m_fltCn;
37  m_fltGn = (float) 0.1e-6; //Membrane conductance
38  m_fltVth = (float) 0; //Firing frequency voltage threshold
40  m_fltFmin = (float) 0.25; //Minimum Firing frequency
41  m_fltGain = (float) 0.1e-3; //Firing frequency gain
42  m_fltExternalI = 0; //Externally injected current
43  m_fltIntrinsicI = 0;
44  m_fltSynapticI = 0;
45  m_fltAdapterI = 0;
48  m_fltVn = 0;
49  m_fltFiringFreq = 0;
50  m_fltVndisp = 0;
51  m_fltVthdisp = 0;
52  m_fltVrest = 0;
53 
54  m_fltVNoiseMax = (float) 0.1e-4; //Max noise is 0.4 mV
55  m_bUseNoise = true;
56  m_fltVNoise = 0;
57 
58  m_fltDCTH = 0;
60  m_fltAccomTimeConst = (float) 100e-3;
62  m_bUseAccom = false;
63  m_fltVthadd = 0;
64 
65  m_bGainType = true;
66 
67  m_fltIinit = 0;
68  m_fltInitTime = 0;
69 }
70 
78 {
79 
80 try
81 {
82  m_arySynapses.RemoveAll();
83 }
84 catch(...)
85 {Std_TraceMsg(0, "Caught Error in desctructor of Neuron\r\n", "", -1, false, true);}
86 }
87 
96 float Neuron::Cn()
97 {return m_fltCn;}
98 
107 void Neuron::Cn(float fltVal)
108 {
109  Std_IsAboveMin((float) 0, fltVal, true, "Cn");
110 
111  m_fltCn=fltVal;
112  m_fltInvCn = 1/m_fltCn;
113 }
114 
123 float Neuron::Gn()
124 {return m_fltGn;}
125 
134 void Neuron::Gn(float fltVal)
135 {
136  Std_IsAboveMin((float) 0, fltVal, true, "Cn");
137 
138  m_fltGn=fltVal;
139 }
140 
149 float Neuron::Vth()
150 {return m_fltVth;}
151 
160 void Neuron::Vth(float fltVal)
161 {
162  float fltDiff = fltVal - m_fltVrest;
163 
164  m_fltVthi = fltDiff;
165  m_fltVth = fltDiff;
166  m_fltVthdisp = m_fltVrest + m_fltVth;
167  m_aryVth[0] = fltDiff;
168  m_aryVth[1] = fltDiff;
169  m_fltVthadd = fltDiff;
170 }
171 
181 {return m_fltFmin;}
182 
191 void Neuron::Fmin(float fltVal)
192 {
193  Std_IsAboveMin((float) 0, fltVal, true, "Fmin", true);
194 
195  m_fltFmin=fltVal;
196 }
197 
207 {return m_fltGain;}
208 
217 void Neuron::Gain(float fltVal)
218 {
219  Std_IsAboveMin((float) 0, fltVal, true, "Gain");
220  m_fltGain=fltVal;
221 }
222 
232 {return m_fltExternalI;}
233 
242 void Neuron::ExternalI(float fltVal)
243 {
244  m_fltExternalI=fltVal;
245 }
246 
255 void Neuron::AddExternalI(float fltVal)
256 {
257  m_fltExternalI+=fltVal;
258 }
259 
269 {return m_fltVrest;}
270 
279 void Neuron::Vrest(float fltVal)
280 {
281  m_fltVrest = fltVal;
282  Vth(m_fltVthi);
283 
284  if(!m_lpSim->SimRunning())
286 }
287 
297 {return m_fltVNoiseMax;}
298 
308 
317 void Neuron::UseNoise(bool bVal)
318 {
319  m_bUseNoise = bVal;
320 }
321 
331 
340 void Neuron::UseAccom(bool bVal)
341 {
342  m_bUseAccom = bVal;
343 
346  else
347  m_fltDCTH = 0;
348 }
349 
358 void Neuron::VNoiseMax(float fltVal)
359 {
360  m_fltVNoiseMax = fltVal;
361 
362  if(m_fltVNoiseMax != 0)
363  m_bUseNoise = true;
364  else
365  m_bUseNoise = false;
366 }
367 
377 {return m_fltRelativeAccom;}
378 
388 {
389  Std_InValidRange((float) 0, (float) 1, fltVal, true, "RelativeAccomodation");
390 
391  m_fltRelativeAccom = fltVal;
392 
393  if(m_fltRelativeAccom != 0)
394  m_bUseAccom = true;
395  else
396  m_bUseAccom = false;
397 
400  else
401  m_fltDCTH = 0;
402 }
403 
413 {return m_fltAccomTimeConst;}
414 
424 {
425  m_fltAccomTimeConst = fltVal;
426 
429  else
430  m_fltDCTH = 0;
431 }
432 
433 float Neuron::Iinit() {return m_fltIinit;}
434 
435 void Neuron::Iinit(float fltVal) {m_fltIinit = fltVal;}
436 
437 float Neuron::InitTime() {return m_fltInitTime;}
438 
439 void Neuron::InitTime(float fltVal)
440 {
441  Std_InValidRange((float) 0, (float) 10, fltVal, true, "InitTime");
442  m_fltInitTime = fltVal;
443 }
444 
454 {return m_bGainType;}
455 
464 void Neuron::GainType(bool bVal)
465 {
466  m_bGainType = bVal;
467 }
468 
477 float Neuron::Vn()
478 {return m_fltVn;}
479 
491 {
492  return CalculateFiringFrequency(m_aryVn[m_lpFRModule->ActiveArray()], m_aryVth[m_lpFRModule->ActiveArray()]);
493 }
494 
504 {return m_fltIntrinsicI;}
505 
514 void Neuron::IntrinsicCurrent(float fltVal)
515 {m_fltIntrinsicI = fltVal;}
516 
525 unsigned char Neuron::NeuronType()
526 {return RUGULAR_NEURON;}
527 
528 void Neuron::Copy(CStdSerialize *lpSource)
529 {
530  Node::Copy(lpSource);
531 
532  Neuron *lpOrig = dynamic_cast<Neuron *>(lpSource);
533 
534  m_lpFRModule = lpOrig->m_lpFRModule;
535  m_fltCn = lpOrig->m_fltCn;
536  m_fltInvCn = lpOrig->m_fltInvCn;
537  m_fltGn = lpOrig->m_fltGn;
538  m_fltFmin = lpOrig->m_fltFmin;
539  m_fltGain = lpOrig->m_fltGain;
540  m_fltExternalI = lpOrig->m_fltExternalI;
542  m_fltSynapticI = lpOrig->m_fltSynapticI;
543  m_fltAdapterI = lpOrig->m_fltAdapterI;
546  m_fltVNoiseMax = lpOrig->m_fltVNoiseMax;
547  m_bUseNoise = lpOrig->m_bUseNoise;
548  m_bGainType = lpOrig->m_bGainType;
549  m_fltDCTH = lpOrig->m_fltDCTH;
553  m_bUseAccom = lpOrig->m_bUseAccom;
554  m_fltVn = lpOrig->m_fltVn;
556  m_aryVn[0] = lpOrig->m_aryVn[0];
557  m_aryVn[1] = lpOrig->m_aryVn[1];
558  m_fltVNoise = lpOrig->m_fltVNoise;
559  m_fltVth = lpOrig->m_fltVth;
560  m_fltVthi = lpOrig->m_fltVthi;
561  m_fltVthadd = lpOrig->m_fltVthadd;
562  m_aryVth[0] = lpOrig->m_aryVth[0];
563  m_aryVth[1] = lpOrig->m_aryVth[1];
564  m_fltVrest = lpOrig->m_fltVrest;
565  m_fltVndisp = lpOrig->m_fltVndisp;
566  m_fltIinit = lpOrig->m_fltIinit;
567  m_fltInitTime = lpOrig->m_fltInitTime;
568 }
569 
578 CStdPtrArray<Synapse> *Neuron::GetSynapses()
579 {return &m_arySynapses;}
580 
581 
582 void Neuron::AddSynapse(Synapse *lpSynapse)
583 {
584  if(!lpSynapse)
585  THROW_ERROR(Nl_Err_lSynapseToAddNull, Nl_Err_strSynapseToAddNull);
586  m_arySynapses.Add(lpSynapse);
587 }
588 
597 void Neuron::AddSynapse(std::string strXml, bool bDoNotInit)
598 {
599  CStdXml oXml;
600  oXml.Deserialize(strXml);
601  oXml.FindElement("Root");
602  oXml.FindChildElement("Synapse");
603 
604  Synapse *lpSynapse = LoadSynapse(oXml);
605  if(!bDoNotInit)
606  lpSynapse->Initialize();
607 }
608 
617 void Neuron::RemoveSynapse(int iIndex)
618 {
619  if( iIndex<0 || iIndex>=m_arySynapses.GetSize() )
620  THROW_ERROR(Std_Err_lInvalidIndex, Std_Err_strInvalidIndex);
621  m_arySynapses.RemoveAt(iIndex);
622 }
623 
633 void Neuron::RemoveSynapse(std::string strID, bool bThrowError)
634 {
635  int iPos = FindSynapseListPos(strID, bThrowError);
636  m_arySynapses.RemoveAt(iPos);
637 }
638 
650 {
651  if( iIndex<0 || iIndex>=m_arySynapses.GetSize() )
652  THROW_ERROR(Std_Err_lInvalidIndex, Std_Err_strInvalidIndex);
653  return m_arySynapses[iIndex];
654 }
655 
667 int Neuron::FindSynapseListPos(std::string strID, bool bThrowError)
668 {
669  std::string sID = Std_ToUpper(Std_Trim(strID));
670 
671  int iCount = m_arySynapses.GetSize();
672  for(int iIndex=0; iIndex<iCount; iIndex++)
673  if(m_arySynapses[iIndex]->ID() == sID)
674  return iIndex;
675 
676  if(bThrowError)
677  THROW_TEXT_ERROR(Nl_Err_lSynapseNotFound, Nl_Err_strSynapseNotFound, "ID");
678 
679  return -1;
680 }
681 
691 {return m_arySynapses.GetSize();}
692 
700 {m_arySynapses.RemoveAll();}
701 
703 {
706  else
707  m_fltDCTH = 0;
708 }
709 
711 {
712 
713  if(m_bEnabled)
714  {
716  //int i=5;
717  //if(m_strID == "742CB5DC-6BFB-4BAB-8CC2-36A4725A33D5")
718  // i=6;
719 
720  //Lets get the Summation of synaptic inputs
723 
724  //If we need to apply an init current then do so.
725  if(m_fltInitTime > 0 && m_lpSim->Time() < m_fltInitTime)
727 
728  //if(m_fltInitTime > 0 && m_lpSim->Time() >= m_fltInitTime)
729  // m_fltIntrinsicI = m_fltIntrinsicI; //For testing only comment out!!
730 
731  if(m_bUseNoise)
733 
734  //Get the total current being applied to the neuron.
736 
739  (m_fltSynapticI + m_fltIntrinsicI + m_fltExternalI + m_fltAdapterI -
741 
744 
745  if(m_bUseAccom)
746  {
747  if(m_fltAccomTimeMod != 0 && m_lpFRModule)
749 
752  }
753  else
755 
758 
759  m_fltFiringFreq = CalculateFiringFrequency(m_fltVn, m_fltVth);
760  m_fltAdapterI = 0; //Reset the adapter current for the next cycle.
761  }
762 }
763 
775 float Neuron::CalculateFiringFrequency(float fltVn, float fltVth)
776 {
777  float fltFreq;
778 
779  if(m_bGainType)
780  {
781  if(fltVn<fltVth)
782  fltFreq=0;
783  else
784  fltFreq = (m_fltGain*(fltVn-fltVth)) + m_fltFmin;
785 
786  //Final insurance
787  if(fltFreq<1e-6) fltFreq = 0;
788  if(fltFreq>1) fltFreq = 1;
789  }
790  else
791  {
792  if(fltVn<fltVth)
793  fltFreq = 0;
794  else
795  {
796  fltFreq = m_fltFmin - m_fltGain * fltVth;
797  if (fltVn < (1 - fltFreq)/m_fltGain)
798  fltFreq = (m_fltGain * fltVn) + fltFreq;
799  else
800  fltFreq = 1;
801  }
802 
803  //Final insurance
804  if(fltFreq<1e-6) fltFreq = 0;
805  if(fltFreq>1) fltFreq = 1;
806  }
807 
808  return fltFreq;
809 }
810 
822 float Neuron::CalculateIntrinsicCurrent(FiringRateModule *m_lpFRModule, float fltInputCurrent)
823 {return 0;}
824 
836 {
837  unsigned char iSynapse, iCount;
838  float fltSynapticI=0;
839  Synapse *lpSynapse=NULL;
840 
841  iCount = m_arySynapses.GetSize();
842  for(iSynapse=0; iSynapse<iCount; iSynapse++)
843  {
844  lpSynapse = m_arySynapses[iSynapse];
845 
846  if(lpSynapse->Enabled() && lpSynapse->FromNeuron())
847  lpSynapse->Process(fltSynapticI);
848  }
849 
850  return fltSynapticI;
851 }
852 
861 void Neuron::InjectCurrent(float fltVal)
862 {m_fltExternalI+=fltVal;}
863 
865 {
866  Node::Initialize();
867 
868  if(m_bUseAccom)
870 
871  int iCount = m_arySynapses.GetSize();
872  for(int iIndex=0; iIndex<iCount; iIndex++)
873  m_arySynapses[iIndex]->Initialize();
874 }
875 
876 void Neuron::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
877 {
878  Node::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, false);
879 
880  m_lpFRModule = dynamic_cast<FiringRateModule *>(lpModule);
881 
882  if(bVerify) VerifySystemPointers();
883 }
884 
886 {
887  Node::VerifySystemPointers();
888 
889  if(!m_lpFRModule)
890  THROW_PARAM_ERROR(Al_Err_lUnableToCastNeuralModuleToDesiredType, Al_Err_strUnableToCastNeuralModuleToDesiredType, "ID: ", m_lpFRModule->ID());
891 
892  if(!m_lpOrganism)
893  THROW_PARAM_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Link: ", m_strID);
894 }
895 
897 {
899 
900  m_fltExternalI = 0;
901  m_fltIntrinsicI = 0;
902  m_fltSynapticI = 0;
903  m_fltAdapterI = 0;
905  m_fltTotalMemoryI = 0;
906  m_fltFiringFreq = 0;
907  m_fltVNoise = 0;
908  m_aryVn[0]=0;
909  m_aryVn[1]=0;
910  m_fltVn = 0;
914  m_aryVth[0] = m_aryVth[1] = m_fltVth;
915  m_fltAccomTimeMod = 0;
916  m_fltVthadd = 0;
917 
918  int iCount = m_arySynapses.GetSize();
919  for(int iSynapse=0; iSynapse<iCount; iSynapse++)
920  m_arySynapses[iSynapse]->ResetSimulation();
921 }
922 
923 void Neuron::AddExternalNodeInput(int iTargetDataType, float fltInput)
924 {
925  m_fltAdapterI += fltInput;
927 }
928 
929 #pragma region DataAccesMethods
930 
931 float *Neuron::GetDataPointer(const std::string &strDataType)
932 {
933  std::string strType = Std_CheckString(strDataType);
934 
935  if(strType == "INTRINSICCURRENT")
936  return &m_fltIntrinsicI;
937 
938  if(strType == "EXTERNALCURRENT")
939  return &m_fltExternalI;
940 
941  if(strType == "SYNAPTICCURRENT")
942  return &m_fltSynapticI;
943 
944  if(strType == "ADAPTERCURRENT")
945  return &m_fltAdapterMemoryI;
946 
947  if(strType == "TOTALCURRENT")
948  return &m_fltTotalMemoryI;
949 
950  if(strType == "MEMBRANEVOLTAGE")
951  return &m_fltVndisp;
952 
953  if(strType == "FIRINGFREQUENCY")
954  return &m_fltFiringFreq;
955 
956  if(strType == "NOISEVOLTAGE")
957  return &m_fltVNoise;
958 
959  if(strType == "THRESHOLD")
960  return &m_fltVthdisp;
961 
962  if(strType == "Gm")
963  return &m_fltGn;
964 
965  if(strType == "VREST")
966  return &m_fltVrest;
967 
968  if(strType == "ACCOMTIMEMOD")
969  return &m_fltAccomTimeMod;
970 
971  //If it was not one of those above then we have a problem.
972  THROW_PARAM_ERROR(Nl_Err_lInvalidNeuronDataType, Nl_Err_strInvalidNeuronDataType, "Neuron Data Type", strDataType);
973 
974  return NULL;
975 }
976 
977 bool Neuron::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
978 {
979  std::string strType = Std_CheckString(strDataType);
980 
981  if(Node::SetData(strDataType, strValue, false))
982  return true;
983 
984  if(strType == "CM")
985  {
986  Cn(atof(strValue.c_str()));
987  return true;
988  }
989 
990  if(strType == "GM")
991  {
992  Gn(atof(strValue.c_str()));
993  return true;
994  }
995 
996  if(strType == "VTH")
997  {
998  Vth(atof(strValue.c_str()));
999  return true;
1000  }
1001 
1002  if(strType == "VREST")
1003  {
1004  Vrest(atof(strValue.c_str()));
1005  return true;
1006  }
1007 
1008  if(strType == "RELATIVEACCOMMODATION")
1009  {
1010  RelativeAccommodation(atof(strValue.c_str()));
1011  return true;
1012  }
1013 
1014  if(strType == "ACCOMMODATIONTIMECONSTANT")
1015  {
1016  AccommodationTimeConstant(atof(strValue.c_str()));
1017  return true;
1018  }
1019 
1020  if(strType == "VNOISEMAX")
1021  {
1022  VNoiseMax(atof(strValue.c_str()));
1023  return true;
1024  }
1025 
1026  if(strType == "FMIN")
1027  {
1028  Fmin(atof(strValue.c_str()));
1029  return true;
1030  }
1031 
1032  if(strType == "GAIN")
1033  {
1034  Gain(atof(strValue.c_str()));
1035  return true;
1036  }
1037 
1038  if(strType == "GAINTYPE")
1039  {
1040  GainType(Std_ToBool(strValue));
1041  return true;
1042  }
1043 
1044  if(strType == "ADDEXTERNALCURRENT")
1045  {
1046  AddExternalI(atof(strValue.c_str()));
1047  return true;
1048  }
1049 
1050  if(strType == "IINIT")
1051  {
1052  Iinit(atof(strValue.c_str()));
1053  return true;
1054  }
1055 
1056  if(strType == "INITTIME")
1057  {
1058  InitTime(atof(strValue.c_str()));
1059  return true;
1060  }
1061 
1062  //If it was not one of those above then we have a problem.
1063  if(bThrowError)
1064  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
1065 
1066  return false;
1067 }
1068 
1069 void Neuron::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
1070 {
1071  Node::QueryProperties(aryProperties);
1072 
1073  aryProperties.Add(new TypeProperty("IntrinsicCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1074  aryProperties.Add(new TypeProperty("ExternalCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1075  aryProperties.Add(new TypeProperty("SynapticCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1076  aryProperties.Add(new TypeProperty("AdapterCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1077  aryProperties.Add(new TypeProperty("TotalCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1078  aryProperties.Add(new TypeProperty("MembraneVoltage", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1079  aryProperties.Add(new TypeProperty("FiringFrequency", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1080  aryProperties.Add(new TypeProperty("NoiseVoltage", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1081  aryProperties.Add(new TypeProperty("Threshold", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1082  aryProperties.Add(new TypeProperty("AccomTimeMod", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
1083 
1084  aryProperties.Add(new TypeProperty("Cm", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1085  aryProperties.Add(new TypeProperty("Gm", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
1086  aryProperties.Add(new TypeProperty("Vth", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1087  aryProperties.Add(new TypeProperty("Vrest", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
1088  aryProperties.Add(new TypeProperty("RelativeAccommodation", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1089  aryProperties.Add(new TypeProperty("AccommodationTimeConstant", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1090  aryProperties.Add(new TypeProperty("VNoiseMax", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1091  aryProperties.Add(new TypeProperty("Fmin", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1092  aryProperties.Add(new TypeProperty("Gain", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1093  aryProperties.Add(new TypeProperty("GainType", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
1094  aryProperties.Add(new TypeProperty("AddExternalCurrent", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1095  aryProperties.Add(new TypeProperty("Iinit", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1096  aryProperties.Add(new TypeProperty("InitTime", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
1097 }
1098 
1099 bool Neuron::AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError, bool bDoNotInit)
1100 {
1101  std::string strType = Std_CheckString(strItemType);
1102 
1103  if(strType == "SYNAPSE")
1104  {
1105  AddSynapse(strXml, bDoNotInit);
1106  return true;
1107  }
1108 
1109 
1110  //If it was not one of those above then we have a problem.
1111  if(bThrowError)
1112  THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType, "Item Type", strItemType);
1113 
1114  return false;
1115 }
1116 
1117 bool Neuron::RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError)
1118 {
1119  std::string strType = Std_CheckString(strItemType);
1120 
1121  if(strType == "SYNAPSE")
1122  {
1123  RemoveSynapse(strID, bThrowError);
1124  return true;
1125  }
1126 
1127  //If it was not one of those above then we have a problem.
1128  if(bThrowError)
1129  THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType, "Item Type", strItemType);
1130 
1131  return false;
1132 }
1133 
1134 #pragma endregion
1135 
1137 {
1138  //We need bytes for the internal state variables for this neuron.
1139  return (sizeof(m_aryVn) + sizeof(m_fltExternalI) + sizeof(m_fltIntrinsicI) + sizeof(m_fltSynapticI) + sizeof(m_fltVn) + sizeof(m_fltFiringFreq));
1140 }
1141 
1142 void Neuron::SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
1143 {
1144  memcpy((void *) (aryBytes+lIndex), (void *)m_aryVn, sizeof(m_aryVn));
1145  lIndex += sizeof(m_aryVn);
1146 
1147  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltExternalI, sizeof(m_fltExternalI));
1148  lIndex += sizeof(m_fltExternalI);
1149 
1150  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltIntrinsicI, sizeof(m_fltIntrinsicI));
1151  lIndex += sizeof(m_fltIntrinsicI);
1152 
1153  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltSynapticI, sizeof(m_fltSynapticI));
1154  lIndex += sizeof(m_fltSynapticI);
1155 
1156  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltVn, sizeof(m_fltVn));
1157  lIndex += sizeof(m_fltVn);
1158 
1159  memcpy((void *) (aryBytes+lIndex), (void *)&m_fltFiringFreq, sizeof(m_fltFiringFreq));
1160  lIndex += sizeof(m_fltFiringFreq);
1161 }
1162 
1163 void Neuron::LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
1164 {
1165  memcpy((void *)m_aryVn, (void *) (aryBytes+lIndex) , sizeof(m_aryVn));
1166  lIndex += sizeof(m_aryVn);
1167 
1168  memcpy((void *)&m_fltExternalI, (void *) (aryBytes+lIndex), sizeof(m_fltExternalI));
1169  lIndex += sizeof(m_fltExternalI);
1170 
1171  memcpy((void *)&m_fltIntrinsicI, (void *) (aryBytes+lIndex), sizeof(m_fltIntrinsicI));
1172  lIndex += sizeof(m_fltIntrinsicI);
1173 
1174  memcpy((void *)&m_fltSynapticI, (void *) (aryBytes+lIndex), sizeof(m_fltSynapticI));
1175  lIndex += sizeof(m_fltSynapticI);
1176 
1177  memcpy((void *)&m_fltVn, (void *) (aryBytes+lIndex), sizeof(m_fltVn));
1178  lIndex += sizeof(m_fltVn);
1179 
1180  memcpy((void *)&m_fltFiringFreq, (void *) (aryBytes+lIndex), sizeof(m_fltFiringFreq));
1181  lIndex += sizeof(m_fltFiringFreq);
1182 }
1183 
1184 void Neuron::Load(CStdXml &oXml)
1185 {
1186  int iCount, iIndex;
1187 
1188  Node::Load(oXml);
1189 
1190  oXml.IntoElem(); //Into Neuron Element
1191 
1192  m_arySynapses.RemoveAll();
1193 
1194  Enabled(oXml.GetChildBool("Enabled", true));
1195 
1196  Cn(oXml.GetChildFloat("Cn"));
1197  Gn(oXml.GetChildFloat("Gn"));
1198  Vrest(oXml.GetChildFloat("Vrest", 0));
1199  Vth(oXml.GetChildFloat("Vth"));
1200  Fmin(oXml.GetChildFloat("Fmin"));
1201  Gain(oXml.GetChildFloat("Gain"));
1202  ExternalI(oXml.GetChildFloat("ExternalI"));
1203  VNoiseMax(fabs(oXml.GetChildFloat("VNoiseMax", m_fltVNoiseMax)));
1204  Iinit(oXml.GetChildFloat("Iinit", m_fltIinit));
1205  InitTime(oXml.GetChildFloat("InitTime", m_fltInitTime));
1206 
1209 
1210  GainType(oXml.GetChildBool("GainType", true));
1211 
1212  m_aryVth[0] = m_aryVth[1] = m_fltVth;
1213 
1214  if(m_fltVNoiseMax != 0)
1215  UseNoise(true);
1216  else
1217  UseNoise(false);
1218 
1219  RelativeAccommodation(fabs(oXml.GetChildFloat("RelativeAccom", m_fltRelativeAccom)));
1220  AccommodationTimeConstant(fabs(oXml.GetChildFloat("AccomTimeConst", m_fltAccomTimeConst)));
1221 
1222  if(m_fltRelativeAccom != 0)
1223  UseAccom(true);
1224  else
1225  UseAccom(false);
1226 
1227  //*** Begin Loading Synapses. *****
1228  if(oXml.FindChildElement("Synapses", false))
1229  {
1230  oXml.IntoElem(); //Into Synapses Element
1231 
1232  iCount = oXml.NumberOfChildren();
1233  for(iIndex=0; iIndex<iCount; iIndex++)
1234  {
1235  oXml.FindChildByIndex(iIndex);
1236  LoadSynapse(oXml);
1237  }
1238 
1239  oXml.OutOfElem();
1240  }
1241  //*** End Loading Synapses. *****
1242 
1243 
1244  oXml.OutOfElem(); //OutOf Neuron Element
1245 }
1246 
1258 {
1259  std::string strType;
1260  Synapse *lpSynapse=NULL;
1261 
1262 try
1263 {
1264  oXml.IntoElem(); //Into Synapse Element
1265  strType = oXml.GetChildString("Type");
1266  oXml.OutOfElem(); //OutOf Synapse Element
1267 
1268  lpSynapse = dynamic_cast<Synapse *>(m_lpSim->CreateObject(Nl_NeuralModuleName(), "Synapse", strType));
1269  if(!lpSynapse)
1270  THROW_TEXT_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Synapse");
1271 
1272  lpSynapse->SetSystemPointers(m_lpSim, m_lpStructure, m_lpFRModule, this, true);
1273  lpSynapse->Load(oXml);
1274  AddSynapse(lpSynapse);
1275 
1276  return lpSynapse;
1277 }
1278 catch(CStdErrorInfo oError)
1279 {
1280  if(lpSynapse) delete lpSynapse;
1281  RELAY_ERROR(oError);
1282  return NULL;
1283 }
1284 catch(...)
1285 {
1286  if(lpSynapse) delete lpSynapse;
1287  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
1288  return NULL;
1289 }
1290 }
1291 
1292  } //Neurons
1293 } //FiringRateSim
1294 
1295 
1296 
virtual void Process(float &fltCurrent)
Processes this synapse.
Definition: Synapse.cpp:171
float m_fltIinit
The initialization current to turn on at the beginning of the simulation.
Firing rate neural module.
bool InactiveArray()
Gets the inactive array.
virtual bool UseNoise()
Gets whether to use noise.
float m_fltAdapterI
current added from all of the adapters.
virtual void Initialize()
Initializes this object.
float m_fltAccomTimeConst
The accomodation time constant tells how fast the neuron accomodates to a new membrane potential...
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
Definition: Synapse.cpp:363
virtual float Gn()
Gets the membrane conductance.
virtual float Fmin()
Gets the minimum firing frequency.
virtual float TimeStep()
Gets the time step for this moudle in time units.
virtual void Initialize()
Initializes this object.
Definition: Synapse.cpp:348
virtual float AccommodationTimeConstant()
Gets the accomodation time constant.
virtual Synapse * GetSynapse(int iIndex)
Gets a synapse by its index in the array.
float m_fltFiringFreq
Current firing frequency.
virtual void AddSynapse(Synapse *lpSynapse)
Adds a synapse to this neuron.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual void RemoveSynapse(int iIndex)
Removes the synapse described by iIndex.
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
float m_fltVndisp
this is the membrane voltage that is reported back to animatlab.
float m_fltAccomTimeMod
If we are setting the accomodation time constant through modulation then this keeps track of it...
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual float Vth()
Gets the voltage threshold for firing.
virtual float Cn()
Gets the membrane capacitance.
virtual float Vrest()
Gets the rest potential.
float m_fltVNoise
This is the random noise that should be added to the membrane voltage at a timestep.
float m_fltVthadd
The component added to Vthi for accomodation.
float m_fltVNoiseMax
Tells the maximum noise to use when running sim.
bool Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
CStdPtrArray< Synapse > m_arySynapses
The array of synapses that are in-coming to this neuron.
virtual bool SimRunning()
Gets whether the simulation is running.
Definition: Simulator.cpp:673
Organism * m_lpOrganism
The pointer to this node's organism.
Definition: Node.h:29
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
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
virtual bool Enabled()
Tells whether this node is enabled.
Definition: Node.cpp:84
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
virtual float CalculateIntrinsicCurrent(FiringRateModule *lpModule, float fltInputCurrent)
Calculates the intrinsic current.
std::string Std_Trim(std::string strVal)
Trims a string.
float m_aryVn[2]
Current and next Membrane voltage. Vn.
float m_fltExternalI
Externally injected current.
virtual void StepSimulation()
Step the simulation for this object.
virtual bool RemoveItem(const std::string &strItemType, const std::string &strID, bool bThrowError=true)
Removes a child item from this parent.
virtual void ClearSynapses()
Clears the synapses list.
virtual int TotalSynapses()
Gets the total number of synapses.
virtual CStdSerialize * CreateObject(std::string strModule, std::string strClassName, std::string strType, bool bThrowError=true)
Creates an object using a class factory.
Definition: Simulator.cpp:3440
float m_fltAdapterMemoryI
Used to allow datacharts to track current input from adapters.
virtual unsigned char NeuronType()
Gets the neuron type.
virtual bool UseAccom()
Gets whether to use accommodation.
float m_fltFmin
Minimum Firing frequency.
virtual float ExternalI()
Gets the external current.
float m_fltIntrinsicI
Intrinsic current.
float m_fltInvCn
Inverse membrane capacitance.
Firing Rate Neuron model.
virtual CStdPtrArray< Synapse > * GetSynapses()
Gets a pointer to the synapses array.
bool m_bUseAccom
true use accomodation
virtual long CalculateSnapshotByteSize()
Calculates the snapshot byte size.
virtual float CalculateSynapticCurrent(FiringRateModule *lpModule)
Calculates the total incoming synaptic current.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
float m_fltInitTime
The duration for how long the Iinit current is on at the beginning of the simulation.
float m_fltVn
Current membrane voltage.
virtual float FiringFreq(FiringRateModule *lpModule)
Calculates the current firing frequency.
virtual float Vn()
Gets the membrane voltage.
virtual void SaveKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Saves a key frame snapshot.
Declares the synapse class.
virtual void AddExternalNodeInput(int iTargetDataType, float fltInput)
Adds an external node input.
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual int FindSynapseListPos(std::string strID, bool bThrowError=true)
Searches for a synapse with the specified ID and returns its position in the list.
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 float VNoiseMax()
Gets the maximum noise voltage.
float m_fltVth
Firing frequency voltage threshold.
Declares the firing rate module class.
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 float Gain()
Gets the firing frequency gain.
virtual float RelativeAccommodation()
Gets the relative accomodation.
float Std_FRand(float low, float high)
Generates a random number between two values.
float m_fltRelativeAccom
The relative accomodation rate.
virtual float IntrinsicCurrent()
Gets the intrinsic current.
float m_fltCn
Membrane capacitance.
float m_fltVthi
Initial firing frequency voltage threshold.
virtual void AddExternalI(float fltVal)
Adds to the external current.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
Neuron * FromNeuron()
Gets the pre-synaptic neuron.
Definition: Synapse.h:77
virtual void LoadKeyFrameSnapshot(byte *aryBytes, long &lIndex)
Loads a key frame snapshot.
bool ActiveArray()
Gets the active array.
Contains the classes for a firing rate neural model.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Node.cpp:106
Firing rate synapse model.
Definition: Synapse.h:29
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void TimeStepModified()
Notification method that the time step modified has been modified. Objects should recalculate any sli...
float m_fltTotalMemoryI
Total current applied to the neuron.
virtual bool AddItem(const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
Adds a new object to this parent.
bool m_bUseNoise
Tells if we should use noise or not.
float m_fltGn
Membrane conductance.
virtual float Time()
Gets the current simulation time in seconds.
Definition: Simulator.cpp:559
float m_fltDCTH
expon decline working factor for thresh accomm
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
virtual float CalculateFiringFrequency(float fltVn, float fltVth)
Calculates the firing frequency of the neuron.
virtual void InjectCurrent(float fltVal)
Injects current into this neuron.
bool m_bGainType
Tells whether to use the old type gain or new type gain.
Synapse * LoadSynapse(CStdXml &oXml)
Loads a synapse.
float m_fltSynapticI
Current synaptic current.
float m_fltVthdisp
this is the theshold voltage that is reported back to animatlab.
float m_aryVth[2]
Current and next threshold voltage. Vth.
FiringRateModule * m_lpFRModule
Pointer to the parent FiringRateModule.
float m_fltVrest
this is the resting potential of the neuron.
virtual bool GainType()
Gets the gain type. (Old way or new way)