📄 basicneuron.cpp
字号:
else { converged = 0; } } else { // find a good starting point for N's method// calcTime = inTime + int( memTimeConst * 1000.0 );//// while (iterate) {// CalcState(currState, currDeriv, calcTime, histSize);//// if ( (currDeriv < 0.0) || (currState > thresholdPtnl) ) {// // went too far -- choose a smaller starting point// calcTime -= ( ( calcTime - inTime ) / 2 );// }// else {// // good starting point// iterate = 0;// }// }//// iterate = 1; } lstThreshCrs = float(calcTime); while (iterate) { currState = 0.0; currDeriv = 0.0; // debug msg // calcTime has to be rounded to the nearest simStepSize Utilities::RoundTime(calcTime, pspStepSize); #ifdef DEBUG_NEURON cout << "calcTime: " << calcTime << endl; #endif // should be inline CalcState(currState, currDeriv, calcTime, histSize);// for (i=0; i<histSize; i++) {// funcTime = calcTime - inTimeHist[i];// funcWeight = inWeightHist[i];//// // debugging msg// cout << "funcTime: " << funcTime << endl;// cout << "funcWeight: " << funcWeight << endl;// // end debugging//// tblIndex = (funcTime / pspStepSize);// currState = currState + (funcWeight * (pspLookup[tblIndex]));// currDeriv = currDeriv + (funcWeight * (dPspLookup[tblIndex]));// } #ifdef DEBUG_NEURON cout << "currState: " << currState << endl; cout << "currDeriv: " << currDeriv << endl; #endif if ( (currDeriv < 0.0) && (currState < 1.0) ) { converged = 0; iterate = 0; // set the scheduled spike time to zero to keep // the neuron from spiking when an inhibitory input // spike has canceled a previously scheduled spike. schedSpikeTime = 0; } else if (currState > 1.0) { converged = 1; iterate = 0; } else { stateDelta = fabs(1.0 - currState); threshCrs = (stateDelta / currDeriv) + lstThreshCrs; #ifdef DEBUG_NEURON cout << "stateDelta: " << stateDelta << endl; cout << "threshCrs: " << threshCrs << endl; cout << "lstThreshCrs: " << lstThreshCrs << endl; #endif if ( (threshCrs - lstThreshCrs) < convergeRes) { converged = 1; iterate = 0; #ifdef DEBUG_NEURON cout << "threshCrs - lstThreshCrs < convergeRes\n"; cout << "Converged\n"; #endif } else { converged = 0; if (threshCrs > (maxThreshCrs + lstThreshCrs)) { iterate = 0; } calcTime = int(threshCrs); lstThreshCrs = threshCrs; // set the scheduled spike time to zero to keep // the neuron from spiking when an inhibitory input // spike has canceled a previously scheduled spike. schedSpikeTime = 0; } } } if (converged) { // Make sure we wait at least one cycle before spiking if (calcTime == inTime) { calcTime += simStepSize; } schedSpikeTime = calcTime; LOGGER(5, "Neuron " << nId << " Scheduling spike at " << schedSpikeTime) Network::GetNetworkRef()->ScheduleSpike( schedSpikeTime, this ); }}void BasicNeuron::ScaleFunctionLookups(){ unsigned int i; float lastPtnl=0.0; float maxPtnl=0.0; cout << "Scaling function lookup\n"; for (i=0; i<pspLSize; i++) { LOGGER(1, "pspLookup[" << i << "] = " << pspLookup[i]); } for (i=0; i<pspLSize; ++i) { maxPtnl = pspLookup[i]; if (maxPtnl < lastPtnl) { maxPtnl = lastPtnl; break; } else { lastPtnl = maxPtnl; } } if (maxPtnl == 0.0) return; // Normalize the function float scaleFactor = 1.0/maxPtnl; for (i=0; i<pspLSize; i++) { pspLookup[i] = scaleFactor*pspLookup[i]; dPspLookup[i] = scaleFactor*dPspLookup[i]; }}float BasicNeuron::GetMembranePtnl(){ float currState=0.0, currDeriv=0.0; AmTimeInt calcTime = Network::GetNetworkRef()->SimTime(); Utilities::RoundTime(calcTime, pspStepSize); CalcState(currState, currDeriv, calcTime, inputHist.size()); return currState;}void BasicNeuron::Init(){ pspStepSize = Network::TimeStepSize(); pspLSize = 100000/pspStepSize; // 100ms / step size LOGGER(3, "pspStepSize: " << pspStepSize << " pspLSize: " << pspLSize)}void BasicNeuron::InitLookup(){ FunctionLookup* fl = Network::GetNetworkRef()->GetFunctionLookup(); try { TableProperties t0 = GetTableProps(0); TableProperties t1 = GetTableProps(1); pspLookup = fl->GetTableData(t0); dPspLookup = fl->GetTableData(t1); } catch (TableNotFoundException& e) { MakeLookupTables(); //PrintLookupTables(); }}TableProperties BasicNeuron::GetTableProps(unsigned int index){ TableProperties props; props.SetClassName("BasicNeuron"); props.SetTableSize(pspLSize); BasicNeuronProperties* bnProps = dynamic_cast<BasicNeuronProperties*>(neuronProps); float synConst = bnProps->GetSynapseConst(); props.AddParam((AmTimeInt)index); props.AddParam(synConst); return props;}void BasicNeuron::MakeLookupTables(){ FunctionLookup* fl = Network::GetNetworkRef()->GetFunctionLookup(); TableProperties t0 = GetTableProps(0); TableProperties t1 = GetTableProps(1); LOGGER(6, "Making lookup tables") pspLookup = fl->MakeLookupTable(t0); dPspLookup = fl->MakeLookupTable(t1); LOGGER(6, "Lookups made") LOGGER(6, "Filling lookup tables") float calcTm = 0.0; for (unsigned int i=0; i<pspLSize; ++i) { calcTm = (float(i) * pspStepSize); PspKernel(calcTm, &pspLookup[i]); } for (unsigned int i=0; i<pspLSize; ++i) { calcTm = (float(i) * pspStepSize); DPspKernel(calcTm, &dPspLookup[i]); } ScaleFunctionLookups();}void BasicNeuron::PspKernel(float calcTime, float* pspElement){ // Model the PSP as Ep = ( t/( Ts^2 ) ) * exp[ -t / Ts ] float term1 = 0.0, term2 = 0.0, expTerm = 0.0, convCalcTime; BasicNeuronProperties* bnProps = dynamic_cast<BasicNeuronProperties*>(neuronProps); float synConst = bnProps->GetSynapseConst(); // convert time from microseconds to milliseconds convCalcTime = calcTime*0.001; term1 = (convCalcTime/(pow(synConst, 2))); expTerm = -convCalcTime/synConst; term2 = exp(expTerm); *pspElement = term1 * term2;}void BasicNeuron::DPspKernel(float calcTime, float* dPspElement){ float tempVar, convCalcTime; // convert time from microseconds to milliseconds convCalcTime = calcTime*0.001; BasicNeuronProperties* bnProps = dynamic_cast<BasicNeuronProperties*>(neuronProps); float synConst = bnProps->GetSynapseConst(); tempVar = exp(-convCalcTime/synConst)/(pow(synConst, 2)); tempVar = tempVar - (convCalcTime/(pow(synConst, 3))*exp(-convCalcTime/synConst)); // Divide the result by 1000 so that it has units of mV/us (converted from // mV/ms). *dPspElement = tempVar*0.001;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -