📄 neuron.h
字号:
* @return True if neuron sign is being enforced, * meaning that Neurons can only form inhibitory * or excitatory output connections, but not * both at the same time. False by default. */ static bool EnforceSign() { return enforceSign; } /** Get the multi-processing mode. * @return The run-mode of an Amygdala simulation. * Returns True if multi-processing mode (multi-threaded) * is in use. * @see Neuron::SetMPMode(). */ static bool GetMPMode() { return mpMode; } /** @return A pointer to the physical properties of this neuron */ PhysicalProperties * GetPhysicalProperties(); /** Get the class name. This is needed for xml tags. * This must be implemented in all derived classes. * @return The name of the class. * @see NetLoader::Save(), NetLoader::Load(). */ virtual const char* ClassId() = 0; /** Enable spike batching mode. Simply calling this * function enables spike batching and it cannot be turned off * once it has been enabled. Off by default. * If spike batching is enabled, then spike events are queued up * until the end of the time step and then each Neuron * receives all of its incoming spikes in one batch. This * can sometimes result in more efficient processing (depending on * how the child Neuron implements Neuron::InputSpike(). Under normal * operation, Neuron::InputSpike() is called every time a spike is * sent. Spike batching is always enabled if spike delays are being used. * @see Neuron::InputSpike(), Neuron::SendSpike(). */ static void EnableSpikeBatching(); /** Fill a lookup table and return * a pointer to the first element. Neuron::SetTableDimensions() * should be called first. * This is an internal function and should only be called * by FunctionLookup. This function will be made private or removed * completely for Amygdala 0.4. * @param index The index of the table to be initialized. * @return A pointer to the lookup table (an array of floats). */ virtual float* InitializeLookupTable(int index) = 0; /** This is an internal function and should only be called * by FunctionLookup. This function will be either removed * or made private for Amygdala 0.4. * @return An array containing any values used to generate * the lookup tables that were set at runtime. * @param index * @param numParams Number of unique parameters (variables) needed * to generate the lookup table associated with index. */ virtual float* GetTableParams(int index, int& numParams) = 0; /** Iterator for the synapses in the axon */ typedef vector<Synapse*>::iterator iterator; /** Const iterator for the synapses in the axon */ typedef vector<Synapse*>::const_iterator const_iterator; /** Reverse iterator for the synapses in the axon */ typedef vector<Synapse*>::reverse_iterator reverse_iterator; /** Const reverse iterator for the synapses it the axon */ typedef vector<Synapse*>::const_reverse_iterator const_reverse_iterator; /** Find the beginning of the axon. * @return An iterator pointing to the first * synapse in the axon */ iterator begin() { return axon.begin(); } /** @return an iterator pointing to the last * synapse in the axon */ iterator end() { return axon.end(); } /** @return a const_iterator pointing to the first * synapse in the axon */ const_iterator begin() const { return axon.begin(); } /** @return a const_iterator pointing to the last * synapse in the axon */ const_iterator end() const { return axon.end(); } /** @return A reverse iterator pointing to the first * synapse in the axon. */ reverse_iterator rbegin() { return axon.rbegin(); } /** @return A reverse iterator pointing to the * last synapse in the axon. */ reverse_iterator rend() { return axon.rend(); } /** @return A reverse const_iterator pointing to the first * synapse in the axon */ const_reverse_iterator rbegin() const { return axon.rbegin(); } /** @return A reverse const_iterator pointing to the last * synapse in the axon */ const_reverse_iterator rend() const { return axon.rend(); }protected: // Functions: /** Turn multi-processing mode on or off. Multi-processing * mode includes both multi-threaded and clustered processing. * Off by default. * @param mode Boolean value of the desired MP mode. */ static void SetMPMode(bool mode) { mpMode = mode; } /** Send a spike to this Neuron. When spikes are * grouped, this function will only be called once per step, but * it can be called multiple times otherwise. * This should only be called from other Neurons or the Network. * @param inSynapse The synapses that the incoming spikes are crossing. * (locations of the weights). * @param inTime Time of input (microseconds). * @param numSyn Number of synapses that are receiving * input during the current time step. The default value * of 0 indicates that spikes are not being grouped together * and only a single spike is being passed. * @see Neuron::SendSpike(), Network::SendDelayedSpikes(). */ virtual void InputSpike(SynapseItr& inSynapse, AmTimeInt inTime, unsigned int numSyn = 0) = 0; /** Determine the maximum value of a weight for this neuron and * set maxScaledWeight to this value. This will be used * as the multiplication factor to convert to and from the * normalized weight values that are used in the public * interface. * <P>NOTE: This function will be deprecated in version 0.4 * if favor of normalizing PSP curves rather than recalculating * normalized weights. */ virtual void SetMaxScaledWeight(); /** Train the network after firing. This assumes that some sort * of Hebbian learning will be used, but children of this class * should be able to either overload this to do nothing (or turn * training off) and provide alternative training methods with * little consequence to the rest of the neuron code. * This is generally called from SendSpike(). * @param spikeTime Time of the last spike or the current * time if called from SendSpike(). */ virtual void Train(AmTimeInt& spikeTime); /** Extend the Neuron::SendSpike() function. First, all local * neurons receive the spike as usual. Then, the spike is sent * to all other instances. TODO: Revise this note. * @param now The current time. * @see Neuron::SendSpike(). */ void SendSMPSpike(AmTimeInt& now); /** Query funcRef to see if a lookup table has already * been generated for an identical neuron and retrieve * a pointer to the table if it has. * This is an internal function and should not be called * by library users. * @param funcRef Pointer to a FunctionLookup object. */ virtual int SetLookupTables(FunctionLookup* funcRef) = 0; /** Round time to nearest simulation time step. This is done to * make sure that the calculated neuron spiking times coincide * with the simulation time steps. * @param time A time value that requires rounding. */ inline void RoundTime(AmTimeInt& time); // Data: /** Neuron ID -- unique in network */ AmIdInt nId; /** Input, Hidden, or Output layer. Will change to neuronRole in the future. */ LayerType layerType; bool inhibitory; static SpikeOutput* spikeOutput; // Output class shared by all instances of Neuron static bool defaultOutputObj; // Flag indicating that the default amygOutput // object is being used. static bool enforceSign; // Time constants float memTimeConst; // Membrane time constant (ms) float synTimeConst; // Synaptic time constant (ms) float refPeriod; // Refractory time period (ms) // Learning parameters float synPotConst; // Synaptic potentiation constant float synDepConst; // Synaptic depression constant float learningMax; // Relative time of max weight increase (ms) float posLearnTimeConst; // Positive learning time const (t+) (ms) float negLearnTimeConst; // Negative learning time const (t-) (ms) float learningConst; // Learning constant // Potentials have mV units float thresholdPtnl; // Threshold potential (theta) float restPtnl; // u-r (unused) float membranePtnl; // u-i (unused) // Needed for calculation of spike times -- see InputSpike() for comments float maxThreshCrs; float convergeRes; /* * Times are measured in microseconds since the begining * of the simulation. These will eventually be changed * to 64-bit integers to allow for longer simulations * (32-bit integers will roll over after about an hour). */ AmTimeInt schedSpikeTime; // time of next scheduled spike AmTimeInt spikeTime; // time of last spike AmTimeInt currTime; // current simulation time - set in InputSpike() AmTimeInt inputTime; // time of last received spike static AmTimeInt simStepSize; // simulation step size in us static bool recordOutput; static OutputMode outputMode; // Also need some vars relevant to the training rule... // Get those out of the Hebbian Learning paper bool trainingMode; // Training indicator Network* SNet; // Parent Network int axonSize; // number of outputs //int dendriteSize; // number of inputs int initAxonSize; // initial size of output float maxScaledWeight; // scaling factor for normalized weights vector<Synapse*> axon; /** * Synaptic history needed for training. * Reset during Train() */ struct SynapseHist { AmTimeInt time; Synapse* syn; }; vector<SynapseHist> synapseHist; /** * History of input spike times and associated weights used * to calculate the current activation potential of the neuron. * Reset during SendSpike(). */ struct InputHist { float weight; AmTimeInt time; }; vector<InputHist> inputHist; unsigned int histBeginIdx; /** represents synaptic connections to Neurons on Instances on other nodes * The smpAxon vector contains only the instance Ids of the target Instance. * The remote Instance needs to resolve which neurons get the spike based on * our InstanceID and our neuron Id. */ vector <SMPSynapse*> smpAxon; unsigned int pspLSize; // array size unsigned int pspStepSize; // size of time increment in pspLookup (in us) // Obsolete -- now used as a flag in SetTimeConstants to indicate // that the lookup tables have been filled. A new method // for doing that should be developed. bool usePspLookup; PhysicalProperties physicalProperties;private: /** Send a spike to all outgoing neurons. This function * is generally called from Network. It should not be called * directly by library users. * @param now Time of spike. */ void SendSpike(AmTimeInt& now); /** Add a synapse to the axon (output connection). * This should only be called from Network::ConnectNeurons(). * @param synapse Synapse that stores the outgoing connection. * This is created by Network, but Neuron owns the pointer * and is responsible for its destruction. * @throw string A string describing the exception. */ void AddSynapse(Synapse* synapse); /** Add a synapse to another Instance the remoteAxon (output connection). * @param synapse Synapse that stores the outgoing connection data. * @throw string A string describing the exception. * @see Neuron::AddSynapse(). */ void AddSMPSynapse(SMPSynapse* synapse); /** Set the step size and number of elements to be * inserted into the lookup tables. * This is an internal function that should only be called * from Network when a Neuron is being initialized. * @param tblSize Number of elements in the table. * @param tblRes Element resolution, the size of the * time step between table elements. Usually * set at 1/10 of the simulation time step. */ void SetTableDimensions(int tblSize, int tblRes); /** Initializes default variable values during construction. */ void SetDefaults(); /** NOTE: This will be deprecated in version 0.4 in favor of * normalizing PSP curves rather than recalculating normalized * weight values. *@Return The maximum value of the scaled (non-normalized) weight */ float GetMaxScaledWeight() const { return maxScaledWeight; } static bool mpMode; static bool spikeDelaysOn; friend class Network; friend class MpNetwork;};inline void Neuron::RoundTime(AmTimeInt& time){ float tmpTime; float roundTime; tmpTime = float(time) / pspStepSize; tmpTime = modff(tmpTime, &roundTime); if (tmpTime > 0.5) { time = (int(roundTime) * pspStepSize) + pspStepSize; } else { time = int(roundTime) * pspStepSize; }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -