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