⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alphaneuron.cpp

📁 amygdata的神经网络算法源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          alphaneuron.cpp  -  description                             -------------------    copyright            : (C) 2001 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 <cmath>#include "alphaneuron.h"#include "euler.h"#include "network.h"#include "functionlookup.h"#include "dendrite.h"#include "logging.h"#include "utilities.h"#include <iostream>using namespace std;using namespace Amygdala;unsigned int AlphaNeuron::pspStepSize = 0;unsigned int AlphaNeuron::pspLSize = 0;///////////////////////////////////////////////////////// AlphaNeuronProperties/////////////////////////////////////////////////////AlphaNeuronProperties::AlphaNeuronProperties():	SpikingNeuronProperties(){}AlphaNeuronProperties::AlphaNeuronProperties(bool initializePhysicalProps):	SpikingNeuronProperties(initializePhysicalProps){}AlphaNeuronProperties::AlphaNeuronProperties(const AlphaNeuronProperties& rhs):	SpikingNeuronProperties(rhs){	memTimeConst = rhs.memTimeConst;	eSynTimeConst = rhs.eSynTimeConst;	iSynTimeConst = rhs.iSynTimeConst;}AlphaNeuronProperties::~AlphaNeuronProperties(){}AlphaNeuronProperties* AlphaNeuronProperties::Copy() const{	return new AlphaNeuronProperties(*this);}void AlphaNeuronProperties::SetProperty(string& name, string& value){    // Properties:    // memTimeConst    // eSynTimeConst    // iSynTimeConst    if (!name.compare("membraneTimeConst")) {        memTimeConst = atof(value.c_str());    }    else if (!name.compare("eSynapticTimeConst")) {        eSynTimeConst = atof(value.c_str());    }    else if (!name.compare("iSynapticTimeConst")) {        iSynTimeConst = atof(value.c_str());    }    else {        NeuronProperties::SetProperty(name, value);    }}map< string, string > AlphaNeuronProperties::GetPropertyMap() const{    map< string, string > propMap = NeuronProperties::GetPropertyMap();    propMap["membraneTimeConst"] = Utilities::ftostr(memTimeConst);    propMap["eSynapticTimeConst"] = Utilities::ftostr(eSynTimeConst);    propMap["iSynapticTimeConst"] = Utilities::ftostr(iSynTimeConst);        return propMap;}///////////////////////////////////////////////////////// AlphaNeuron/////////////////////////////////////////////////////AlphaNeuron::AlphaNeuron(AmIdInt neuronId, const AlphaNeuronProperties& neuronProps):    SpikingNeuron(neuronId, neuronProps),    histBeginIdx(0),    maxThreshCrs(0),    convergeRes(0){    epspLookup = 0;    edPspLookup = 0;    ipspLookup = 0;    idPspLookup = 0;        if (!pspStepSize) {	    Init();    }        InitLookup();}AlphaNeuron::~AlphaNeuron(){}void AlphaNeuron::Init(){	//pspStepSize = Network::TimeStepSize()/10;	pspStepSize = Network::TimeStepSize();	pspLSize = 100000/pspStepSize;		// 100ms / step size		LOGGER(3, "pspStepSize: " << pspStepSize << " pspLSize: " << pspLSize)}void AlphaNeuron::SetProperties(AlphaNeuronProperties* props){	delete neuronProps;	neuronProps = props->Copy();}void AlphaNeuron::SpikeCleanup(){	// reset inputHist vector	inputHist.clear();	histBeginIdx = 0;}void AlphaNeuron::ProcessInput(const AmTimeInt& inTime){    unsigned int i, iterate, converged, histSize, tblIndex;    AmTimeInt calcTime, funcTime;    float currState = 0.0;    float currDeriv = 0.0;    float funcWeight = 0.0;    float stateDelta = 0.0;    float threshCrs = 0.0;    float lstThreshCrs = 0.0;    InputHist tmpInput;    // If the neuron is within a refractory period,    if ( (inTime - spikeTime) <= refPeriod ) {        if (inTime > refPeriod) {	        dendrite->ResetTrigger();            return;        }    }    iterate = 1;    converged = 0;    calcTime = 0;    funcTime = 0;    histSize = 0;    if (!maxThreshCrs) {        maxThreshCrs = pspLSize * pspStepSize;        LOGGER(5, "maxThreshCrs = " << maxThreshCrs)        // find the convergence resolution (the resolution at which two values        // of threshCrs are considered to be identical) -- must be <= simStepSize        if (simStepSize > pspStepSize) {            if (pspStepSize > (simStepSize / 2.0)) {                convergeRes = pspStepSize;            }            else {                convergeRes = simStepSize / 2.0;            }        }        else {            convergeRes = simStepSize;        }    }    calcTime = inTime;    inputTime = inTime;    currTime = inTime;    float inWeightPos, inWeightNeg;    dendrite->GetStimulationLevel(inWeightPos, inWeightNeg);    /*if (trainingMode) {        //inWeight = inputHeader->SumQueue(true, synapseHist, inTime);        dendrite->GetStimulationLevel(inWeightPos, inWeightNeg);    }    else {        //inWeight = inputHeader->SumQueue(true);        dendrite->GetStimulationLevel(inWeightPos, inWeightNeg);    }*/    tmpInput.time = inTime;    if (inWeightPos) {        tmpInput.weight = inWeightPos;        inputHist.push_back(tmpInput);    }    if (inWeightNeg) {        tmpInput.weight = inWeightNeg;        inputHist.push_back(tmpInput);    }        histSize = inputHist.size();    //LOG_WEIGHT_HIST(6)        i = 0;    // Use Newton's method to determine if and when the spike will occur    /**************************************************************************    *    1) Determine the membrane potential (currState) at time (calcTime -    *       inTimeHist[i]) by summing the state of each inTimeHist[]    *       (use pspLookup).    *    2) Find the derivative of the function for calcTime (dPspLookup).    *    3) Calculate intercept with thresholdPtnl.    *    4) Set new calcTime to time of intercept.    *    5) Repeat until:    *        a) Two successive iterations result in no change in calcTime.    *            (Converges)    *        b) The derivative of the function becomes negative.    *            (Does not converge)    **************************************************************************/    LOGGER(6, "NEURON " << nId << " Starting main loop...")    lstThreshCrs = float(calcTime);    while (iterate) {        currState = 0.0;        currDeriv = 0.0;        Utilities::RoundTime(calcTime, pspStepSize);        LOGGER(6, "calcTime: " << calcTime)        for (i=histBeginIdx; i<histSize; i++) {            tmpInput = inputHist[i];            funcTime = calcTime - tmpInput.time;            funcWeight = tmpInput.weight;            LOGGER(6, "funcTime: " << funcTime << "\n\tfuncWeight: " << funcWeight)            tblIndex = (funcTime / pspStepSize);            LOGGER(6, "tblIndex for psp lookups: " << tblIndex)            if (tblIndex < pspLSize) {                if ( funcWeight > 0.0 ) {                    currState = currState + (funcWeight * (epspLookup[tblIndex]));                    currDeriv = currDeriv + (funcWeight * (edPspLookup[tblIndex]));                }                else {                    currState = currState + (funcWeight * (ipspLookup[tblIndex]));                    currDeriv = currDeriv + (funcWeight * (idPspLookup[tblIndex]));                }            }            else {                if (calcTime <= inTime)                    ++histBeginIdx;            }        }        LOGGER(6, "currState: " << currState << "\n\tcurrDerive: " << currDeriv)        if ( (currDeriv < 0.0) && (currState < 1.0) ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -