📄 pacmanspikeinput.cpp
字号:
/*************************************************************************** pacmanspikeinput.cpp - description ------------------- begin : Tue Nov 6 2001 copyright : (C) 2001 by Rudiger Koch email : rkoch@rkoch.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 <string.h>#include <math.h>#include "pacmanspikeinput.h"#include "pacman.h"#include "amygdala/neuron.h"PacmanSpikeInput::PacmanSpikeInput(Network *network, Pacman* pacman): SpikeInput(network), timingConst(10), pacmanTimestep(300000) { this->pacman = pacman; lastMoveTime = 0; feeling = new Senses; for (unsigned int i=0; i<14; i++) lastSpike[i] = 0;}PacmanSpikeInput::~PacmanSpikeInput(){}void PacmanSpikeInput::ReadInputBuffer(){ Network *network = pacman->getNetwork(); AmTimeInt simTime = network->SimTime();// if(simTime == 0) return; // every 0.3 sec simTime we make a new step if(simTime - lastMoveTime < pacmanTimestep) return; memcpy((void*)feeling, pacman->step(), sizeof(Senses)); lastMoveTime = simTime; // After the step we calculate the new spike frequency // We add .1 to every feeling to make sure we're not dividing by zero timeDiff[0] = (AmTimeInt) (pacmanTimestep / (feeling->upGood + .1)); timeDiff[1] = (AmTimeInt) (pacmanTimestep / (feeling->downGood + .1)); timeDiff[2] = (AmTimeInt) (pacmanTimestep / (feeling->leftGood + .1)); timeDiff[3] = (AmTimeInt) (pacmanTimestep / (feeling->rightGood + .1)); timeDiff[4] = (AmTimeInt) (pacmanTimestep / (feeling->upBad + .1)); timeDiff[5] = (AmTimeInt) (pacmanTimestep / (feeling->downBad + .1)); timeDiff[6] = (AmTimeInt) (pacmanTimestep / (feeling->leftBad + .1)); timeDiff[7] = (AmTimeInt) (pacmanTimestep / (feeling->rightBad + .1)); timeDiff[8] = (AmTimeInt) (pacmanTimestep / (feeling->pain + .1)); timeDiff[9] = (AmTimeInt) (pacmanTimestep / (feeling->pleasure + .1)); timeDiff[10] = (AmTimeInt) (pacmanTimestep / (feeling->upTouch + .1)); timeDiff[11] = (AmTimeInt) (pacmanTimestep / (feeling->downTouch + .1)); timeDiff[12] = (AmTimeInt) (pacmanTimestep / (feeling->leftTouch + .1)); timeDiff[13] = (AmTimeInt) (pacmanTimestep / (feeling->rightTouch + .1)); for(int i=0; i<14; i++) timeDiff[i] /= timingConst; // We feed the spikes into Amygdala as a rate code. The frequency is higher // if the particualar feeling is stronger for (unsigned int i=0; i<14; i++){ for(AmTimeInt t = simTime; t - simTime < pacmanTimestep; t += timeDiff[i]){ network->ScheduleNEvent(INPUTSPIKE, t, inputNeurons[i]); } }}void PacmanSpikeInput::SetInputNeurons(vector <AmIdInt> in){ inputNeurons = in;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -