Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

network.h

00001 /***************************************************************************
00002                           network.h  -  description
00003                              -------------------
00004     copyright            : (C) 2001, 2002 by Matt Grover
00005     email                : mgrover@amygdala.org
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #ifndef NETWORK_H
00018 #define NETWORK_H
00019 
00020 using namespace std;
00021 
00022 #include <amygdala/types.h>
00023 // check for g++ version 3.0.0 or higher
00024 #if GCC_VERSION >= 30000
00025     #include <ext/hash_map>
00026 #else
00027     #include <hash_map>
00028 #endif
00029 #include <string>
00030 #include <queue>
00031 #include <amygdala/mpspikeinput.h>
00032 
00033 
00034 enum NEvent { NOACTION, RMSPIKE, SPIKE, INPUTSPIKE, RESPIKE };
00035 class Neuron;
00036 class FunctionLookup;
00037 class Layer;
00038 class SpikeInput;
00039 class Synapse;
00040 
00041 
00063 class Network {
00064 public:
00065     //friend void Neuron::SendSpike(AmTimeInt& now);
00066     friend class Neuron;
00067     friend void MpSpikeInput::ReadInputBuffer();
00068 
00069     Network();
00070     virtual ~Network();
00071 
00078     void ScheduleNEvent(NEvent eventType,
00079                         AmTimeInt eventTime,
00080                         Neuron* reqNrn);
00087     void ScheduleNEvent(NEvent eventType,
00088                         AmTimeInt eventTime,
00089                         AmIdInt reqNrnId);
00090 
00096     Neuron* AddNeuron(NeuronRole nRole, AmIdInt nId);
00097 
00104     Neuron* AddNeuron(NeuronRole nRole, Neuron* nrn);
00105 
00113     bool ConnectNeurons(AmIdInt preSynapticNeuron,
00114                         AmIdInt postSynapticNeuron,
00115                         float weight,
00116                         AmTimeInt delay=0);
00117 
00125     bool ConnectNeurons(Neuron* preSynapticNeuron,
00126                         Neuron* postSynapticNeuron,
00127                         float weight,
00128                         AmTimeInt delay=0);
00129 
00138     void Run(AmTimeInt maxRunTime);
00139 
00141     int Size() { return net.size(); }
00142 
00144     int LayerCount() { return layers.size(); }
00145 
00148     typedef hash_map<AmIdInt, Neuron*>::const_iterator const_iterator;
00149 
00151     const_iterator begin() const { return net.begin(); }
00152 
00154     const_iterator end() const { return net.end(); }
00155 
00158     typedef hash_map<unsigned int, Layer*>::iterator layer_iterator;
00159 
00161     layer_iterator layer_begin() { return layers.begin(); }
00162 
00164     layer_iterator layer_end() { return layers.end(); }
00165 
00169     void AddLayer(Layer* newLayer);
00170 
00172     AmIdInt MaxNeuronId() { return (nextNeuronId - 1); }
00173 
00175     bool Layered() { return isLayered; }
00176 
00181     static void SetTimeStepSize(AmTimeInt stepSize);
00182 
00184     static AmTimeInt TimeStepSize() { return simStepSize; }
00185 
00187     static AmTimeInt SimTime() { return simTime; }
00188 
00192     Neuron* GetNeuron(AmIdInt nId) { return net[nId]; }
00193 
00195     SpikeInput* GetSpikeInput() { return spikeInput; }
00196 
00204     void SetSpikeInput(SpikeInput* sIn);
00205 
00207     bool StreamingInput() { return streamingInput; }
00208 
00213     void StreamingInput(bool streaming) { streamingInput = streaming; }
00214 
00216     static void ResetSimTime();
00217 
00220     void SetTrainingMode(bool tMode);
00221 
00223     bool GetTrainingMode() const { return trainingMode; }
00224 
00226     Layer * GetLayer(AmIdInt layerId);
00227 
00232     void EnableSpikeBatching() { spikeDelaysOn = true; }
00233 
00234 protected:
00244     void ScheduleSpikeDelay(vector<Synapse*>& axon);
00245 
00249     virtual void IncrementSimTime();
00250 
00251     int pspLSize;                   // Size of lookup tables
00252     int pspLRes;                    // Lookup table timestep resolution
00253     static AmTimeInt simStepSize;
00254 
00255     int netSize;
00256     bool streamingInput;
00257 
00258     AmIdInt nextNeuronId;
00259     unsigned int nextLayerId;
00260 
00261     FunctionLookup* functionRef;    // Container for lookup tables
00262     SpikeInput* spikeInput;
00263 
00264     hash_map<AmIdInt, Neuron*> net;     // Neurons that make up net. Key is neuron ID.
00265 
00266     hash_map<unsigned int, Layer*> layers; // layer container
00267 
00272     struct SpikeRequest {
00273         AmTimeInt spikeTime;     // Desired time of spike
00274         AmTimeInt requestTime;   // Time SpikeRequest was entered in queue
00275         unsigned int requestOrder;  // Entry number within a given time step.
00276         Neuron* requestor;          // Neuron scheduling spike
00277         // operator< overloaded to make the priority_queue happy
00278         bool operator<(const SpikeRequest& sr) const
00279         {
00280             if(spikeTime != sr.spikeTime) {
00281                 return spikeTime>sr.spikeTime;
00282             }
00283             else if(requestTime != sr.requestTime) {
00284                 return requestTime>sr.requestTime;
00285             }
00286             else {
00287                 return requestOrder<sr.requestOrder;
00288             }
00289         }
00290     };
00291 
00292     priority_queue<SpikeRequest> eventQ;    // Main event queue
00293     priority_queue<SpikeRequest> inputQ;    // Queue of inputs into network
00294     vector< vector<Synapse*> > delayedSpikeQ;
00295     AmTimeInt currSpikeDelayOffset;
00296     AmTimeInt maxOffset;
00297     bool spikeDelaysOn;
00298     AmTimeInt maxSpikeDelay;
00299     Synapse* maxSpikeDelaySyn;
00300     static AmTimeInt simTime;               // Current simulation time
00301     static unsigned int runCount;           // number of Network objects calling Run()
00302     unsigned int spikeBatchCount;
00303 
00304     inline void IncrementDelayOffset();
00305 
00306 private:
00310     void SendDelayedSpikes();
00311 
00313     void SetDefaults();
00314 
00316     void InitializeDelayedSpikeQ();
00317 
00318     unsigned int eventRequestCount;         // Counter for SpikeRequest.requestOrder
00319     bool isLayered;
00320     bool trainingMode;
00321 };
00322 
00323 #endif

Generated on Wed Sep 4 02:30:35 2002 for Amygdala by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002