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

📄 euler.cpp

📁 amygdata的神经网络算法源代码
💻 CPP
字号:
/***************************************************************************                          euler.cpp  -  description                             -------------------    copyright            : (C) 2001, 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.                                   * *                                                                         * ***************************************************************************/#include <iostream>#include <cmath>#include "euler.h"#include "logging.h"using namespace std;using namespace Amygdala;Euler::Euler(unsigned int step,            unsigned int min,            unsigned int max,            float esynapticTimeConst,            float isynapticTimeConst,            float membraneTimeConst):    stepSize(step),    plotMin(min),    plotMax(max){    if (esynapticTimeConst == 0) {        tauSe = 2000.0;    }    else {        tauSe = esynapticTimeConst * 1000.0;    }    if (isynapticTimeConst == 0) {        tauSi = 4000.0;    }    else {        tauSi = isynapticTimeConst * 1000.0;    }    if (membraneTimeConst == 0) {        tauM = 10000.0;    }    else {        tauM = membraneTimeConst * 1000.0;    }    if (plotMax <= plotMin) {        cerr << "Plot min and max invalid.\n";        return;    }    plotSize = (plotMax - plotMin)/stepSize;    plotData = new float[plotSize];    plotDeriv = new float[plotSize];    	    unsigned int i = 0;    for (i = 0; i < plotSize; i++) {        plotData[i] = 0.0;        plotDeriv[i] = 0.0;    }}Euler::~Euler(){}/*void Euler::GenPlot(){    unsigned int i;    lastV = 0.0;	// initial condition    lastSlope = 0.0;    time = 0;    // Get the initial slope    //AlphaExcite();    AlphaInhibit();    lastSlope = currSlope;    for (i=0; i< plotSize; i++) {        //AlphaExcite();        AlphaInhibit();        plotData[i] = currV;        // display value for every 500 iterations        if (drem(i, 1000) == 0.0) {            cout << currV << endl;        }        lastV = currV;        lastSlope = currSlope;        time = time + stepSize;    }}*/void Euler::GenExcitatoryTable(int resolution, float* tbl, float* derivTbl){	LOGGER(4, "Generating Excitatory lookup tables")    unsigned int i;    int tblStep = 0, counter = 0;    lastV = 0.0;	// initial condition    lastSlope = 0.0;    time = 0;    tblStep = resolution / stepSize;    // Make sure the table is empty    for (i=0; i < plotSize; i++) {        plotData[i] = 0.0;        plotDeriv[i] = 0.0;    }    // Get the initial slope    AlphaExcite();    lastSlope = currSlope;    for (i=0; i< plotSize; i++) {        AlphaExcite();        plotData[i] = currV;        plotDeriv[i] = currSlope;        lastV = currV;        lastSlope = currSlope;        time = time + stepSize;    }    LOGGER(5, "Copying " << plotSize << " elements to tables")    // Copy the tables    for (i=0; i < plotSize; i+=tblStep) {        tbl[counter] = plotData[i];        //cout << "plotData[" << i << "] = " << plotData[i] << endl;        derivTbl[counter] = plotDeriv[i];        counter++;    }}void Euler::GenInhibitoryTable(int resolution, float* tbl, float* derivTbl){	LOGGER(4, "Generating Inhibitory lookup tables")    unsigned int i;    int tblStep = 0, counter = 0;    lastV = 0.0;	// initial condition    lastSlope = 0.0;    time = 0;    tblStep = resolution / stepSize;    // Make sure the table is empty    for (i=0; i < plotSize; i++) {        plotData[i] = 0.0;        plotDeriv[i] = 0.0;    }    // Get the initial slope    AlphaInhibit();    lastSlope = currSlope;    for (i=0; i< plotSize; i++) {        AlphaInhibit();        plotData[i] = currV;        plotDeriv[i] = currSlope;        lastV = currV;        lastSlope = currSlope;        time = time + stepSize;    }    LOGGER(5, "Copying " << (plotSize/tblStep) << " elements to tables")    // Copy the tables    for (i=0; i < plotSize; i+=tblStep) {        tbl[counter] = plotData[i];        derivTbl[counter] = plotDeriv[i];        counter++;    }}void Euler::AlphaExcite(){	float dV = 0.0, I = 0.0;		// find new V value	currV = lastV + float(stepSize)*(lastSlope);	// calculate new derivative	I = ( exp( -(float(time) + float(stepSize) )/tauSe)/tauSe );	dV = I - ( currV/tauM );	currSlope = dV;}void Euler::AlphaInhibit(){	float dV = 0.0, I = 0.0;	// find new V value	currV = lastV + float(stepSize)*(lastSlope);	// calculate new derivative	I = ( (float(time) + float(stepSize)) * exp( -(float(time) +	        float(stepSize) )/tauSi)/(tauSi * tauSi) );	dV = I - ( currV/tauM );	currSlope = dV;}

⌨️ 快捷键说明

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