⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 func.h

📁 a useful spiking neural networks simulator
💻 H
📖 第 1 页 / 共 3 页
字号:
	virtual real get1stDeriv( ntime_t /*t*/ ) const				{ return 0; }	virtual real get2ndDeriv( ntime_t /*t*/ ) const				{ return 0; }	virtual ntime_t getNextIncontinuity( ntime_t from ) const { return from < t0 ? t0 : mak::Infinity; };	virtual void getValueDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const 				{ upslope = downslope = 0; ceil = floor = (t >= t0 ? r : 0);  }	virtual void get1stDerivDomain( ntime_t /*t*/, real &upslope, real &ceil, real &downslope, real &floor ) const 				{ upslope = downslope = 0; ceil = floor = 0;  }	virtual void get2ndDerivDomain( ntime_t /*t*/, real &upslope, real &ceil, real &downslope, real &floor ) const 				{ upslope = downslope = 0; ceil = floor = 0;  }	virtual func_step * clone() { return new func_step(*this); }	virtual std::string getDescription() { std::ostringstream oss; oss << "func_step r=" << r << ", t0=" << t0; return oss.str(); }};/// </body></classdef>//////////////////////////////////////////////////////////////////////////// An integrated delta function with leak.////// A leaky integration of a delta function./// $df/dt = r \delta( t - t0 ) - \lambda f$.class func_delta_int : public func_deriveq_base{	real r;	ntime_t t0;	virtual void valueChange() { }public:							/// Constructs func_delta_int with pulse amplitude r, and pulse arrival time t0.	func_delta_int(real ir, ntime_t it0) : func_deriveq_base(), r(ir), t0(it0) { valueChange(); }				virtual real getMaxGradient( ntime_t /*t*/ ) const { return r<0 ? - lambda * r : 0 ; };	void setParam(real ir, ntime_t it0) { r = ir; t0 = it0; }	virtual real getValue( ntime_t t ) const 		/// A function that returns a leaky integrated value between the last pulse arrival time <var>t0</var> and <var>t</var>.		/// $x = 1/e<sup>&lambda;<var>t</var></sup> ( &int;<sub><var>from</var></sub><sup><var>to</var></sup>e<sup>&lambda;<var>t</var></sup>f(<var>t</var>) + C)$				{ //					std::cout << "zerop=" << zerop << ", t0=" << t0 << ",t=" << t << std::endl;					return (zerop < t0 && t0 <= t) ? r * exp( - lambda * (t - t0) ) : 0.0; }	virtual real get1stDeriv( ntime_t t ) const				{ return (zerop < t0 && t0 <= t) ? - lambda * r * exp( - lambda * (t - t0) ) : 0.0; }	virtual real get2ndDeriv( ntime_t t ) const				{ return (zerop < t0 && t0 <= t) ? lambda * lambda * r * exp( - lambda * (t - t0) ) : 0.0; }	virtual real get3rdDeriv( ntime_t t ) const				{ return (zerop < t0 && t0 <= t) ? - lambda * lambda * lambda * r * exp( - lambda * (t - t0) ) : 0.0; }	virtual ntime_t getNextIncontinuity( ntime_t from ) const { return from < t0 ? t0 : mak::Infinity; };	virtual void getValueDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get1stDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get2ndDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual std::string getDescription() { std::ostringstream oss; oss << "func_delta_int r=" << r << ", t0=" << t0 << ", lambda=" << lambda << ", zerop=" << zerop; return oss.str(); }	/// A message that adds a new pulse.	class message_add_pulse : public message_base	{		real pulselev;public:			message_add_pulse(real ipl) : message_base() { pulselev = ipl; }		static const char * const messageId;		virtual const char *getMessageId() const { return messageId; }		real getPulseLevel() const { return pulselev; }	};	virtual bool processMessage(ntime_t t, const message_base &m) { #ifdef USE_DYNAMIC		if( const message_add_pulse *mm = dynamic_cast<const message_add_pulse *>(&m) ) {			setParam( getValue(t) + mm->getPulseLevel(), t );			return true;		}#else		if( m.getMessageId() == message_add_pulse::messageId ) {			setParam( getValue(t) + dynamic_cast<const message_add_pulse &>(m).getPulseLevel(), t );			return true;		}#endif		return func_deriveq_base::processMessage(t, m); 	}	virtual func_delta_int * clone() { return new func_delta_int(*this); }};//////////////////////////////////////////////////////////////////////////// A response function.////// \todo document this functionclass func_response : public func_deriveq_base{	real r, rinit;	virtual void valueChange() { }public:	func_response(real ir) : func_deriveq_base(), r(ir), rinit(ir) { valueChange(); }				virtual real getMaxGradient( ntime_t /*t*/ ) const { return r<0 ? - lambda * r : 0 ; };	virtual real getValue( ntime_t t ) const 				{ 					return r * exp( - lambda * (t - zerop) ) ; }	virtual real get1stDeriv( ntime_t t ) const				{ return - lambda * r * exp( - lambda * (t - zerop) ); }	virtual real get2ndDeriv( ntime_t t ) const				{ return lambda * lambda * r * exp( - lambda * (t - zerop) ); }	virtual real get3rdDeriv( ntime_t t ) const				{ return - lambda * lambda * lambda * r * exp( - lambda * (t - zerop) ); }	virtual ntime_t getNextIncontinuity( ntime_t /*from*/ ) const { return mak::Infinity; };	virtual void getValueDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get1stDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get2ndDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual std::string getDescription() { std::ostringstream oss; oss << "func_response r=" << r << ", lambda=" << lambda << ", zerop=" << zerop; return oss.str(); }	virtual func_response * clone() { return new func_response(*this); }	virtual void setZeroPoint(real new_zeropoint) { 			r = rinit + r * exp( - lambda * (new_zeropoint - zerop) );				zerop = new_zeropoint; zeropChange(); }};//////////////////////////////////////////////////////////////////////////// Sinusoidal function////// This function represents a sinusoidal function f(<var>t</var>) = r sin(&omega; t + &theta;).class func_sine : public func_base{	real r;	real omega;	real theta;	static const real alpha = 1.311;	static const real beta  = 0.375867;	void valueChange() { }public:					/// Constructs a func_sine with amplitude r, angle velocity omega, and phase theta.	func_sine(real ir, real iomega, real itheta) : func_base(), r(ir), omega(iomega), theta(itheta) { valueChange(); }				virtual real getMaxGradient( ntime_t /*t*/ ) const { return omega * r; };	virtual real getValue( ntime_t t ) const				{ return r * sin(omega * t + theta); }	virtual real get1stDeriv( ntime_t t ) const				{ return omega * r * cos(omega * t + theta); }	virtual real get2ndDeriv( ntime_t t ) const				{ return - omega * omega * r * sin(omega * t + theta); }	virtual real get3rdDeriv( ntime_t t ) const				{ return - omega * omega * omega * r * cos(omega * t + theta); }	virtual ntime_t getNextIncontinuity( ntime_t /*from*/ ) const { return mak::Infinity; };	virtual void getValueDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get1stDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get2ndDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual func_sine * clone() { return new func_sine(*this); }	virtual std::string getDescription() { std::ostringstream oss; oss << "func_sine r=" << r << ", omega=" << omega << ", theta=" << theta; return oss.str(); }};//////////////////////////////////////////////////////////////////////////// A single shot of sinusoidal function////// This function represents a single shot (one cycle) of a sinusoidal function /// f(<var>t</var>) = r sin^2(&omega; (t - t0)) (t0 <= t <= t0+&pi;/&omega;).class func_sineshot : public func_base{	real r;	real omega;	real t0;	real r_div_2;		///< = r/2	real omega_2;		///< = 2 &omega;	real duration;		///< = &pi; / &omega;	static const real alpha = 1.311;	static const real beta  = 0.375867;	void valueChange() { duration = M_PI / omega; omega_2 = 2 * omega; r_div_2 = r * 0.5; }public:					/// Constructs a func_sineshot with amplitude r, angle velocity omega, and origin t0.	func_sineshot(real ir, real iomega, real it0) : func_base(), r(ir), omega(iomega), t0(it0) { valueChange(); }				virtual real getMaxGradient( ntime_t /*t*/ ) const { return fabs(r_div_2) * omega_2; };	virtual bool shouldDelete(ntime_t current) { return (current >= t0 + duration); }	virtual real getValue( ntime_t t ) const				{ return (t0 <= t && t <= t0 + duration ? r_div_2 * (1-cos(omega_2 * (t-t0) )) : 0.0); }	virtual real get1stDeriv( ntime_t t ) const				{ return (t0 <= t && t <= t0 + duration ? r_div_2 * omega_2 * sin(omega_2 * (t-t0) ) : 0.0); }	virtual real get2ndDeriv( ntime_t t ) const				{ return (t0 <= t && t <= t0 + duration ? r_div_2 * omega_2 * omega_2 * cos(omega_2 * (t-t0) ) : 0.0); }	virtual ntime_t getNextIncontinuity( ntime_t from ) const { return from < t0 ? t0 : mak::Infinity; };		/// A virtual function that returns the next incontinuity point after the time t.		/// Although this function has no incontinuity, it returns t0 because the linear envelope is divided at the point.	virtual void getValueDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get1stDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual void get2ndDerivDomain( ntime_t t, real &upslope, real &ceil, real &downslope, real &floor ) const;	virtual func_sineshot * clone() { return new func_sineshot(*this); }	virtual std::string getDescription() { std::ostringstream oss; oss << "func_sineshot r=" << r << ", omega=" << omega << ", t0=" << t0; return oss.str(); }	/// A message that changes t0.	class message_set_t0 : public message_base	{public:			message_set_t0() : message_base() { }		static const char * const messageId;		virtual const char *getMessageId() const { return messageId; }	};	virtual bool processMessage(ntime_t t, const message_base &m) { #ifdef USE_DYNAMIC		if( dynamic_cast<const message_set_t0 *>(&m) != NULL ) #else		if( m.getMessageId() == message_set_t0::messageId ) #endif		{			t0 = t;			return true;		}		return func_base::processMessage(t, m); 	}};//////////////////////////////////////////////////////////////////////////// Integrated function of func_sine////// This function represents an integration of a sinusoidal function.class func_sine_int : public func_deriveq_base{	real r;	real omega;	real theta;	real r_inv_lsq_osq;	///< Equal to r/(&lambda;<sup>2</sup> + &omega;<sup>2</sup>).	real zerop_value;	void valueChange() { r_inv_lsq_osq = r / (lambda * lambda + omega * omega); }	void zeropChange() { zerop_value = lambda * sin( theta + omega * zerop ) - omega * cos( theta + omega * zerop ); }public:					/// Constructs a func_sine_int with amplitude r, angle velocity omega, and phase theta.	func_sine_int(real ir, real iomega, real itheta) : func_deriveq_base(), r(ir), omega(iomega), theta(itheta) { valueChange(); }				virtual real getMaxGradient( ntime_t /*t*/ ) const { return r_inv_lsq_osq * (omega * (lambda + 1) - lambda * lambda * zerop_value); };	virtual real getValue(ntime_t t) const				{ return r_inv_lsq_osq * (							lambda * sin( theta + omega * t ) - omega * cos( theta + omega * t )							+ exp( lambda * (zerop - t) ) * zerop_value );				}	virtual real get1stDeriv(ntime_t t) const				{ return r_inv_lsq_osq * (							omega * (lambda * cos( theta + omega * t ) + omega * sin( theta + omega * t ))								- lambda * exp( lambda * (zerop - t) ) * zerop_value );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -