📄 neuron.h
字号:
/*************************************************************************** neuron.h - description ------------------- copyright : (C) 2001, 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. * * * ***************************************************************************/#ifndef NEURON_H#define NEURON_H#include <amygdala/amygdalaclass.h>#include <amygdala/outputmanager.h>#include <vector>#include <cmath>#ifdef LOGGING#define LOG_WEIGHT_HIST(level) if(level>=LOGLEVEL){ \# cout << "LOGLEVEL " << level << " " << __FILE__ << ":" << __LINE__ << " -- " << WEIGHT HISTORY << endl; \# cout << "\tNEURON " << nId << endl; \# for (i=0; i<histSize; i++) { \# tmpInput = inputHist[i]; \# cout << "\t\tinTimeHist[" << i << "] " << tmpInput.time << endl; \# cout << "\t\tinWeightHist[" << i << "] " << tmpInput.weight << endl; \# } \# cout << "\t\tcalcTime: " << calcTime << endl; \# cout << "\t\tinTime: " << inTime << endl; \# cout << "\t\tcurrTime: " << currTime << endl; }#else#define LOG_WEIGHT_HIST(level)#endifnamespace Amygdala {class NeuronProperties;class Trainer;class Axon;/** @class Neuron neuron.h amygdala/neuron.h * @brief Virtual base class for all Neurons. * * Neuron provides an interface for the implementation of * integrate-and-fire model neurons. Neuron cannot be * instantiated as an object itself, but can only be * instantiated via a child class. Neuron does not place any * restrictions on how child neurons are modeled other than * requiring the implementation of a set of functions that * will generally be unique to each model. Neuron implementors * should also be aware that Amygdala is an event driven * simulator and a Neuron will only interact with the rest * of the network when it receives a spike or when it is * scheduled to spike itself. * Neurons cannot be created directly, but must be instantiated * via a NeuronFactory. * @see AlphaNeuron, BasicNeuron, FastNeuron, NeuronFactory, Topology * @author Matt Grover */class Neuron: public AmygdalaClass {public: virtual ~Neuron() = 0; /** @return The neuron ID. */ AmIdInt GetId() const { return(nId); } /** Set this to true if this is is an inhibitory * neuron. This function has no effect if neuron * signs (positive or negative) are not being enforced. * @param val Inhibitory status. If true, * all outgoing connections will have * negative weights. * @see Neuron::EnforceSign(). */ void Inhibitory(bool val) { inhibitory = val; } // Leave this one in even if setter function is moved to props /** Get the neuron sign. * @return True for inhibitory neurons, false otherwise. * This value has no real meaning if neuron sign is not * being enforced. * @see Neuron::EnforceSign(). */ bool Inhibitory() const { return inhibitory; } /** Turn output on or off for a group of neurons. * @param enable Flag to enable or disable output * @param groupId Id of output group that will be turned on or off * @see OutputManager, SpikeOutput */ static void CaptureOutput(bool enable, unsigned int groupId); static bool CaptureOutput(unsigned int groupId); /** Allow the network to force neurons to be either inhibitory * or excitatory. If false, Neurons can form both inhibitory and * excitatory output connections. * @param enforce True if neuron sign should be enforced. False by default. * @see Neuron::Inhibitory(). */ static void EnforceSign(bool enforce) { enforceSign = enforce; } /** Get the sign enforcement mode. * @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; } /** @return Ptr to Properties object associated with this neuron. * @see NeuronProperties */ NeuronProperties* Properties() const { return neuronProps; } /** @return The time of the last spike for this neuron. Returns * 0 if neuron has never spiked. */ const AmTimeInt GetLastSpiketime() const {return spikeTime; } /** @return The current membrane potential for this neuron */ virtual float GetMembranePtnl() const { return 0.F; } /** @return The neuron's axon * @see Axon, AxonNode */ Axon* GetAxon() const { return axon; } Trainer* GetDefaultTrainer() const { return defaultTrainer; } void SetDefaultTrainer(Trainer* trainer) { defaultTrainer = trainer; } /** Get the output group index for this neuron. The index * is a bit field that identifies which groups the neuron * belongs to. * @return The output group bit field */ AmGroupInt GetOutputGroupIndex() const { return outputGroupIdx; }protected: // Functions: /** @param neuronId A unique, positive integer that is used * to identify the neuron. * @param props A container for values that are needed * to initialize a neuron. */ Neuron(AmIdInt neuronId, const NeuronProperties& props); Neuron(AmIdInt neuronId); /** Scale the values in the function lookup tables so that * the weight values can be normalized. A weight of 1.0 should * be the minimum weight required for a single presynaptic spike to cause * the neuron to fire. */ virtual void ScaleFunctionLookups() {}; /** Add the neuron to an output group * @param groupId ID of the output group */ void AddOutputGroup(unsigned int groupId); // Data: /** Neuron ID -- unique in network */ AmIdInt nId; AmTimeInt spikeTime; // time of last spike NeuronProperties* neuronProps; bool inhibitory; Axon* axon; Trainer* defaultTrainer; static AmTimeInt simStepSize; // simulation step size in us static float stepSizeInv; // 1/simStepSize static AmGroupInt outputMode; AmGroupInt outputGroupIdx; static bool enforceSign;private: static void InitStepSize(); friend class Network; friend class Topology; friend void OutputManager::EnableOutput(bool,unsigned int); friend void OutputManager::AddNeuronToGroup(Neuron*, AmGroupInt);};} // namespace Amygdala#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -