?? lsmtopology.cpp
字號:
/*************************************************************************** lsmtopology.cpp - description ------------------- begin : Wed Mar 30 2005 copyright : (C) 2005 by Rudiger Koch email : rkoch@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 "lsmtopology.h"#include "spikeinput.h"#include "factory.h"#include "physicalproperties.h"#include "neuronproperties.h"#include "neuron.h"#include "spikingneuron.h"#include "inputneuron.h"#include "nconnector.h"#include "synapse.h"#include "synapseproperties.h"#include "utilities.h"#include "logging.h"#include <stdexcept>#include <cstdlib>namespace Amygdala {using namespace std;LSMTopology::LSMTopology(string name) : Topology(name), X(0), Y(0), Z(0), lastInX(0), lastInY(0), lastInZ(0), lastInSide(0), lastOutX(0), lastOutY(0), lastOutZ(0){}LSMTopology::~LSMTopology(){}Topology * LSMTopology::MakeInput(SpikeInput * sInput, unsigned int iNeurons){ if( X==0 || Y==0 || Z==0) throw runtime_error("No cube defined yet. Call MakeCube before attempting to create Input"); //TFactory * lsmInput = dynamic_cast<TFactory*> (Factory::GetRegistry().GetFactory("LSMTopology::Input")); //if(!lsmInput) throw runtime_error("No LSMTopology::Input factory registered"); TopologyFactory<LSMTopology::Input> lsmInput; Input* in = lsmInput("LSM Input"); input.push_back(in); // Move the code that used to be in Input::MakeInput() to here since more than one Input // object is now allowed. Since we have to keep track of where input neurons have been added // previously, it will be easier to do that here. //in->MakeInput(sInput, X, Y, Z, iNeurons); LOGGER(3, "Making Inputs"); unsigned int neuronCounter = 1; unsigned int inputLocs = 2*X*Z + 2*Y*Z; unsigned int totInputs = 0; for (unsigned int i=0; i<input.size(); ++i) { totInputs += input[i]->size(); } totInputs += iNeurons; if(totInputs > inputLocs) throw runtime_error("Insufficient space for InputNeurons. Consider making the cube larger"); if (lastInSide == 0) { int y=-1; // distribute the InputNeurons alongside at the X-Z side of the cube (y == -1) for(int x=lastInX; x < X; x++){ for(int z=lastInZ; z < Z; z++){ InputNeuron * inNrn = in->MakeInputNeuron(x, y, z); sInput->AddNeuron(inNrn); lastInZ = z; if(++neuronCounter > iNeurons) return in; } lastInZ = 0; lastInX = x; } lastInX = 0; lastInZ = 0; lastInSide = 1; } if (lastInSide == 1) { int y=Y; // distribute the InputNeurons alongside at the X-Z side of the cube (y == Y) for(int x=lastInX; x < X; x++){ for(int z=lastInZ; z < Z; z++){ InputNeuron * inNrn = in->MakeInputNeuron(x, y, z); sInput->AddNeuron(inNrn); lastInZ = z; if(++neuronCounter > iNeurons) return in; } lastInZ = 0; lastInX = x; } lastInX = 0; lastInZ = 0; lastInSide = 2; } if (lastInSide == 2) { // if there are still more input neurons // distribute them alongside at the X-Y side of the cube (z == -1) int z=-1; for(int x=lastInX; x < X; x++){ for(int y=lastInY; y < Y; y++){ InputNeuron * inNrn = in->MakeInputNeuron(x, y, z); sInput->AddNeuron(inNrn); lastInY = y; if(++neuronCounter > iNeurons) return in; } lastInY = 0; lastInX = x; } lastInX = 0; lastInSide = 3; } if (lastInSide == 3) { // if there are still more input neurons // distribute them alongside at the X-Y side of the cube (z == Z) int z=Z; for(int x=lastInX; x < X; x++){ for(int y=lastInY; y < Y; y++){ InputNeuron * inNrn = in->MakeInputNeuron(x, y, z); sInput->AddNeuron(inNrn); lastInY = y; if(++neuronCounter > iNeurons) return in; } lastInY = 0; lastInX = x; } lastInX = 0; lastInSide = 4; } return in;}Topology * LSMTopology::MakeReadout(const string & nType, unsigned int oNeurons){ if( X==0 || Y==0 || Z==0) throw runtime_error("No cube defined yet. Call MakeCube before attempting to create Output"); TFactory * lsmOutput = dynamic_cast<TFactory*> (Factory::GetRegistry().GetFactory("LSMTopology::Output")); if(!lsmOutput) throw runtime_error("No LSMTopology::Output factory registered"); Output* out = dynamic_cast<Output*> (lsmOutput->MakeTopology("LSM Output")); output.push_back(out); // Move the code that used to be in Output::MakeReadout() to here since more than one Output // object is now allowed. Since we have to keep track of where neurons have been added // previously, it will be easier to do that here. //out->MakeReadout(nType, X, Y, oNeurons); LOGGER(3, "Making Outputs"); unsigned int neuronCounter = 1; NFactory * nf = dynamic_cast<NFactory*> (Factory::GetRegistry().GetFactory(nType)); if (nf == NULL) throw runtime_error("No neuron type " + nType + " registered!"); NeuronProperties * nProps = nf->MakeNeuronProperties(true); PhysicalProperties * pProps = nProps->GetPhysicalProps(); // distribute the OutputNeurons alongside at the Y-Z side of the cube starting at X+1, 0, 0 for (int z=lastOutZ; true; z++){ for (int y = lastOutY; y < Y; y++){ pProps->SetPosition(X + 1, y, z); Neuron * n = nf->MakeNeuron(Network::GetNetworkRef()->GetNewNeuronId(), nProps, out); OutputManager::AddNeuronToGroup(n, OUTPUTGROUP); LOGGER(4, "Output neuron at " << X+1 << ", " << y << ", " << z); lastOutY++; if(++neuronCounter > oNeurons) return out; } lastOutY=0; lastOutZ++; } return out;}Topology * LSMTopology::MakeReadout(NFactory* nf, NeuronProperties* np, unsigned int oNeurons){ if( X==0 || Y==0 || Z==0) throw runtime_error("No cube defined yet. Call MakeCube before attempting to create Output"); TFactory * lsmOutput = dynamic_cast<TFactory*> (Factory::GetRegistry().GetFactory("LSMTopology::Output")); if(!lsmOutput) throw runtime_error("No LSMTopology::Output factory registered"); Output* out = dynamic_cast<Output*> (lsmOutput->MakeTopology("LSM Output")); output.push_back(out); // Move the code that used to be in Output::MakeReadout() to here since more than one Output // object is now allowed. Since we have to keep track of where neurons have been added // previously, it will be easier to do that here. //out->MakeReadout(nType, X, Y, oNeurons); LOGGER(3, "Making Outputs"); unsigned int neuronCounter = 1; /*NFactory * nf = dynamic_cast<NFactory*> (Factory::GetRegistry().GetFactory(nType)); if (nf == NULL) throw runtime_error("No neuron type " + nType + " registered!");*/ //NeuronProperties * nProps = nf->MakeNeuronProperties(true); PhysicalProperties * pProps = np->GetPhysicalProps(); // distribute the OutputNeurons alongside at the Y-Z side of the cube starting at X+1, 0, 0 for (int z=lastOutZ; true; z++){ for (int y = lastOutY; y < Y; y++){ pProps->SetPosition(X + 1, y, z); Neuron * n = nf->MakeNeuron(Network::GetNetworkRef()->GetNewNeuronId(), np, out); OutputManager::AddNeuronToGroup(n, OUTPUTGROUP); LOGGER(4, "Output neuron at " << X+1 << ", " << y << ", " << z); lastOutY++; if(++neuronCounter > oNeurons) return out; } lastOutY=0; lastOutZ++; } return out;}void LSMTopology::MakeCube(const string & nType, unsigned int lx, unsigned int ly, unsigned int lz){ X=lx; Y=ly; Z=lz; LOGGER(1, "Making Cube of size " << X << ", " << Y << ", " << Z); NFactory * nf = dynamic_cast<NFactory*> (Factory::GetRegistry().GetFactory(nType)); if (nf == NULL) throw runtime_error("No neuron type " + nType + " registered!"); NeuronProperties * nProps = nf->MakeNeuronProperties(true); PhysicalProperties * pProps = nProps->GetPhysicalProps(); for (int x = 0; x < X; x++){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -