SpikeStream Nemo Plugin
0.2
|
00001 //SpikeStream includes 00002 #include "SpikeStreamException.h" 00003 #include "StepSTDPFunction.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 StepSTDPFunction::StepSTDPFunction() : 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("pre_y_value", "Location of the pre step function on the Y axis. Can be positive or negative", ParameterInfo::DOUBLE)); 00021 parameterInfoList.append(ParameterInfo("post_y_value", "Location of the post step function on the Y axis. Can be positive or negative", ParameterInfo::DOUBLE)); 00022 parameterInfoList.append(ParameterInfo("min_excitatory_weight", "Minimum weight that excitatory synapse can reach with learning.", ParameterInfo::DOUBLE)); 00023 parameterInfoList.append(ParameterInfo("max_excitatory_weight", "Maximum weight that excitatory synapse can reach with learning.", ParameterInfo::DOUBLE)); 00024 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)); 00025 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)); 00026 00027 //Default values of parameters 00028 defaultParameterMap["pre_length"] = 1; 00029 defaultParameterMap["post_length"] = 1; 00030 defaultParameterMap["pre_y_value"] = 0.10; 00031 defaultParameterMap["post_y_value"] = -0.15; 00032 defaultParameterMap["min_excitatory_weight"] = 0.0001; 00033 defaultParameterMap["max_excitatory_weight"] = 1.0; 00034 defaultParameterMap["min_inhibitory_weight"] = -0.0001; 00035 defaultParameterMap["max_inhibitory_weight"] = -1.0; 00036 00037 00038 //Initialize arrays 00039 preLength = 0; 00040 postLength = 0; 00041 preArray = NULL; 00042 postArray = NULL; 00043 00044 //Initialise current parameter map with default values 00045 parameterMap = defaultParameterMap; 00046 } 00047 00048 00050 StepSTDPFunction::~StepSTDPFunction(){ 00051 cleanUp(); 00052 } 00053 00054 00055 /*----------------------------------------------------------*/ 00056 /*----- PUBLIC METHODS -----*/ 00057 /*----------------------------------------------------------*/ 00058 00061 float* StepSTDPFunction::getPreArray(){ 00062 checkFunctionUpToDate(); 00063 return preArray; 00064 } 00065 00066 00068 int StepSTDPFunction::getPreLength(){ 00069 checkFunctionUpToDate(); 00070 return preLength; 00071 } 00072 00073 00076 float* StepSTDPFunction::getPostArray(){ 00077 checkFunctionUpToDate(); 00078 return postArray; 00079 } 00080 00081 00083 int StepSTDPFunction::getPostLength(){ 00084 checkFunctionUpToDate(); 00085 return postLength; 00086 } 00087 00088 00090 float StepSTDPFunction::getMinExcitatoryWeight(){ 00091 return getParameter("min_excitatory_weight"); 00092 } 00093 00094 00096 float StepSTDPFunction::getMaxExcitatoryWeight(){ 00097 return getParameter("max_excitatory_weight"); 00098 } 00099 00100 00102 float StepSTDPFunction::getMinInhibitoryWeight(){ 00103 return getParameter("min_inhibitory_weight"); 00104 } 00105 00106 00108 float StepSTDPFunction::getMaxInhibitoryWeight(){ 00109 return getParameter("max_inhibitory_weight"); 00110 } 00111 00112 00114 void StepSTDPFunction::print(){ 00115 checkFunctionUpToDate(); 00116 00117 //Extract parameters 00118 double preY = getParameter("pre_y_value"); 00119 double postY = getParameter("post_y_value"); 00120 00121 cout<<"Step STDP Function"<<endl; 00122 cout<<"Parameters. Pre length: "<<preLength<<"; post length: "<<postLength<<"; preY: "<<preY<<"; postY: "<<postY<<endl; 00123 for(int i=0; i<preLength; ++i) 00124 cout<<"Pre array ["<<i<<"]: "<<preArray[i]<<endl; 00125 cout<<endl; 00126 for(int i=0; i<postLength; ++i) 00127 cout<<"Post array ["<<i<<"]: "<<postArray[i]<<endl; 00128 cout<<"Min excitatory weight: "<<getMinExcitatoryWeight()<<"; Max excitatory weight: "<<getMaxExcitatoryWeight()<<"; Min inhibitory weight: "<<getMinInhibitoryWeight()<<"; Max inhibitory weight: "<<getMaxInhibitoryWeight()<<endl; 00129 } 00130 00131 00132 /*----------------------------------------------------------*/ 00133 /*----- PRIVATE METHODS -----*/ 00134 /*----------------------------------------------------------*/ 00135 00137 void StepSTDPFunction::buildStepSTDPFunction(){ 00138 //Delete previous arrays if allocated 00139 cleanUp(); 00140 00141 //Extract parameters 00142 preLength = (int)getParameter("pre_length"); 00143 postLength = (int)getParameter("post_length"); 00144 double preY = getParameter("pre_y_value"); 00145 double postY = getParameter("post_y_value"); 00146 00147 //Build the arrays specifying the function 00148 preArray = new float[preLength]; 00149 for(int i = 0; i < preLength; ++i) { 00150 preArray[i] = preY; 00151 } 00152 postArray = new float[postLength]; 00153 for(int i = 0; i < postLength; ++i) { 00154 postArray[i] = postY; 00155 } 00156 00157 #ifdef DEBUG 00158 print(); 00159 #endif//DEBUG 00160 } 00161 00162 00164 void StepSTDPFunction::checkFunctionUpToDate(){ 00165 if(functionUpToDate) 00166 return; 00167 buildStepSTDPFunction(); 00168 functionUpToDate = true; 00169 } 00170 00171 00173 void StepSTDPFunction::cleanUp(){ 00174 if(preArray != NULL) 00175 delete [] preArray; 00176 preArray = NULL; 00177 if(postArray != NULL) 00178 delete [] postArray; 00179 postArray = NULL; 00180 } 00181 00182 00183 00184 00185