00001 #ifndef GENERICNSHEBBIANSYNAPSE_H_
00002 #define GENERICNSHEBBIANSYNAPSE_H_
00003
00004 #include "SpikeResponse.h"
00005 #include "EvSimObjectTypeUtils.h"
00006
00007 template<class Base>
00008 class GenericNSHebbianSynapse : public Base {
00009
00010 public:
00011 GenericNSHebbianSynapse(float Winit,
00012 float eta,
00013 bool activePlasticity,
00014 float maxW,
00015 float minW,
00016 short sign,
00017 SpikeResponse *response,
00018 SpikeResponse *bap_trace)
00019 {
00020
00021 this->Winit = Winit;
00022 this->eta = eta;
00023 this->sign=sign;
00024 this->activePlasticity = activePlasticity;
00025 this->Base::syn_resp = (response) ? dynamic_cast<SpikeResponse *>(response->copy()) : 0;
00026 this->bap_response = (bap_trace) ? dynamic_cast<SpikeResponse *>(bap_trace->copy()) : 0;
00027 this->maxW = maxW;
00028 this->minW = minW;
00029
00030 }
00031
00032 virtual ~GenericNSHebbianSynapse() {};
00033
00034 float eta;
00035
00036 float Winit;
00037
00038 short sign;
00039
00040 bool activePlasticity;
00041
00042 float maxW;
00043
00044 float minW;
00045
00046 virtual void setBackpropAPResponse(SpikeResponse *response) {
00047 bap_response = response;
00048 };
00049
00050 virtual bool propagatesUpdate(update_id_t upd_id) const {
00051 if (upd_id == 1)
00052 return false;
00053 return true;
00054 };
00055
00056 virtual void reset(SimContext &sim_ctxt)
00057 {
00058 Base::W = Winit;
00059 Base::resetPSRs();
00060 };
00061
00062 virtual SpikeResponse *createBackpropAPResponseObject() {return bap_response;};
00063
00064 virtual void updateState(SimContext &sim_ctxt, Time time, update_id_t upd_id);
00065
00066 virtual bool isPlastic() { return true; };
00067
00068 protected:
00069 SpikeResponse *bap_response;
00070 Time timeOfLastChange;
00071
00072 };
00073
00074 template<class Base>
00075 void GenericNSHebbianSynapse<Base>::updateState(SimContext& sim_ctxt, Time time, update_id_t upd_id) {
00076 double pre_trace, post_trace;
00077 if (upd_id == 0) {
00078 pre_trace = Base::syn_resp->getOld();
00079 post_trace = bap_response->get();
00080 }
00081 else {
00082 pre_trace = Base::syn_resp->get();
00083 post_trace = bap_response->getOld();
00084 }
00085 if (activePlasticity) {
00086 double newW = Base::W + eta * sign *post_trace * pre_trace * (time - timeOfLastChange);
00087 if (newW < maxW && newW > minW) Base::W = newW;
00088 timeOfLastChange = time;
00089 }
00090 if (upd_id == 0)
00091 Base::updateState(sim_ctxt, time, upd_id);
00092 }
00093
00094 #endif