📄 fastneuron.cpp
字号:
/*************************************************************************** fastneuron.cpp - description ------------------- begin : Tue Jan 22 2002 copyright : (C) 2002 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. * * * ***************************************************************************/using namespace std;#include <cmath>#include <iostream>#include "fastneuron.h"#include "functionlookup.h"FastNeuron::FastNeuron(AmIdInt neuronId): Neuron(neuronId){ pspLookup = 0; histBgnIdx = 0;}FastNeuron::~FastNeuron(){}void FastNeuron::InputSpike(SynapseItr& inSynapse, AmTimeInt inTime, unsigned int numSyn = 0){ // If the neuron is within a refractory period, either ignore the // input (training off) or call Train(inTime) if ( (inTime - spikeTime) <= refPeriod ) { // Don't do anything if spikeTime == 0 because this neuron // has not yet fired and the simulation time could be less // than the refractory period. if (spikeTime) { if ( IsTraining() ) { Train(inTime); } return; } } float inWeight = 0.0; if (numSyn) { for (unsigned int i=0; i<numSyn; ++i) { inWeight += inSynapse[i]->GetWeight(); } } else { inWeight = inSynapse[0]->GetWeight(); } if (trainingMode) { SynapseHist synHist; synHist.time = inTime; if (numSyn) { for (unsigned int i=0; i<numSyn; ++i) { synHist.syn = inSynapse[i]; synapseHist.push_back(synHist); } } else { synHist.syn = inSynapse[0]; synapseHist.push_back(synHist); } } // If a spike is scheduled for this time step and the pre-synaptic // spike is excitatory, don't do anything more. if (inTime == schedSpikeTime) { if (inWeight > 0.0) { return; } } unsigned int tblIndex = (unsigned int)((float)(inTime - currTime) * stepSizeInv); if (tblIndex < pspLSize) { // don't go beyond the end of the tables membranePtnl = membranePtnl * pspLookup[tblIndex]; membranePtnl += inWeight; } else { membranePtnl = inWeight; } currTime = inTime; if (membranePtnl >= 1.0) { // Schedule a spike for the next time step. schedSpikeTime = inTime + simStepSize; SNet->ScheduleNEvent( SPIKE, schedSpikeTime, this ); }}void FastNeuron::SetMaxScaledWeight(){ // The PSP function for this neuron model is Ep = exp[ -t/Tm ]. // The threshold is assumed to be at 1, so the weights are already normalized. maxScaledWeight = 1.0;}float* FastNeuron::InitializeLookupTable(int index){ unsigned int i; switch (index) { case 0: pspLookup = new float[pspLSize]; for (i=0; i<pspLSize; i++) { pspLookup[i] = 0.0; } if ( FillLookupTables(index) ) { return pspLookup; } else { cerr << "FillLookupTables() failed in Neuron.\n"; return 0; } break; default: return 0; }}float* FastNeuron::GetTableParams(int index, int& numParams){ float* paramList; switch (index) { case 0: numParams = 1; paramList = new float[1]; paramList[0] = memTimeConst; break; default: return 0; } return paramList;}int FastNeuron::SetLookupTables(FunctionLookup* funcRef){ // Get the pointer for the pspLookup table. If a table for this // class and set of constants has not been initialized, the FunctionLookup // class will call this.InitializeLookupTable() pspLookup = funcRef->GetLookupTable(this, 0, pspLSize, pspStepSize); // set stepSizeInv for InputSpike stepSizeInv = 1.0/pspStepSize; // test for table pointers if ( pspLookup == 0) { return 0; } SetMaxScaledWeight(); return 1;}int FastNeuron::FillLookupTables(int index){ if (pspLSize == 0 || pspStepSize == 0) { return 0; } float calcTm = 0.0; unsigned int i; switch (index) { case 0: // Fill the PSP table //cout << "Filling PSP Table..." << endl; for (i=0; i<pspLSize; i++) { calcTm = (float(i) * pspStepSize); PspKernel(calcTm, &pspLookup[i]); } break; default: return 0; } usePspLookup = true; return 1;}inline void FastNeuron::PspKernel(float calcTime, float* pspElement){ // Model the PSP as Ep = exp[ -t / Tm ] float expTerm, convCalcTime; // convert time from microseconds to miliseconds convCalcTime = calcTime / 1000.0; expTerm = -convCalcTime/memTimeConst; *pspElement = exp(expTerm);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -