📄 spikeloop.cpp
字号:
/*************************************************************************** spikeloop.cpp - description ------------------- begin : Mon Feb 11 2002 copyright : (C) 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.h>#include <stdlib.h>#include <string>#include <vector>#include <amygdala/basicneuron.h>#include <amygdala/fastneuron.h>#include <amygdala/network.h>#include <amygdala/netloader.h>#include <amygdala/layer.h>#include <amygdala/types.h>#include <amygdala/statisticsoutput.h>#include "spikeloop.h"SpikeLoop::SpikeLoop(int layerSize, int numLayers): poolSize(layerSize), numLayers(numLayers){ sigma = 0.0001; gnuplot = false;}SpikeLoop::~SpikeLoop(){}void SpikeLoop::Run(AmTimeInt runTime){ cout << "Starting spikeloop...\n"; cout << "Building the network.\n"; BuildNetwork(); // Turn on output for the output layer //Neuron::CaptureOutput( OUTPUT_LAYERS ); // Turn on output for ALL neurons. This is used to create a complete log // using StatisticsOutput. If you don't want this turn on output only for // OUTPUT_LAYERS Neuron::CaptureOutput( ALL ); // Schedule the input for (int i=1; i<=poolSize; i++) { //net->ScheduleNEvent(INPUTSPIKE, 1000 + (i*500), i); net->ScheduleNEvent(INPUTSPIKE, 1000, i); } net->Run(runTime*1000); delete net; cout << "Runtime: " << Network::SimTime()/1000 << endl; cout << "Exiting." << endl;}void SpikeLoop::BuildNetwork(){ unsigned int startId = 1, layerCount = 1; LayerConstants layerConst; net = new Network(); Layer* tmpLayer; NetLoader* netLoad = new NetLoader(net); // Set up the constants struct layerConst.type = INPUTLAYER; layerConst.layerId = layerCount; layerConst.learningConst = 1e-3; layerConst.membraneTimeConst = 2.0; layerConst.synapticTimeConst = 7.0; layerConst.restPtnl = 0.0; layerConst.thresholdPtnl = 5.0; net->SetTrainingMode(false); // Build the layers with NetworkLoader. Layers are automatically // added to testNet // Build the input layer tmpLayer = netLoad->BuildLayer(poolSize, startId, layerConst, "BasicNeuron"); startId += poolSize; tmpLayer->LayerName("Input Layer"); layer.push_back(tmpLayer); // Build the hidden layers layerConst.type = HIDDENLAYER; while (layerCount++ < numLayers + 1) { layerConst.layerId = layerCount; tmpLayer = netLoad->BuildLayer(poolSize, startId, layerConst, "BasicNeuron"); startId += poolSize; layer.push_back(tmpLayer); } // Build the output layer layerConst.type = OUTPUTLAYER; layerConst.layerId = ++layerCount; tmpLayer = netLoad->BuildLayer(poolSize, startId, layerConst, "BasicNeuron"); startId += poolSize; layer.push_back(tmpLayer); // set up the connection parameters GaussConnectType conParms; conParms.meanWeight = 1.4/(float)poolSize; conParms.stdDev = sigma; conParms.pctConnect = 100.0; // Fully connected for (uint i=0; i<layer.size() - 1; i++) { layer[i]->SetSynapticDelay(10000); layer[i]->ConnectLayers(layer[i+1], conParms); } // Connect the last layer to the first hidden layer (since input layers // cannot receive connections yet). layer[layer.size() - 1]->SetSynapticDelay(10000); layer[layer.size() - 1]->ConnectLayers(layer[1], conParms); // create a complete log of all spikes if gnuplot mode is turned on if (gnuplot) { StatisticsOutput *spikeOut = new StatisticsOutput(); spikeOut->LogSpikeTimes(string("spikes.log")); Neuron::SetSpikeOutput(spikeOut); cout << "Logging output to spikes.log\n"; cout << "Use the command 'gnuplot spikes.gnuplot' to generate spikeloop.png\n"; cout << "Run 'gimp spikeloop.png' to view the png file.\n"; } delete netLoad;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -