00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "RBFPopulation.h"
00025 #include "RBFNeuron.h"
00026 #include "Projection.h"
00027 #include "RBFInputData.h"
00028
00029 namespace verve
00030 {
00031 RBFPopulation::RBFPopulation()
00032 : Population()
00033 {
00034 mContinuousResolution = 0;
00035 mNumDiscreteDimensions = 0;
00036 mNumContinuousDimensions = 0;
00037 mIsDynamic = true;
00038 mSingleState = false;
00039 mStdDevWidth = 0;
00040 }
00041
00042 RBFPopulation::~RBFPopulation()
00043 {
00044 }
00045
00046 void RBFPopulation::init(const RBFInputData& inputData, bool isDynamic)
00047 {
00048 assert(inputData.contResolution > 0);
00049
00050 clear();
00051
00052 mContinuousResolution = inputData.contResolution;
00053 mNumDiscreteDimensions = inputData.numDiscInputs;
00054 mNumContinuousDimensions = inputData.numContInputs;
00055 mIsDynamic = isDynamic;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 mStdDevWidth = 2 / (real)mContinuousResolution;
00066
00067
00068
00069
00070
00071
00072
00073
00074 if (0 == mNumDiscreteDimensions && 0 == mNumContinuousDimensions)
00075 {
00076 mSingleState = true;
00077
00078
00079
00080 Population::init(1);
00081
00082
00083 mNeurons[0]->setFiringRate(1);
00084
00085 return;
00086 }
00087
00088
00089
00090 if (!isDynamic)
00091 {
00092 RBFInputData tempInputData;
00093 tempInputData.init(inputData.numDiscInputs,
00094 inputData.discNumOptionsData, inputData.discInputData,
00095 inputData.numContInputs, inputData.contResolution,
00096 inputData.contCircularData, inputData.contInputData);
00097 unsigned numStates = tempInputData.computeNumUniqueStates(
00098 inputData.contResolution);
00099 for (unsigned int i = 0; i < numStates; ++i)
00100 {
00101 tempInputData.setToUniqueState(i, numStates,
00102 inputData.contResolution);
00103 makeNewRBF(tempInputData);
00104 }
00105 }
00106
00107
00108
00109
00110 }
00111
00112 void RBFPopulation::resetShortTermMemory()
00113 {
00114 Population::resetShortTermMemory();
00115
00116
00117 mActiveNeurons.clear();
00118
00119 if (mSingleState)
00120 {
00121
00122 mNeurons[0]->setFiringRate(1);
00123 }
00124 }
00125
00126 void RBFPopulation::clear()
00127 {
00128 Population::clear();
00129 }
00130
00131 void RBFPopulation::updateFiringRatesRBF(const RBFInputData& inputData,
00132 bool allowDynamicRBFCreation)
00133 {
00134 mActiveNeurons.clear();
00135
00136 if (mSingleState)
00137 {
00138
00139
00140
00141
00142 mActiveNeurons.push_back(mNeurons.back());
00143 return;
00144 }
00145
00146
00147
00148 bool needNewRBF = true;
00149
00150 unsigned int numRBFs = (unsigned int)mNeurons.size();
00151 for (unsigned int i = 0; i < numRBFs; ++i)
00152 {
00153 RBFNeuron* neuron = static_cast<RBFNeuron*>(mNeurons[i]);
00154 RBFActivationCode code = neuron->updateFiringRate(inputData);
00155
00156 if (HIGH_ACTIVATION == code)
00157 {
00158 needNewRBF = false;
00159
00160
00161 mActiveNeurons.push_back(neuron);
00162 }
00163 else if (LOW_ACTIVATION == code)
00164 {
00165
00166 mActiveNeurons.push_back(neuron);
00167 }
00168 }
00169
00170 if (allowDynamicRBFCreation && mIsDynamic && needNewRBF)
00171 {
00172 makeNewRBF(inputData);
00173 Neuron* newRBFNeuron = mNeurons.back();
00174 connectNewRBFToTargets(newRBFNeuron);
00175
00176
00177
00178 newRBFNeuron->setFiringRate(1);
00179
00180
00181 mActiveNeurons.push_back(newRBFNeuron);
00182 }
00183 }
00184
00185 void RBFPopulation::createNeuron(unsigned int id)
00186 {
00187 RBFNeuron* neuron = new RBFNeuron(id);
00188 mNeurons.push_back(neuron);
00189 }
00190
00191 void RBFPopulation::makeNewRBF(const RBFInputData& inputData)
00192 {
00193
00194 createNeuron((unsigned int)mNeurons.size());
00195 RBFNeuron* newRBFNeuron = static_cast<RBFNeuron*>(mNeurons.back());
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 real newRBFThreshold = 2 / (real)mContinuousResolution;
00206
00207
00208
00209
00210
00211
00212 assert(mStdDevWidth >= (real)0.25 * newRBFThreshold);
00213
00214
00215 newRBFNeuron->init(mStdDevWidth, newRBFThreshold, inputData);
00216 }
00217
00218 void RBFPopulation::connectNewRBFToTargets(Neuron* n)
00219 {
00220
00221
00222 unsigned int numProjections = (unsigned int)mOutputProjections.size();
00223 for (unsigned int i = 0; i < numProjections; ++i)
00224 {
00225 mOutputProjections[i]->addPreNeuron(n);
00226 }
00227 }
00228
00229 unsigned int RBFPopulation::getNumActiveNeurons()const
00230 {
00231 return (unsigned int)mActiveNeurons.size();
00232 }
00233
00234 Neuron* RBFPopulation::getActiveNeuron(unsigned int i)
00235 {
00236 return mActiveNeurons.at(i);
00237 }
00238
00239 real RBFPopulation::computeMaxActivationSum()const
00240 {
00241
00242
00243
00244
00245
00246 real maxActivationSum = 0;
00247
00248 if (0 == mNumContinuousDimensions)
00249 {
00250
00251
00252 maxActivationSum = 1;
00253 }
00254 else
00255 {
00256
00257
00258
00259
00260 maxActivationSum = globals::pow((real)2.5,
00261 (real)mNumContinuousDimensions);
00262
00268
00269
00270
00271
00272 }
00273
00274 return maxActivationSum;
00275 }
00276 }