📄 pacmanspikeoutput.cpp
字号:
/*************************************************************************** pacmanspikeoutput.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 "pacmanspikeoutput.h"#include <math.h>PacmanSpikeOutput::PacmanSpikeOutput(){ for(int i=0; i<4; i++) spikeCounter[i] = 0; plotfile = fopen("spikes.log", "w");}PacmanSpikeOutput::~PacmanSpikeOutput(){ fclose (plotfile);}// This gets called by Amygdala every time an output neuron fires if// OUTPUT_NEURONS is set. If ALL is set it gets called every time a// neuron fires....void PacmanSpikeOutput::OutputEvent(AmIdInt neuronId, AmTimeInt eventTime){// fprintf(plotfile, "%d %d\n", neuronId, eventTime); for(unsigned int i=0; i<outputNeurons.size(); i++){ // ..... which is why we test this. This is only necessary if we want // to log all spikes to create plots. if(outputNeurons[i]->GetID() == neuronId) { // figure out the direction this spike points to and add it // Later PacmanSpikeOutput::getDirection() will pick up the // results unsigned int counterIndex = (unsigned int)(i/2); // For each direction we have 2 emphasis, positive... if(i % 2) spikeCounter[counterIndex]++; // ... and negative else spikeCounter[counterIndex]--; break; } }}void PacmanSpikeOutput::SetOutputNeurons(vector <Neuron*> oNeurons){ outputNeurons = oNeurons;}void PacmanSpikeOutput::OutputCache(){}// This one looks complicated. But it simply figures out in which direction the NN// decided to go. The highest difference counts (right-left) or (up-down)int PacmanSpikeOutput::getDirection(){ int sc[4]; for(int i=0; i<4; i++) { printf(" %d", spikeCounter[i]); sc[i] = spikeCounter[i]; spikeCounter[i] = 0; } putchar('\n'); if(abs(sc[0] - sc[1]) == abs(sc[2] - sc[3])) { return ' '; // nothing } if(abs(sc[0] - sc[1]) < abs(sc[2] - sc[3])) { if(sc[2] == sc[3]) return ' '; // nothing if(sc[2] > sc[3]) return 'O'; // left else return 'P'; // right } else { if(sc[0] == sc[1]) return ' '; // nothing if(sc[0] > sc[1]) return 'Q'; // up else return 'A'; // down } return ' '; // nothing (we should never get here)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -