Mercurial > hg > midi-score-follower
comparison src/BayesianArrayStructure.cpp @ 4:4a8e6a6cd224
optimised draw function in dynamic vector class. Added Gaussian lookup but not yet used.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Fri, 19 Aug 2011 15:53:04 +0100 |
parents | de86d77f2612 |
children | 75dcd1308658 |
comparison
equal
deleted
inserted
replaced
3:de86d77f2612 | 4:4a8e6a6cd224 |
---|---|
28 tmpPrior.addGaussianShape(100, 40, 1); | 28 tmpPrior.addGaussianShape(100, 40, 1); |
29 tmpPrior.addGaussianShape(200, 10, 0.2); | 29 tmpPrior.addGaussianShape(200, 10, 0.2); |
30 tmpPrior.translateDistribution(20); | 30 tmpPrior.translateDistribution(20); |
31 */ | 31 */ |
32 tmpBestEstimate = 0; | 32 tmpBestEstimate = 0; |
33 crossUpdateTimeThreshold = 100; | |
33 } | 34 } |
34 | 35 |
35 BayesianArrayStructure::BayesianArrayStructure(int length){ | 36 BayesianArrayStructure::BayesianArrayStructure(int length){ |
36 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length); | 37 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length); |
37 //this constructor isnt called it seems | 38 //this constructor isnt called it seems |
248 | 249 |
249 // printf("time difference %f, ", timeDifference); | 250 // printf("time difference %f, ", timeDifference); |
250 | 251 |
251 double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; | 252 double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; |
252 | 253 |
254 | |
253 prior.zero();//kill prior | 255 prior.zero();//kill prior |
254 calculateNewPriorOffset(timeDifference);//set new prior offset here | 256 calculateNewPriorOffset(timeDifference);//set new prior offset here |
255 | 257 |
256 for (int i = 0;i < speed.arraySize;i++){ | 258 if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) |
257 // printf("[%i] %f\n", i, speed.array[i]); | 259 complexCrossUpdate(timeDifferenceInPositionVectorUnits); |
258 //set speed | 260 else |
259 double speedValue = speed.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | 261 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); |
260 | 262 |
263 | |
264 updateCounter++; | |
265 prior.renormalise(); | |
266 | |
267 } | |
268 | |
269 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ | |
270 int distanceMoved, newPriorIndex; | |
271 for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ | |
272 | |
273 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | |
274 | |
261 //so we have moved | 275 //so we have moved |
262 int distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value | 276 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value |
263 | 277 |
264 if (speed.array[i] != 0){ | 278 if (relativeSpeedPosterior.array[i] != 0){ |
279 double speedContribution = relativeSpeedPosterior.array[i]; | |
280 // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); | |
265 | 281 |
266 // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); | 282 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ |
267 | 283 //old posterior contributing to new prior |
268 for (int postIndex = 0;postIndex < position.arraySize;postIndex++){ | 284 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; |
269 //old posterior contributing to new prior | 285 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ |
270 int newPriorIndex = postIndex + position.offset - prior.offset + distanceMoved; | 286 prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); |
271 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ | 287 } |
272 prior.addToIndex(newPriorIndex, position.array[postIndex]*speed.array[i]); | 288 |
273 // printf("adding [%i] : %f\n", newPriorIndex, posterior.array[postIndex]*speed.array[i]); | |
274 } | 289 } |
275 | |
276 } | |
277 | 290 |
278 }//if not zero | 291 }//if not zero |
279 }//end speed | 292 }//end speed |
280 updateCounter++; | 293 } |
281 prior.renormalise(); | 294 |
282 | 295 |
283 } | 296 |
284 | 297 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ |
298 int distanceMoved, newPriorIndex; | |
299 | |
300 | |
301 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate);//using max value only | |
302 //so for scalar 0.01, 50 -> speed value of 0.5 | |
303 double speedContribution = relativeSpeedPosterior.array[relativeSpeedPosterior.MAPestimate]; | |
304 //so we have moved | |
305 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value | |
306 // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); | |
307 | |
308 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ | |
309 //old posterior contributing to new prior | |
310 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; | |
311 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ | |
312 prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); | |
313 } | |
314 | |
315 } | |
316 | |
317 } | |
285 | 318 |
286 void BayesianArrayStructure::addGaussianNoiseToSpeedPosterior(const double& std_dev){ | 319 void BayesianArrayStructure::addGaussianNoiseToSpeedPosterior(const double& std_dev){ |
287 tmpPosteriorForStorage.copyFromDynamicVector(relativeSpeedPosterior); | 320 tmpPosteriorForStorage.copyFromDynamicVector(relativeSpeedPosterior); |
288 | 321 |
289 for (int i = 0;i < relativeSpeedPosterior.length;i++){ | 322 for (int i = 0;i < relativeSpeedPosterior.length;i++){ |