SpikeStream Nemo Plugin  0.2
AbstractSTDPFunction.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "AbstractSTDPFunction.h"
00003 #include "SpikeStreamException.h"
00004 #include "Util.h"
00005 using namespace spikestream;
00006 
00007 
00009 AbstractSTDPFunction::AbstractSTDPFunction(){
00010         functionUpToDate = false;
00011 
00012         //Create parameters common to all STDP functions
00013         defaultParameterMap["reward"] = 1.0;
00014         parameterInfoList.append(ParameterInfo("reward", "Reward applied for each iteration of STDP learning.", ParameterInfo::DOUBLE));
00015         defaultParameterMap["apply_stdp_interval"] = 1.0;
00016         parameterInfoList.append(ParameterInfo("apply_stdp_interval", "Time in between each call to nemo_apply_stdp.", ParameterInfo::UNSIGNED_INTEGER));
00017 }
00018 
00019 
00021 AbstractSTDPFunction::~AbstractSTDPFunction(){
00022 }
00023 
00024 
00025 /*----------------------------------------------------------*/
00026 /*-----                 PUBLIC METHODS                 -----*/
00027 /*----------------------------------------------------------*/
00028 
00030 timestep_t AbstractSTDPFunction::getApplySTDPInterval(){
00031         return Util::rUInt(getParameter("apply_stdp_interval"));
00032 }
00033 
00034 
00036 QHash<QString, double> AbstractSTDPFunction::getParameters(){
00037         return parameterMap;
00038 }
00039 
00040 
00042 void AbstractSTDPFunction::setParameters(QHash<QString, double>& newParamMap){
00043         if(parameterMap.size() != newParamMap.size())
00044                 throw SpikeStreamException("Size of new parameter map does not match that of current parameters");
00045         for(QHash<QString,double>::iterator iter = newParamMap.begin(); iter != newParamMap.end(); ++iter){
00046                 if(!parameterMap.contains(iter.key()))
00047                         throw SpikeStreamException("Parameter " + iter.key() + " is not valid for this STDP function.");
00048                 parameterMap[iter.key()] = iter.value();
00049         }
00050 
00051         //Need to rebuild function
00052         functionUpToDate = false;
00053 }
00054 
00055 
00057 QHash<QString, double> AbstractSTDPFunction::getDefaultParameters(){
00058         return defaultParameterMap;
00059 }
00060 
00061 
00063 QList<ParameterInfo> AbstractSTDPFunction::getParameterInfoList(){
00064         return parameterInfoList;
00065 }
00066 
00067 
00069 float AbstractSTDPFunction::getReward(){
00070         return getParameter("reward");
00071 }
00072 
00073 
00074 /*----------------------------------------------------------*/
00075 /*-----               PROTECTED METHODS                -----*/
00076 /*----------------------------------------------------------*/
00077 
00080 double AbstractSTDPFunction::getParameter(QString parameterName){
00081         if(!parameterMap.contains(parameterName))
00082                 throw SpikeStreamException("Parameter " + parameterName + " cannot be found.");
00083         return parameterMap[parameterName];
00084 }
00085 
00086 
 All Classes Files Functions Variables Typedefs Defines