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 "RBFInputData.h"
00025 #include "Observation.h"
00026
00027 namespace verve
00028 {
00029 RBFInputData::RBFInputData()
00030 {
00031 numDiscInputs = 0;
00032 discNumOptionsData = NULL;
00033 discInputData = NULL;
00034 numContInputs = 0;
00035 contResolution = 0;
00036 contCircularData = NULL;
00037 contInputData = NULL;
00038 }
00039
00040 RBFInputData::~RBFInputData()
00041 {
00042 if (discNumOptionsData)
00043 {
00044 delete [] discNumOptionsData;
00045 }
00046
00047 if (discInputData)
00048 {
00049 delete [] discInputData;
00050 }
00051
00052 if (contCircularData)
00053 {
00054 delete [] contCircularData;
00055 }
00056
00057 if (contInputData)
00058 {
00059 delete [] contInputData;
00060 }
00061 }
00062
00063 void RBFInputData::init(unsigned int numDiscreteInputs,
00064 const unsigned int* discreteNumOptionsData,
00065 const unsigned int* discreteInputData,
00066 unsigned int numContinuousInputs,
00067 unsigned int continuousResolution,
00068 const bool* continuousCircularData,
00069 const real* continuousInputData)
00070 {
00071 if (discNumOptionsData)
00072 {
00073 delete [] discNumOptionsData;
00074 }
00075
00076 if (discInputData)
00077 {
00078 delete [] discInputData;
00079 }
00080
00081 if (contCircularData)
00082 {
00083 delete [] contCircularData;
00084 }
00085
00086 if (contInputData)
00087 {
00088 delete [] contInputData;
00089 }
00090
00091 numDiscInputs = numDiscreteInputs;
00092 discNumOptionsData = new unsigned int[numDiscreteInputs];
00093 discInputData = new unsigned int[numDiscreteInputs];
00094 for (unsigned int i = 0; i < numDiscreteInputs; ++i)
00095 {
00096 discNumOptionsData[i] = discreteNumOptionsData[i];
00097 discInputData[i] = discreteInputData[i];
00098 }
00099
00100 numContInputs = numContinuousInputs;
00101 contResolution = continuousResolution;
00102 contCircularData = new bool[numContinuousInputs];
00103 contInputData = new real[numContinuousInputs];
00104 for (unsigned int i = 0; i < numContinuousInputs; ++i)
00105 {
00106 contCircularData[i] = continuousCircularData[i];
00107 contInputData[i] = continuousInputData[i];
00108 }
00109 }
00110
00111 void RBFInputData::init(const Observation& obs)
00112 {
00113 if (discNumOptionsData)
00114 {
00115 delete [] discNumOptionsData;
00116 }
00117
00118 if (discInputData)
00119 {
00120 delete [] discInputData;
00121 }
00122
00123 if (contCircularData)
00124 {
00125 delete [] contCircularData;
00126 }
00127
00128 if (contInputData)
00129 {
00130 delete [] contInputData;
00131 }
00132
00133 numDiscInputs = obs.getNumDiscreteInputs();
00134 discNumOptionsData = new unsigned int[numDiscInputs];
00135 discInputData = new unsigned int[numDiscInputs];
00136 for (unsigned int i = 0; i < numDiscInputs; ++i)
00137 {
00138 discNumOptionsData[i] = obs.getDiscreteInputNumOptions(i);
00139 discInputData[i] = obs.getDiscreteValue(i);
00140 }
00141
00142 numContInputs = obs.getNumContinuousInputs();
00143 contResolution = obs.getContinuousResolution();
00144 contCircularData = new bool[numContInputs];
00145 contInputData = new real[numContInputs];
00146 for (unsigned int i = 0; i < numContInputs; ++i)
00147 {
00148 contCircularData[i] = obs.getContinuousInputIsCircular(i);
00149 contInputData[i] = obs.getContinuousValue(i);
00150 }
00151 }
00152
00153 void RBFInputData::zeroInputData()
00154 {
00155 for (unsigned int i = 0; i < numDiscInputs; ++i)
00156 {
00157 discInputData[i] = 0;
00158 }
00159
00160 for (unsigned int i = 0; i < numContInputs; ++i)
00161 {
00162 contInputData[i] = 0;
00163 }
00164 }
00165
00166 void RBFInputData::copyInputData(const unsigned int* discreteInputData,
00167 const real* continuousInputData)
00168 {
00169 for (unsigned int i = 0; i < numDiscInputs; ++i)
00170 {
00171 discInputData[i] = discreteInputData[i];
00172 }
00173
00174 for (unsigned int i = 0; i < numContInputs; ++i)
00175 {
00176 contInputData[i] = continuousInputData[i];
00177 }
00178 }
00179
00180 unsigned int RBFInputData::computeNumUniqueStates(
00181 unsigned int continuousResolution)const
00182 {
00183
00184
00185 unsigned int numStates = (unsigned int)globals::pow(
00186 (real)continuousResolution, (real)numContInputs);
00187
00188 if (0 == continuousResolution)
00189 {
00190
00191 numStates = 1;
00192 }
00193
00194 for (unsigned int i = 0; i < numDiscInputs; ++i)
00195 {
00196 numStates *= discNumOptionsData[i];
00197 }
00198
00199 return numStates;
00200 }
00201
00202 void RBFInputData::setToUniqueState(unsigned int index,
00203 unsigned int numStates, unsigned int continuousResolution)
00204 {
00205
00206
00207 if (0 == numDiscInputs && 0 == numContInputs
00208 || numContInputs > 0 && 0 == continuousResolution)
00209 {
00210 return;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219 for (unsigned int i = 0; i < numDiscInputs + numContInputs; ++i)
00220 {
00221 unsigned int value = 0;
00222
00223
00224
00225
00226 if (i < numDiscInputs)
00227 {
00228
00229 numStates = numStates / discNumOptionsData[i];
00230 }
00231 else
00232 {
00233
00234 numStates = numStates / continuousResolution;
00235 }
00236
00237 while (index >= numStates)
00238 {
00239 value += 1;
00240 index -= numStates;
00241 }
00242
00243
00244 if (i < numDiscInputs)
00245 {
00246
00247 discInputData[i] = value;
00248 }
00249 else
00250 {
00251 unsigned int continuousIndex = i - numDiscInputs;
00252
00253
00254 if (1 == continuousResolution)
00255 {
00256 contInputData[continuousIndex] = 0;
00257 }
00258 else
00259 {
00260
00261
00262
00263
00264
00265
00266
00267
00268 if (contCircularData[continuousIndex])
00269 {
00270 real continuousIncrement =
00271 2 / (real)continuousResolution;
00272 contInputData[continuousIndex] = -1 +
00273 (verve::real)0.5 * continuousIncrement +
00274 value * continuousIncrement;
00275 }
00276 else
00277 {
00278 real continuousIncrement =
00279 2 / (real)(continuousResolution - 1);
00280 contInputData[continuousIndex] = -1 +
00281 + value * continuousIncrement;
00282 }
00283 }
00284 }
00285 }
00286 }
00287 }