00001 /*************************************************************************** 00002 * SpikeStream Simulation * 00003 * Copyright (C) 2007 by David Gamez * 00004 * david@davidgamez.eu * 00005 * Version 0.1 * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 ***************************************************************************/ 00022 00023 #ifndef SYNAPSE_H 00024 #define SYNAPSE_H 00025 00026 //SpikeStream includes 00027 #include "Neuron.h" 00028 #include "SimulationClock.h" 00029 #include "GlobalVariables.h" 00030 00031 00032 /*! The minimum double weight for a synapse. */ 00033 #define MIN_DOUBLE_WEIGHT -1.0 00034 00035 /*! The maximum double weight for a synapse. */ 00036 #define MAX_DOUBLE_WEIGHT 1.0 00037 00038 /*! The minimum short weight for a synapse. */ 00039 #define MIN_SHORT_WEIGHT -127 00040 00041 /*! The maximum short weight for a synapse. */ 00042 #define MAX_SHORT_WEIGHT 127 00043 00044 00045 //---------------------------- Synapse -------------------------------------- 00046 /*! Base class inherited by all synapse classes This base class handles all 00047 the simulation related stuff. The modelling aspects, such as STDP learning 00048 etc. should be implemented by classes inheriting from this class. 00049 00050 NOTE getWeight() and getShortWeight() are virtual because there may need 00051 to be some retrospective calculations done on the weight to get its 00052 current value. */ 00053 00054 /* FIXME IT WOULD BE MUCH BETTER TO HOLD THE SIMULATION CLOCK AS A STATIC 00055 REFERENCE, BUT WHEN THIS IS SET USING Synapse::setSimulationClock() IT 00056 DOES NOT CHANGE THE ADDRESS IN CLASSES INHERITING FROM SYNAPSE. IT WOULD 00057 BE GOOD IF THIS COULD BE SORTED OUT. */ 00058 //--------------------------------------------------------------------------- 00059 00060 class Synapse { 00061 00062 public: 00063 Synapse(); 00064 virtual ~Synapse(); 00065 00066 00067 /*-------------------------------------------------------------------------------- 00068 ------ Methods that subclasses of Synapse may or have to implement ------ 00069 --------------------------------------------------------------------------------*/ 00070 00071 /*! Should return a descriptive name for the synapse. This is sometimes 00072 useful for debugging class loading. */ 00073 virtual const string* getDescription() = 0; 00074 00075 /* Should return the weight as a short between MIN_SHORT_WEIGHT and MAX_SHORT_WEIGHT. 00076 This is a virtual method because some implementations may need the state of 00077 the weight to be calculated retrospectively. */ 00078 virtual short getShortWeight() = 0; 00079 00080 /*! Should return the weight as a double between MIN_DOUBLE_WEIGHT and 00081 MAX_DOUBLE_WEIGHT. This is a virtual method because some implementations 00082 may need the state of the weight to be calculated retrospectively. */ 00083 virtual double getWeight() = 0; 00084 00085 /*! Called when the parameters of the synapse have changed. 00086 The parameters of the synapses are held as references to parameter 00087 maps and when these are reloaded this method is called. */ 00088 virtual bool parametersChanged() = 0; 00089 00090 /*! Called when a spike is routed to this synapse. In event based simulation 00091 the synapse should be updated by this method. */ 00092 virtual void processSpike() = 0; 00093 00094 /*! Called to update synapse class when all synapses are being updated at each 00095 time step. This method is never called during event based simulation, when 00096 the synapse class should be updated whenever it processes a spike. */ 00097 virtual void calculateFinalState() = 0; 00098 00099 /*! This method returns an string containing an XML description of the variables 00100 that are available for monitoring within this class. Overload this method and 00101 getMonitoringData() if you want to send monitoring information back to the main 00102 application. This will enable you to view a graph of the weight, 00103 for example. */ 00104 virtual string getMonitoringInfo(); 00105 00106 /*! Returns a monitor data struct (defined in GlobalVariables.h) containing the 00107 data that is being monitored. This returned data must match that defined in 00108 the string returned by getMonitoringInfo(). */ 00109 virtual MonitorData* getMonitoringData(); 00110 00111 00112 /*---------------------------------------------------------------------- 00113 ------ Public methods implemented by Synapse class ------ 00114 ----------------------------------------------------------------------*/ 00115 unsigned int getPresynapticNeuronID(); 00116 void print(); 00117 void setWeight(double weight); 00118 00119 //Make SpikeStreamSimulation a friend to enable the loading of data 00120 friend class SpikeStreamSimulation; 00121 00122 00123 protected: 00124 //============================= VARIABLES ============================= 00125 /*! Holds a reference to the neuron that this synapse is connected to. 00126 This will be a class that inherits from the abstract Neuron class.*/ 00127 Neuron *postSynapticNeuron; 00128 00129 /*! Holds the preSynapticNeuronID to enable the neuron to change its 00130 weight by accessing the synapse map.*/ 00131 unsigned int preSynapticNeuronID; 00132 00133 /*! The weight of the synapse. Stored as a double so that it can be used 00134 without casting in calculations.*/ 00135 double weight; 00136 00137 /*! Reference to the simulation clock.*/ 00138 //FIXME THIS WOULD BE BETTER STATIC, BUT HAD DYNAMIC LOADING PROBLEMS 00139 SimulationClock* simulationClock; 00140 00141 /*! Reference to the map containing the parameters for each connection 00142 group.*/ 00143 map<string, double>* parameterMap; 00144 00145 /*! Holds the monitoring data for the neuron.*/ 00146 MonitorData monitorData; 00147 00148 00149 private: 00150 //============================ METHODS ================================ 00151 void setParameterMapReference(map<string, double>* paramMap); 00152 void setPostSynapticNeuron(Neuron *neuron); 00153 void setPreSynapticNeuronID(unsigned int preSynNeurID); 00154 void setSimulationClock(SimulationClock* simClock); 00155 00156 }; 00157 00158 00159 #endif //SYNAPSE_H 00160
1.4.4