📄 dneuron.h
字号:
void setConvergeLevel(tscheduler &scheduler, ntime_t current_time, real val) { simulateElapse( current_time ); sig_converge_level = val; ext_input = sig_converge_level * coeff_sigdecay; scheduleFire( scheduler, current_time ); } /// Get the class name. virtual const char *getClassName() const { return "tneuron_ext_const"; };};/*************************************************************************////////////////////////////////////////////////////////////////////////////// The extended neuron class./// This class of neurons calculates the potential as a sum of functions./// You can specify arbitrary functions, if you can provide the linear envelopes/// of the function and 1st/2nd derivatives.template <bool debug>class tneuron_ext : public tneuron_base, public taction, public debugflag<debug>{protected: /// A collection of incoming synapses. std::vector<tsynapse_base *> synapses; /// A collection of functions. std::vector<func_base *> exts; /// A pulse function to support tsynapse. func_delta_int *pulses; /// Last simulation time, only for simulate-logging. ntime_t last_simulate; /// Last firing time. ntime_t last_fire; /// Loopback time. It is used to check the loopback time changes, ntime_t loopback; /// The decaying coefficient for the inputs. real lambda; /// The last simulation type, only for simulate-logging. int last_simulate_type; /// Process firing at the specified time. void fire(tscheduler &scheduler, ntime_t current_time); /// Calculate the power of signal at the specified time. real calcSignal( ntime_t current_time ); /// Schedule the next firing. virtual void scheduleFire( tscheduler &scheduler, ntime_t current_time, bool resched = true ); /// Send the message to a function. bool sendMessage(ntime_t t, message_base *mess); /// Send the message to all the functions. bool broadcastMessage(ntime_t t, message_base *mess);public: /// Construct a tneuron_ext class with the specified name and signal half-value period. tneuron_ext(std::string iname = "", real sig_hv_period = 1.0); virtual ~tneuron_ext(); /// Get the current signal level. virtual real getCurrentSigLevel(ntime_t current_time) { return calcSignal(current_time); } /// Get the current threshold level, which is always 0.0. virtual real getCurrentThrLevel(ntime_t /*current_time*/) { return 0.0; } /// Process the pulse arrival to this neuron. virtual void pulseArrive( tscheduler &scheduler, ntime_t current_time, real pulse_level); /// Process the message arrival to this neuron. virtual void pulseArrive( tscheduler &scheduler, ntime_t current_time, message_base *mess); /// Process the function arrival to this neuron. virtual void pulseArrive( tscheduler &scheduler, ntime_t current_time, func_base *func); /// Add an incoming synapse to this neuron. virtual void addSynapse(tsynapse_base *s) { synapses.push_back(s); s->setSrc(*this); } /// Erase an incoming synapse from this neuron. virtual void eraseSynapse(tsynapse_base *s) { remove( synapses.begin(), synapses.end(), s); } /// Add an external function to this neuron. virtual void addExt(func_base *s) { s->setLambda(lambda); s->setZeroPoint(last_fire); exts.push_back(s); } /// This function returns the last time that the neuron fired. Used in STDP and such. virtual ntime_t getLastFire() const { return last_fire; } /// This function returns the last time that the neuron has been simulated. virtual ntime_t getLastSimulate() const { return last_simulate; } /// This function returns the type of the last simulation (0th/1st/2nd and so on). virtual int getLastSimulateType() const { return last_simulate_type; } /// When activated as an event (loopback), it re-calculates its state and check firing. virtual void activate(tscheduler &scheduler, ntime_t current_time) { if( getDeb() ) std::cout << std::setw(9) << std::setiosflags(std::ios::fixed) << std::setprecision(debug_precision) << current_time << " " << getName() << " Pulse arrived (loopback)" << std::endl; if( current_time == loopback ) scheduleFire(scheduler, current_time, false); else { if( getDeb() ) std::cout << std::setw(9) << std::setiosflags(std::ios::fixed) << std::setprecision(debug_precision) << current_time << " " << getName() << " Pulse loopback ignored loopback=" << loopback << ", diff=" << std::setprecision(10) << loopback - current_time << std::endl; } }; /// Gets the class name. virtual const char *getClassName() const { return "tneuron_ext"; }; /// Gets the collection of the synapses. const std::vector<tsynapse_base *> &getSynapses() { return synapses; } /// Get the queue object of this neuron. virtual tqueue *queue() const { return tneuron_base::queue(); } /// Specify the loopback at the time. If the time is infinity, the loopback is cancelled. /// This method is public because the loopback is explicitly set. void setLoopBack(tscheduler &scheduler, ntime_t schedule_time) { loopback = schedule_time; if( schedule_time < mak::Infinity ) scheduler.scheduleEvent( schedule_time, *this ); }};/// @}/// \addtogroup Synapses/// @{/// Synapse class that adds a new function to the destination (postsynaptic) tneuron_ext.template <bool debug>class tsynapse_addfunc : public tsynapse_base, public debugflag<debug>{protected: tneuron_base *src; tneuron_ext<debug> *dest; func_base *func; message_base *mess; real lev;public: /// Constructs add-function synapse with the specified source, destination, delay, /// a pointer to a function, a pointer to a message that is sent before adding, and immediate pulse level. tsynapse_addfunc(tneuron_base &isrc, tneuron_ext<debug> &idest, real idelay, func_base *ifunc, message_base *imess = NULL, real ilev = 0.0) : tsynapse_base(idelay), src(&isrc), dest(&idest), func(ifunc), mess(imess), lev(ilev) { } /// Constructs add-function synapse with the specified destination, delay, /// a pointer to a function, a pointer to a message that is sent before adding, and immediate pulse level. tsynapse_addfunc(tneuron_ext<debug> &idest, real idelay, func_base *ifunc, message_base *imess = NULL, real ilev = 0.0) : tsynapse_base(idelay), src(NULL), dest(&idest), func(ifunc), mess(imess), lev(ilev) { } virtual ~tsynapse_addfunc() { } virtual void setSrc(tneuron_base &isrc) { src = &isrc; }// virtual real getWeight() const { return weight; } virtual tneuron_base &getSrc() const { if( src == NULL ) throw "ERROR"; return *src; } virtual tneuron_ext<debug> &getDest() const { return *dest; } /// When activated, The synapse clones the function and added it to the destination neuron. virtual void activate(tscheduler &scheduler, ntime_t current_time) { if( getDeb() ) std::cout << std::setw(9) << std::setiosflags(std::ios::fixed) << std::setprecision(debug_precision) << current_time << " " << dest->getName() << " Pulse Arrived (func) from " << src->getName() << std::endl; func_base *f = func->clone(); if( mess ) f->processMessage( current_time, *mess ); dest->addExt(f); dest->pulseArrive( scheduler, current_time, lev ); } virtual tqueue *queue() const { return dest->queue(); }};/// Synapse class that sends a message to a function in a tneuron_ext neuron./// It is useful for applying an effect of func_expdiff, on which several firing/// can be calculated by one function and message_add_event_time message.template <bool debug>class tsynapse_messfunc : public tsynapse_base, public debugflag<debug>{protected: tneuron_base *src; tneuron_ext<debug> *dest; func_base *func; message_base *mess; real lev;public: /// Constructs add-function synapse with the specified source, destination, delay, /// a pointer to a function, a pointer to a message that is sent for the function at every activation, and immediate pulse level. /// In the constructor the function is added to the destination neuron. tsynapse_messfunc(tneuron_base &isrc, tneuron_ext<debug> &idest, real idelay, func_base *ifunc, message_base *imess, real ilev=0.0) : tsynapse_base(idelay), src(&isrc), dest(&idest), func(ifunc), mess(imess), lev(ilev) { dest->addExt(func); } /// Constructs add-function synapse with the specified destination, delay, /// a pointer to a function, a pointer to a message that is sent for the function at every activation, and immediate pulse level. /// In the constructor the function is added to the destination neuron. tsynapse_messfunc(tneuron_ext<debug> &idest, real idelay, func_base *ifunc, message_base *imess, real ilev=0.0) : tsynapse_base(idelay), src(NULL), dest(&idest), func(ifunc), mess(imess), lev(ilev) { dest->addExt(func); } virtual ~tsynapse_messfunc() { } virtual void setSrc(tneuron_base &isrc) { src = &isrc; }// virtual real getWeight() const { return weight; } virtual tneuron_base &getSrc() const { if( src == NULL ) throw "ERROR"; return *src; } virtual tneuron_ext<debug> &getDest() const { return *dest; } /// When activated, the synapse sends the message to the function and sends the pulse to the destination neuron /// (to notive the change of the function). virtual void activate(tscheduler &scheduler, ntime_t current_time) { if( getDeb() ) std::cout << std::setw(9) << std::setiosflags(std::ios::fixed) << std::setprecision(debug_precision) << current_time << " " << dest->getName() << " Pulse Arrived (func) from " << src->getName() << std::endl; func->processMessage( current_time, *mess );// cout << f->getDescription() << endl; dest->pulseArrive( scheduler, current_time, lev ); } virtual tqueue *queue() const { return dest->queue(); }};/// @}}namespace punnets_common { /// Generate a pulse to the specified destination.taction &makePulse( tneuron_base &idest, real ilevel ); /// Generate a pulse to the specified destination.taction &makePulse( tneuron_base &idest, message_base *message ); /// Set an external input to a specified level.template <bool b>taction &setExtInput( punnets_private::tneuron_ext_const<b> &idest, real ilevel );}namespace punnets {/// a typedef referring punnets_private::tsynapse class.typedef class punnets_private::tsynapse<true> tsynapse;/// a typedef referring punnets_private::tsynapse_message class.typedef class punnets_private::tsynapse_message<true> tsynapse_message;/// a typedef referring punnets_private::tsynapse_fatigue class.typedef class punnets_private::tsynapse_fatigue<true> tsynapse_fatigue;/// a typedef referring punnets_private::tsynapse_addfunc class.typedef class punnets_private::tsynapse_addfunc<true> tsynapse_addfunc;/// a typedef referring punnets_private::tsynapse_messfunc class.typedef class punnets_private::tsynapse_messfunc<true> tsynapse_messfunc;/// a typedef referring punnets_private::tneuron class.typedef class punnets_private::tneuron<true> tneuron;/// a typedef referring punnets_private::tneuron_ext_const class.typedef class punnets_private::tneuron_ext_const<true> tneuron_ext_const;/// a typedef referring punnets_private::tneuron_ext class.typedef class punnets_private::tneuron_ext<true> tneuron_ext;} // namespace punnetsnamespace punnets_nodebug {/// tsynapse class.typedef class punnets_private::tsynapse<false> tsynapse;/// tsynapse_message class.typedef class punnets_private::tsynapse_message<false> tsynapse_message;/// tsynapse_fatigue class.typedef class punnets_private::tsynapse_fatigue<false> tsynapse_fatigue;/// tsynapse_addfunc class.typedef class punnets_private::tsynapse_addfunc<false> tsynapse_addfunc;/// tsynapse_messfunc class.typedef class punnets_private::tsynapse_messfunc<false> tsynapse_messfunc;/// tneuron class.typedef class punnets_private::tneuron<false> tneuron;/// tneuron_ext_const class.typedef class punnets_private::tneuron_ext_const<false> tneuron_ext_const;/// tneuron_ext class.typedef class punnets_private::tneuron_ext<false> tneuron_ext;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -