AnimatLab  2
Test
Connexion.cpp
Go to the documentation of this file.
1 
7 #include "stdafx.h"
8 #include "IonChannel.h"
9 #include "SynapseType.h"
10 #include "IntegrateFireModule.h"
11 #include "Connexion.h"
12 #include "CaActivation.h"
13 #include "Neuron.h"
14 #include "ElectricalSynapse.h"
16 #include "SpikingChemicalSynapse.h"
17 
18 namespace IntegrateFireSim
19 {
20  namespace Synapses
21  {
22 
30 {
31  m_iSource = -1;
32  m_iTarget = -1;
33  //m_dPartialBlock=1.0;
34  m_lpSynType = NULL;
35 
36  m_dDelay = 0;
37 
38  m_dBaseG = 0.5f;
39  m_dG = m_dBaseG;
43  //m_dPartialBlockHold = 0;
46 }
47 
60 Connexion::Connexion(int type, int ID, double delay,float topBlock,float botBlock)
61 {
62  m_iSource = -1;
63  m_iTarget = -1;
64  m_iType=type;
65  m_iID=ID;
66  m_dDelay=delay;
67 
68  //m_dPartialBlock=1.0;
69  m_lpSynType = NULL;
70 
71  m_dBaseG = 0.5f;
72  m_dG = m_dBaseG;
76  //m_dPartialBlockHold = 0;
79 }
80 
88 {
89 
90 }
91 
92 #pragma region Accessor-Mutators
93 
102 void Connexion::BaseConductance(double dVal)
103 {
104  //The mempot variables are calculated, so we do not want to just re-set them to the new value.
105  //instead lets adjust them by the difference between the old and new resting potential.
106  double dDiff = dVal - m_dBaseG;
107 
108  m_dBaseG = dVal;
109  m_dG += dDiff;
110  m_dGFacilCx += dDiff;
111 
113  m_fltGReport = m_dG;
114 }
115 
125 
134 void Connexion::Delay(double dVal) {m_dDelay = dVal;}
135 
144 double Connexion::Delay() {return m_dDelay;}
145 
155 
164 void Connexion::SynapseTypeID(std::string strID) {m_strSynapseTypeID = strID;}
165 
174 std::string Connexion::SourceID() {return m_strSourceID;}
175 
184 void Connexion::SourceID(std::string strID) {m_strSourceID = strID;}
185 
194 std::string Connexion::TargetID() {return m_strTargetID;}
195 
204 void Connexion::TargetID(std::string strID) {m_strTargetID = strID;}
205 
213 {
214  if(m_lpSynType)
216 
217  if(m_lpSource)
219 
220  if(m_lpTarget)
222 }
223 
224 #pragma endregion
225 
235 {
236  if(m_lpSynType)
237  {
239  if(!lpSyn)
240  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": FacilD");
241 
242  return lpSyn->FacilD();
243  }
244  else
245  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": FacilD");
246  return 0;
247 }
248 
258 {
259  if(m_lpSynType)
260  {
262  if(!lpSyn)
263  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": RelFacil");
264 
265  return lpSyn->RelFacil();
266  }
267  else
268  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": RelFacil");
269  return 0;
270 }
271 
279 {
280  if (RelFacil()==1)
281  return;
282  else
283  {
286  }
287 }
288 
298 {
299  if(m_lpSynType)
300  {
302  if(lpSyn)
303  return lpSyn->VoltDep();
304  else
305  return false;
306  }
307  else
308  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": VoltDep");
309  return false;
310 }
311 
321 {
322  if(m_lpSynType)
323  {
325  if(lpSyn)
326  return lpSyn->Hebbian();
327  else
328  return false;
329  }
330  else
331  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": Hebbian");
332  return false;
333 }
334 
344 {
345  if(m_lpSynType)
346  {
348  if(!lpSyn)
349  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": HebbIncrement");
350 
351  return lpSyn->HebbIncrement();
352  }
353  else
354  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": HebbIncrement");
355  return 0;
356 }
357 
367 {
368  if(m_lpSynType)
369  {
371  if(!lpSyn)
372  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": HebbTimeWindow");
373 
374  return lpSyn->HebbTimeWindow();
375  }
376  else
377  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": HebbTimeWindow");
378  return 0;
379 }
380 
390 {
391  if(m_lpSynType)
392  {
394  if(!lpSyn)
395  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": MaxGHebb");
396 
397  return lpSyn->MaxGHebb();
398  }
399  else
400  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": MaxGHebb");
401  return 0;
402 }
403 
413 {
414  if(m_lpSynType)
415  {
417  if(lpSyn)
418  return lpSyn->AllowForgetting();
419  else
420  return false;
421  }
422  else
423  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": AllowForgetting");
424  return false;
425 }
426 
436 {
437  if(m_lpSynType)
438  {
440  if(!lpSyn)
441  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": ForgettingWindow");
442 
443  return lpSyn->ForgettingWindow();
444  }
445  else
446  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": ForgettingWindow");
447  return 0;
448 }
449 
459 {
460  if(m_lpSynType)
461  {
463  if(!lpSyn)
464  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": Consolidation");
465 
466  return lpSyn->Consolidation();
467  }
468  else
469  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": Consolidation");
470  return 0;
471 }
472 
482 {
483  if(m_lpSynType)
484  {
486  if(!lpSyn)
487  THROW_TEXT_ERROR(Rn_Err_lNotChemSpikeSyn, Rn_Err_strNotChemSpikeSyn, "ID: " + m_strID + ": MaxGVoltDepRel");
488 
489  return lpSyn->MaxGVoltDepRel();
490  }
491  else
492  THROW_TEXT_ERROR(Rn_Err_lSynpaseTypeNotDefined, Rn_Err_strSynpaseTypeNotDefined, "ID: " + m_strID + ": MaxGVoltDepRel");
493  return 0;
494 }
495 
496 void Connexion::Load(CStdXml &oXml)
497 {
498  AnimatBase::Load(oXml);
499 
500  oXml.IntoElem(); //Into SpikingChemSyn Element
501 // m_dLowCoup= oXml.GetChildDouble("dLowCoup");
502 
503  //m_iSource=oXml.GetChildInt("Source");
504  m_strSourceID = oXml.GetChildString("SourceID");
505  //m_iTarget=oXml.GetChildInt("Target");
506  m_strTargetID = oXml.GetChildString("TargetID");
507  m_iType=oXml.GetChildInt("Type");
508  //m_iID=oXml.GetChildInt("SynapseID");
509  m_strSynapseTypeID = oXml.GetChildString("SynapseTypeID");
510  //m_dPartialBlockHold=oXml.GetChildDouble("PartialBlockHold", 0);
511 
512  BaseConductance(oXml.GetChildDouble("G"));
513  Delay(oXml.GetChildDouble("Delay"));
514 
515  oXml.OutOfElem(); //OutOf Neuron Element
516 }
517 
519 // WORKING
520 
530 void Connexion::DecrementLatencies(double dt,bool FreezeLearning)
531 {
532  double *pTimeToNext;
533  while (1)
534  { // decrease latency for all spikes in transit
535  pTimeToNext=m_TransitCx.Iterate();
536  if (pTimeToNext==NULL) // end of spike list for connexion
537  break;
538  (*pTimeToNext)-=dt;
539  }
540 
541  if (Hebbian() && !FreezeLearning)
542  {
543  bool bTimedOut=false;
544  while (1)
545  { // decrease time marker latency for all previous Hebb events
546  pTimeToNext=m_HebbList.Iterate();
547  if (pTimeToNext==NULL) // end of Hebb list
548  break;
549 //TRACE("decrementing Hebbian time window\n");
550  (*pTimeToNext)-=dt;
551  if ((*pTimeToNext)<=0) // can't delete now because resets iterator
552  bTimedOut=true;
553  }
554  if (bTimedOut==true)
555  {
556 //TRACE("a Hebb input timed out; deleting from list\n");
557  m_HebbList.Del();
558  }
559  if (m_dTimeSincePrevHebbEvent<ForgettingWindow()) // prevent overflow
561  }
562 }
563 
571 {
572  if (Hebbian())
573  {
574  double newG, *pTimeLeftInHebbWindow;
575  while (1) // iterate through Hebb list
576  {
577  pTimeLeftInHebbWindow=m_HebbList.Iterate();
578  if (pTimeLeftInHebbWindow==NULL) // end of Hebb list
579  break;
580 
581 //TRACE("Incrementing Hebbian synapse: m_G was %lf, facil G was %lf\n",m_G,m_GFacilCx);
582  newG=m_dG+(MaxGHebb()-m_dG)*HebbIncrement()*((*pTimeLeftInHebbWindow)/HebbTimeWindow());
583  //ASSERT(newG<=m_dMaxGHebb);
584 // increment current facilitation state by same percentage as base conductance
586  m_dG=newG;
588  m_fltGReport = m_dG;
589 
590 //TRACE("time left in Hebb window = %lf, increment factor = %lf\n",*pTimeLeftInHebbWindow,m_HebbIncrement*((*pTimeLeftInHebbWindow)/m_HebbTimeWindow));
591 //TRACE("and now m_G is %lf, facil G is %lf\n",m_G, m_GFacilCx);
593  }
594  }
595 }
596 
607 double Connexion::ProcessOutput(bool bFreezeHebb)
608 {
609 // if allowing forgetting, decrement Hebb augmentation by fraction of ForgettingWindow
610 // since last Hebb augmentation event
611  if (Hebbian() && AllowForgetting() && !bFreezeHebb)
612  {
613  double newG;
614  double dblForgettingWindow=ForgettingWindow();
615  if (Consolidation()!=1)
616  dblForgettingWindow=dblForgettingWindow*(1+((Consolidation()-1)*(m_dG-m_dBaseG)/(MaxGHebb()-m_dBaseG)));
617  if (m_dTimeSincePrevHebbEvent>=dblForgettingWindow)
618  newG=m_dBaseG;
619  else
620  newG=m_dG-(m_dG-m_dBaseG)*m_dTimeSincePrevHebbEvent/dblForgettingWindow;
621 //ASSERT(m_dG>=m_dBaseG);
622 // decrease current facilitation state by same percentage as base conductance
623  m_dGFacilCx=m_dGFacilCx*newG/m_dG;
624  m_dG=newG;
625 //TRACE("forgetting window = %lf\n",ForgettingWindow);
626  }
627 
628  double G;
629  G=STD_MAX((double) 0,m_dGFacilCx); // get conductance, if not facil below 0
630  m_dGFacilCx=(m_dGFacilCx-m_dG)+(m_dG*RelFacil()); // facilitate next response
631  m_TransitCx.Del(); // remove spike from list
632 
633 // if Hebbian, store set time window
634  if (Hebbian())
635  {
637 // m_PreviousSpikeLatency=m_HebbTimeWindow;
638 //TRACE("appending Hebbian time window to Hebb list\n");
639 
640  }
641 
643  m_fltGReport = m_dG;
644 
645  return G;
646 }
647 
658 double Connexion::GetProspectiveCond(bool bFreezeHebb)
659 {
660  double G=m_dGFacilCx;
661 // if allowing forgetting, decrement Hebb augmentation by fraction of ForgettingWindow
662 // since last Hebb augmentation event
663  if (Hebbian() && AllowForgetting() && !bFreezeHebb)
664  {
665  double newG;
666  double dblForgettingWindow=ForgettingWindow();
667  if (Consolidation()!=1)
668  dblForgettingWindow=dblForgettingWindow*(1+((Consolidation()-1)*(m_dG-m_dBaseG)/(MaxGHebb()-m_dBaseG)));
669  if (m_dTimeSincePrevHebbEvent>=dblForgettingWindow)
670  newG=m_dBaseG;
671  else
672  newG=m_dG-(m_dG-m_dBaseG)*m_dTimeSincePrevHebbEvent/dblForgettingWindow;
673 //ASSERT(m_dG>=m_dBaseG);
674 // decrease current facilitation state by same percentage as base conductance
675  G=m_dGFacilCx*newG/m_dG;
676  }
677 
678 //TRACE("GetProspectiveCond = %lf\n",G);
679  return(STD_MAX((double) 0,G)); // get conductance, if not facil below 0
680 }
681 
683 {
685  m_dG = m_dBaseG;
688 }
689 
690 void Connexion::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, AnimatSim::Behavior::NeuralModule *lpModule, Node *lpNode, bool bVerify)
691 {
692  AnimatBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, false);
693 
694  m_lpIGFModule = dynamic_cast<IntegrateFireNeuralModule *>(lpModule);
695 
696  if(bVerify) VerifySystemPointers();
697 }
698 
700 {
701  AnimatBase::VerifySystemPointers();
702 
703  if(!m_lpIGFModule)
704  THROW_PARAM_ERROR(Al_Err_lStructureNotDefined, Al_Err_strStructureNotDefined, "IGFModule: ", m_strID);
705 }
706 
707 #pragma region DataAccesMethods
708 
709 float *Connexion::GetDataPointer(const std::string &strDataType)
710 {
711  std::string strType = Std_CheckString(strDataType);
712 
713  if(strType == "CONDUCTANCE")
714  return &m_fltGReport;
715 
716  if(strType == "FACILITATION")
717  return &m_fltGFailCxReport;
718 
719  //If it was not one of those above then we have a problem.
720  THROW_PARAM_ERROR(Rn_Err_lInvalidNeuronDataType, Rn_Err_strInvalidNeuronDataType, "Neuron Data Type", strDataType);
721 
722  return NULL;
723 }
724 
725 bool Connexion::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
726 {
727  std::string strType = Std_CheckString(strDataType);
728 
729  if(Link::SetData(strDataType, strValue, false))
730  return true;
731 
732  if(strType == "SYNAPTICCONDUCTANCE")
733  {
734  BaseConductance(atof(strValue.c_str()));
735  return true;
736  }
737 
738  if(strType == "CONDUCTIONDELAY")
739  {
740  Delay(atof(strValue.c_str()));
741  return true;
742  }
743 
744  if(strType == "SYNAPSETYPEID")
745  {
746  SynapseTypeID(strValue);
748  return true;
749  }
750 
751  //If it was not one of those above then we have a problem.
752  if(bThrowError)
753  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
754 
755  return false;
756 }
757 
758 void Connexion::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
759 {
760  Link::QueryProperties(aryProperties);
761 
762  aryProperties.Add(new TypeProperty("Conductance", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
763  aryProperties.Add(new TypeProperty("Facilitation", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
764 
765  aryProperties.Add(new TypeProperty("SynapticConductance", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
766  aryProperties.Add(new TypeProperty("ConductionDelay", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
767  aryProperties.Add(new TypeProperty("SynapseTypeID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
768 }
769 
770 #pragma endregion
771 
772 
773  } //Synapses
774 } //IntegrateFireSim
775 
void ResetIDs()
Resets the IDs of the synapse types.
Definition: Connexion.cpp:212
Neuron * m_lpSource
Pointer to the source Neuron.
Definition: Connexion.h:84
int Del(void)
Deletes this object.
Definition: DoubleList.cpp:73
void DecrementLatencies(double dt, bool FreezeLearning=false)
Decrements latencies.
Definition: Connexion.cpp:530
double ForgettingWindow()
Gets the forgetting time window.
double * Iterate(void)
Gets the iterate.
Definition: DoubleList.cpp:108
bool VoltDep()
Gets whether this synapse is voltage dependent.
int m_iType
Zero-based index of the synaspe type.
Definition: Connexion.h:96
Declares the integrate fire module class.
Integrate and fire neural module.
void IncrementHebbian()
Increments hebbian values.
Definition: Connexion.cpp:570
double HebbIncrement()
Increments the hebbian weight.
Definition: Connexion.cpp:343
DoubleList m_TransitCx
Sets whether there is a partial block hold.
Definition: Connexion.h:122
double m_dPreviousSpikeLatency
The partial block.
Definition: Connexion.h:149
Connexion()
Default constructor.
Definition: Connexion.cpp:29
int NeuronID()
Gets the neuron ID.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Definition: Connexion.cpp:709
double MaxGVoltDepRel()
Gets the maximum relative conductance.
double m_dGFacilCx
facilitated increase in g when input occurs
Definition: Connexion.h:105
Declares the connexion class.
std::string SynapseTypeID()
Gets the synapse type identifier.
Definition: Connexion.cpp:154
double Delay()
Gets the synaptic delay.
Definition: Connexion.cpp:144
double MaxGHebb()
Gets the maximum hebbian conductance.
Definition: Connexion.cpp:389
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
double RelFacil()
Gets the relative facilitation.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: Connexion.cpp:682
double FacilD()
Gets the facilitation decrement value.
int SynapseTypeID()
Gets the synapse type identifier.
Definition: SynapseType.cpp:68
double HebbTimeWindow()
Gets the learning time window.
double Consolidation()
Gets the consolidation factor.
Definition: Connexion.cpp:458
std::string TargetID()
Gets the target neuron ID.
Definition: Connexion.cpp:194
float m_fltGReport
The reported variable for synaptic conductance.
Definition: Connexion.h:114
int m_iTarget
Zero-based index of the target neuron.
Definition: Connexion.h:93
Declares the spiking chemical synapse class.
double ProcessOutput(bool bFreezeHebb=false)
Process the output described of the connection.
Definition: Connexion.cpp:607
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
double BaseConductance()
Gets the base conductance.
Definition: Connexion.cpp:124
void PreCalc()
Performs pre-step calculations.
void Hebbian(bool bVal)
Sets whether this synapse uses Hebbian learning.
std::string SourceID()
Gets the source neuron ID.
Definition: Connexion.cpp:174
virtual ~Connexion()
Destructor.
Definition: Connexion.cpp:87
Neuron * m_lpTarget
Pointer to the target Neuron.
Definition: Connexion.h:87
int AddTail(double d)
Adds a tail.
Definition: DoubleList.cpp:48
Declares the ca activation class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: Connexion.cpp:699
double m_dBaseG
The base conductance.
Definition: Connexion.h:137
double m_dTimeSincePrevHebbEvent
The time since previous hebb event.
Definition: Connexion.h:143
IntegrateFireNeuralModule * m_lpIGFModule
The pointer to the parent IntegrateFireNeuralModule.
Definition: Connexion.h:68
double MaxGVoltDepRel()
Gets the maximum conductance for voltage dependent.
Definition: Connexion.cpp:481
double HebbTimeWindow()
Gets the hebbian time window.
Definition: Connexion.cpp:366
float m_fltGFailCxReport
reported variable for facilitated increase in g when input occurs
Definition: Connexion.h:108
bool Hebbian()
Gets if the synapse type is Hebbian.
Definition: Connexion.cpp:320
std::string m_strSynapseTypeID
GUID ID for the synapse type to use.
Definition: Connexion.h:78
double ForgettingWindow()
Gets the forgetting time window.
Definition: Connexion.cpp:435
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: Connexion.cpp:725
bool VoltDep()
Gets whether the synapse type is voltage dependent.
Definition: Connexion.cpp:297
Declares the synapse type class.
double m_dG
The synaptic conductance.
Definition: Connexion.h:111
SynapseType * m_lpSynType
Pointer to the synapse type for this connection.
Definition: Connexion.h:81
double MaxGHebb()
Gets the maximum augmented conductance.
void Release(void)
Releases this object.
Definition: DoubleList.cpp:90
Declares the electrical synapse class.
double RelFacil()
Gets the relative facilitation.
Definition: Connexion.cpp:257
std::string m_strTargetID
GUID ID for the target Neuron.
Definition: Connexion.h:75
bool AllowForgetting()
Gets whether forgetting is allowed.
Definition: Connexion.cpp:412
DoubleList m_HebbList
List of hebbian events.
Definition: Connexion.h:140
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
double GetProspectiveCond(bool bFreezeHebb)
Gets a prospective condutance.
Definition: Connexion.cpp:658
double FacilD()
Gets the facilitation decrement value.
Definition: Connexion.cpp:234
double Consolidation()
Gets the consolidation factor.
int m_iID
Identifier ID for this connection.
Definition: Connexion.h:99
std::string m_strSourceID
GUID ID for the source Neuron.
Definition: Connexion.h:72
int m_iSource
Zero-based index of the source neuron.
Definition: Connexion.h:90
void AllowForgetting(bool bVal)
Sets whether forgetting is allowed.
void DecrementFacilitation()
Decrements the facilitation.
Definition: Connexion.cpp:278
double m_dDelay
The synaptic delay.
Definition: Connexion.h:102
Contains all of the classes to implement a basic integrate and fire neural model. ...
Declares the non spiking chemical synapse class.
Declares the neuron class.