📄 synapse.cpp
字号:
/*************************************************************************** synapse.cpp - description ------------------- begin : Fri Jun 20 2003 copyright : (C) 2003 by Matt Grover email : mgrover@amygdala.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "synapse.h"#include "dendrite.h"#include "neuron.h"#include "spikingneuron.h"#include "logging.h"#include "statictrainer.h"#include <new>#include <iostream>#include <cmath>using namespace Amygdala;using namespace std;StaticSynapse::NeuronConnector StaticSynapse::Connect;DynamicSynapse::NeuronConnector DynamicSynapse::Connect;//-------------- Methods of class Synapse ---------------------------------//Synapse::Synapse(SynapseProperties& synProps): AmygdalaClass(), dendrite(0), lastTransTime(0){}Synapse::Synapse(const Synapse& rhs): AmygdalaClass(), dendrite(rhs.dendrite), lastTransTime(rhs.lastTransTime){}AmIdInt Synapse::GetPostNrnId(){ return dendrite->GetPostNeuron()->GetId();}SynapseProperties* Synapse::Properties(SynapseProperties* props) const{ // FIXME: Need to get the delay value somehow //props->SetDelay(delay); return props;}StaticSynapse::StaticSynapse(StaticSynapseProperties& synProps): Synapse(synProps), weight(synProps.GetWeight()), trainingHistIdx(0){}StaticSynapse::StaticSynapse(const StaticSynapse& rhs): Synapse(rhs){ weight = rhs.weight; trainingHistIdx = rhs.trainingHistIdx;}void StaticSynapse::Clone(void* newSynapse){ // call placement new with the copy constructor to clone this // synapse into the newSynapse address. Memory has been pre-allocated // by AxonNode.#ifdef LOGLEVEL StaticSynapse* s = new(newSynapse) StaticSynapse(*this);#else new(newSynapse) StaticSynapse(*this);#endif LOGGER(6, "Cloned StaticSynapse at addr " << newSynapse); LOGGER(6, "StaticSynapse* s = " << s);}SynapseProperties* StaticSynapse::Properties() const{ StaticSynapseProperties* sp = new StaticSynapseProperties(weight, 0); Synapse::Properties(sp); return sp;}void StaticSynapse::TransmitSpike(const AmTimeInt& time){ LOGGER(5, "Transmitting spike to neuron " << GetPostNrnId() << " -- weight: " << weight); if (!(dendrite->TriggerIsSet())) { dendrite->SetNrnTrigger(); } dendrite->AddToTotal(weight); if (dendrite->GetTrainer()) { // static_cast can be used here because the Trainer was verified to be of the correct // type when this synapse was added to the dendrite static_cast<StaticTrainer*>(dendrite->GetTrainer())->Train(this, lastTransTime, trainingHistIdx); } lastTransTime = time;}////////////////////////////////////////////////////////////////////////////DynamicSynapse::DynamicSynapse(const DynamicSynapse& rhs): Synapse(rhs){ A = rhs.A; U = rhs.U; D = rhs.D; F = rhs.F; u = rhs.u; fraction = rhs.fraction;}DynamicSynapse::DynamicSynapse(DynamicSynapseProperties& synProps): Synapse(synProps){ A = synProps.GetDynaParam('A'); U = synProps.GetDynaParam('U'); D = synProps.GetDynaParam('D'); F = synProps.GetDynaParam('F'); u = U; fraction = 1.0; invD = 1./D; invF = 1./F;}void DynamicSynapse::Clone(void* newSynapse){ DynamicSynapse* s = new(newSynapse) DynamicSynapse(*this);}SynapseProperties* DynamicSynapse::Properties() const{ DynamicSynapseProperties* sp = new DynamicSynapseProperties(0); Synapse::Properties(sp); sp->SetDynaParam('A', A); sp->SetDynaParam('U', U); sp->SetDynaParam('D', D); sp->SetDynaParam('F', F); return sp;}void DynamicSynapse::TransmitSpike(const AmTimeInt& time){ if (!(dendrite->TriggerIsSet())) { dendrite->SetNrnTrigger(); } float dt = float(time-lastTransTime)/1000000.; // seconds //float dt = float(time-lastTransTime)/1000; // ms float expF = exp(-dt/F); float expD = exp(-dt/D); fraction = fraction * (1 - u) * expD + 1 - expD; u = u * expF + U * ( 1 - u * expF); // Changed to version of equations found in "Synapses as Dynamic Memory Buffers" by // Maass and Markram /*fraction = 1 + ((fraction - (fraction*u) - 1) * exp(-dt*invD)); // fraction calc must go before new u is calced u = U + (u * (1-U) * exp(-dt*invF));*/ float contrib = A*fraction*u; dendrite->AddToTotal(contrib); LOGGER(6, "Transmitting spike to neuron " << GetPostNrnId() << " -- synaptic response: " << contrib); //cout << "Synaptic response at time " << Network::SimTime() << ": " << contrib << endl; lastTransTime = time;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -