SpikeStream Nemo Plugin  0.2
StandardSTDPFunction.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "SpikeStreamException.h"
00003 #include "StandardSTDPFunction.h"
00004 using namespace spikestream;
00005 
00006 //Other includes
00007 #include <cmath>
00008 #include <iostream>
00009 using namespace std;
00010 
00011 //Prints out the arrays when enabled
00012 //#define DEBUG
00013 
00014 
00016 StandardSTDPFunction::StandardSTDPFunction() : AbstractSTDPFunction() {
00017         //Information about parameters
00018         parameterInfoList.append(ParameterInfo("pre_length", "Length of the pre array", ParameterInfo::INTEGER));
00019         parameterInfoList.append(ParameterInfo("post_length", "Length of the post array", ParameterInfo::INTEGER));
00020         parameterInfoList.append(ParameterInfo("A+", "A+ description", ParameterInfo::DOUBLE));
00021         parameterInfoList.append(ParameterInfo("A-", "A- description", ParameterInfo::DOUBLE));
00022         parameterInfoList.append(ParameterInfo("T+", "T+ description", ParameterInfo::DOUBLE));
00023         parameterInfoList.append(ParameterInfo("T-", "T- description", ParameterInfo::DOUBLE));
00024         parameterInfoList.append(ParameterInfo("min_excitatory_weight", "Minimum weight that excitatory synapse can reach with learning.", ParameterInfo::DOUBLE));
00025         parameterInfoList.append(ParameterInfo("max_excitatory_weight", "Maximum weight that excitatory synapse can reach with learning.", ParameterInfo::DOUBLE));
00026         parameterInfoList.append(ParameterInfo("min_inhibitory_weight", "Minimum weight that inhibitory synapse can reach with learning. NOTE: The minimum is defined in ABSOLUTE terms, but the value is negative.", ParameterInfo::DOUBLE));
00027         parameterInfoList.append(ParameterInfo("max_inhibitory_weight", "Maximum weight that inhibitory synapse can reach with learning. NOTE: The maximum is defined in ABSOLUTE terms, but the value is negative.", ParameterInfo::DOUBLE));
00028 
00029         //Default values of parameters
00030         defaultParameterMap["pre_length"] = 20;
00031         defaultParameterMap["post_length"] = 20;
00032         defaultParameterMap["A+"] = 0.005;
00033         defaultParameterMap["A-"] = 0.00525;
00034         defaultParameterMap["T+"] = 20.0;
00035         defaultParameterMap["T-"] = 20.0;
00036         defaultParameterMap["min_excitatory_weight"] = 0.0001;
00037         defaultParameterMap["max_excitatory_weight"] = 1.0;
00038         defaultParameterMap["min_inhibitory_weight"] = -0.0001;
00039         defaultParameterMap["max_inhibitory_weight"] = -1;
00040 
00041         //Initialise current parameter map with default values
00042         parameterMap = defaultParameterMap;
00043 
00044         //Initialize arrays
00045         preLength = 0;
00046         postLength = 0;
00047         preArray = NULL;
00048         postArray = NULL;
00049 }
00050 
00051 
00053 StandardSTDPFunction::~StandardSTDPFunction(){
00054         cleanUp();
00055 }
00056 
00057 
00058 /*----------------------------------------------------------*/
00059 /*-----                 PUBLIC METHODS                 -----*/
00060 /*----------------------------------------------------------*/
00061 
00064 float* StandardSTDPFunction::getPreArray(){
00065         checkFunctionUpToDate();
00066         return preArray;
00067 }
00068 
00069 
00071 int StandardSTDPFunction::getPreLength(){
00072         checkFunctionUpToDate();
00073         return preLength;
00074 }
00075 
00076 
00079 float* StandardSTDPFunction::getPostArray(){
00080         checkFunctionUpToDate();
00081         return postArray;
00082 }
00083 
00084 
00086 int StandardSTDPFunction::getPostLength(){
00087         checkFunctionUpToDate();
00088         return postLength;
00089 }
00090 
00091 
00093 float StandardSTDPFunction::getMinExcitatoryWeight(){
00094         return getParameter("min_excitatory_weight");
00095 }
00096 
00097 
00099 float StandardSTDPFunction::getMaxExcitatoryWeight(){
00100         return getParameter("max_excitatory_weight");
00101 }
00102 
00103 
00105 float StandardSTDPFunction::getMinInhibitoryWeight(){
00106         return getParameter("min_inhibitory_weight");
00107 }
00108 
00109 
00111 float StandardSTDPFunction::getMaxInhibitoryWeight(){
00112         return getParameter("max_inhibitory_weight");
00113 }
00114 
00115 
00117 void StandardSTDPFunction::print(){
00118         checkFunctionUpToDate();
00119 
00120         //Extract parameters
00121         double aPlus = getParameter("A+");
00122         double aMinus = getParameter("A-");
00123         double tPlus = getParameter("T+");
00124         double tMinus = getParameter("T-");
00125 
00126         cout<<"Standard STDP Function"<<endl;
00127         cout<<"Parameters. Pre length: "<<preLength<<"; postLength: "<<postLength<<"; A+: "<<aPlus<<"; A-: "<<aMinus<<"; T+: "<<tPlus<<"; T-: "<<tMinus<<endl;
00128         for(int i=0; i<preLength; ++i)
00129                 cout<<"Pre array ["<<i<<"]: "<<preArray[i]<<endl;
00130         cout<<endl;
00131         for(int i=0; i<postLength; ++i)
00132                 cout<<"Post array ["<<i<<"]: "<<postArray[i]<<endl;
00133         cout<<"Min excitatory weight: "<<getMinExcitatoryWeight()<<"; Max excitatory weight: "<<getMaxExcitatoryWeight()<<"; Min inhibitory weight: "<<getMinInhibitoryWeight()<<"; Max inhibitory weight: "<<getMaxInhibitoryWeight()<<endl;
00134 }
00135 
00136 
00137 /*----------------------------------------------------------*/
00138 /*-----                PRIVATE METHODS                 -----*/
00139 /*----------------------------------------------------------*/
00140 
00142 void StandardSTDPFunction::buildStandardSTDPFunction(){
00143         //Delete previous arrays if allocated
00144         cleanUp();
00145 
00146         //Extract parameters
00147         preLength = (int)getParameter("pre_length");
00148         postLength = (int)getParameter("post_length");
00149         double aPlus = getParameter("A+");
00150         double aMinus = getParameter("A-");
00151         double tPlus = getParameter("T+");
00152         double tMinus = getParameter("T-");
00153 
00154         //Build the arrays specifying the function
00155         preArray = new float[preLength];
00156         for(int i = 0; i < preLength; ++i) {
00157                 float dt = float(i + 1);
00158                 preArray[i] = aPlus * expf( (-1.0 * dt) / tPlus);
00159         }
00160         postArray = new float[postLength];
00161         for(int i = 0; i < postLength; ++i) {
00162                 float dt = float(i + 1);
00163                 postArray[i] = -1.0 * aMinus * expf( (-1.0 * dt) / tMinus);
00164         }
00165 
00166         #ifdef DEBUG
00167                 print();
00168         #endif//DEBUG
00169 }
00170 
00171 
00173 void StandardSTDPFunction::checkFunctionUpToDate(){
00174         if(functionUpToDate)
00175                 return;
00176         buildStandardSTDPFunction();
00177         functionUpToDate = true;
00178 }
00179 
00180 
00182 void StandardSTDPFunction::cleanUp(){
00183         if(preArray != NULL)
00184                 delete [] preArray;
00185         preArray = NULL;
00186         if(postArray != NULL)
00187                 delete [] postArray;
00188         postArray = NULL;
00189 }
00190 
00191 
00192 
00193 
00194 
00195 
 All Classes Files Functions Variables Typedefs Defines