00001 #ifndef GenericDAModulatedSTDPSYNAPSE_H_
00002 #define GenericDAModulatedSTDPSYNAPSE_H_
00003
00004 #include <queue>
00005
00006 using std::queue;
00007
00008 #include "SimObject.h"
00009 #include "SimNetwork.h"
00010 #include "DopamineReceiver.h"
00011
00012 #include "GenericDAModulatedSTDPSynapse.h"
00013 #include "GenericFroemkeDanStdpSynapse.h"
00014 #include "GenericEachPairStdpSynapse.h"
00015 #include "GenericStaticSpikingSynapse.h"
00016 #include "GenericCurrentBasedSpikingSynapse.h"
00017 #include "FiniteSpikeResponse.h"
00018
00019
00021
00027 template<class BaseSyn>
00028 class GenericDAModulatedSTDPSynapse : public BaseSyn
00029 {
00030 public:
00031
00032 GenericDAModulatedSTDPSynapse()
00033 {
00034 da_trace_response = NULL;
00035 };
00036
00037 virtual ~GenericDAModulatedSTDPSynapse()
00038 {
00039 if (da_trace_response != NULL)
00040 delete da_trace_response;
00041 };
00042
00044 double DATrace;
00045
00047 double DAStdpRate;
00048
00050 double DATraceDelay;
00051
00053 bool activeDASTDP;
00054
00055 virtual int reset( double dt )
00056 {
00057 dopamine_receiver = dynamic_cast<DopamineReceiver*>(BaseSyn::target);
00058 while (!trace_starts.empty()) trace_starts.pop();
00059 while (!trace_weights.empty()) trace_weights.pop();
00060 dw = 0;
00061 assert( da_trace_response != NULL );
00062 da_trace_response->reset(dt);
00063 DATrace = 0;
00064 return BaseSyn::reset(dt);
00065 };
00066
00067
00068 virtual void deepCopy(const SimObject *obj)
00069 {
00070 this->da_trace_response = dynamic_cast<FiniteSpikeResponse *>(dynamic_cast< const GenericDAModulatedSTDPSynapse<BaseSyn> *>(obj)->da_trace_response->create());
00071 }
00072
00073 virtual int advance(AdvanceInfo const & ai);
00074
00075 virtual double stdpLearning(const double & delta, const double & t_post, const double & t_pre, const double & t_prev_post, const double & t_prev_pre );
00076
00077 virtual int spikeHit( spikeport_t port, SpikeEvent const& spike );
00078
00079 FiniteSpikeResponse * getTraceResponse() {
00080 return da_trace_response;
00081 };
00082
00083 protected:
00084 DopamineReceiver * dopamine_receiver;
00085
00086 double dw;
00087
00088 queue<double> trace_starts;
00089 queue<double> trace_weights;
00090
00091 FiniteSpikeResponse * da_trace_response;
00092 };
00093
00094
00095 template<class BaseSyn>
00096 int GenericDAModulatedSTDPSynapse<BaseSyn>::advance(AdvanceInfo const &ai)
00097 {
00098
00099 while (!trace_starts.empty() && ai.t.in_sec() + ai.dt.in_sec() >= trace_starts.front()) {
00100 double t = trace_starts.front(); trace_starts.pop();
00101 double w = trace_weights.front(); trace_weights.pop();
00102
00103
00104 da_trace_response->spikeHit(0, SpikeEvent(ai.t.in_sec(), t - ai.t.in_sec(), w, ai.dt ) );
00105 }
00106 if (da_trace_response->isActive()) {
00107
00108 da_trace_response->advance(ai);
00109 }
00110 DATrace = da_trace_response->psr;
00111
00112 if (activeDASTDP) {
00113 BaseSyn::W += DAStdpRate * DATrace * dopamine_receiver->DA_concentration;
00114
00115 if ((BaseSyn::Wex < 0 && BaseSyn::W > 0) || (BaseSyn::Wex > 0 && BaseSyn::W < 0))
00116 BaseSyn::W = 0;
00117
00118 if (fabs(BaseSyn::W) > fabs(BaseSyn::Wex))
00119 BaseSyn::W = BaseSyn::Wex;
00120 }
00121
00122 int retval = ADVANCEFLAG_DEACTIVATE;
00123 if (BaseSyn::isActive()) {
00124 retval = BaseSyn::advance(ai);
00125 }
00126
00127 if (da_trace_response->isActive() || !trace_starts.empty())
00128 return 0;
00129 else {
00130 return retval;
00131 }
00132 }
00133
00134 template<class BaseSyn>
00135 int GenericDAModulatedSTDPSynapse<BaseSyn>::spikeHit( spikeport_t port, SpikeEvent const& spike )
00136 {
00137 bool trace_response_active = da_trace_response->isActive() || !trace_starts.empty();
00138 int retval = BaseSyn::spikeHit( port, spike );
00139 if (fabs(dw) > 0) {
00140
00141 trace_starts.push(spike.time() + DATraceDelay);
00142 trace_weights.push(dw);
00143 }
00144 dw = 0;
00145
00146 if (trace_response_active) {
00147 return 0;
00148 }
00149 else {
00150 if (port == 1 && !trace_starts.empty() ) {
00151 return SPIKEHITFLAG_ACTIVATE;
00152 }
00153 return retval;
00154 }
00155 }
00156
00157
00158 template<class BaseSyn>
00159 double GenericDAModulatedSTDPSynapse<BaseSyn>::stdpLearning(const double & delta, const double & t_post, const double & t_pre, const double & t_prev_post, const double & t_prev_pre )
00160 {
00161 float w_temp = BaseSyn::W;
00162 dw += BaseSyn::stdpLearning(delta, t_post, t_pre, t_prev_post, t_prev_pre);
00163
00164 BaseSyn::W = w_temp;
00165 return dw;
00166 }
00167
00168
00169
00170 #endif