comparison bayesianArraySrc/BayesianArrayStructure.cpp @ 6:746a5af43c02

windowed bayesian distributions - drawn within constrained portion of the screen
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 02 Feb 2012 17:52:08 +0000
parents 5ef00d1dfe68
children 33dedfe32893
comparison
equal deleted inserted replaced
5:5ef00d1dfe68 6:746a5af43c02
244 posterior.array[i] = likelihood.array[i] * prior.array[i]; 244 posterior.array[i] = likelihood.array[i] * prior.array[i];
245 } 245 }
246 246
247 posterior.renormalise(); 247 posterior.renormalise();
248 248
249 //tmp print stuff
250 printf("After CALC");
251 printPostOffset();
252
249 } 253 }
250 254
251 255
252 double BayesianArrayStructure::getSpeedEstimateIndex(){ 256 double BayesianArrayStructure::getSpeedEstimateIndex(){
253 if (usingIntegratedTempoEstimate) 257 if (usingIntegratedTempoEstimate)
263 267
264 prior.offset = newOffset; 268 prior.offset = newOffset;
265 likelihood.offset = newOffset; 269 likelihood.offset = newOffset;
266 270
267 //posterior.offset = newOffset; 271 //posterior.offset = newOffset;
272 }
273
274
275 void BayesianArrayStructure::updateBayesianDistributions(const double& newEventTime){
276
277 //NEED TO CHECK HERE THAT THEY HAVE THE SAME OFFSETS
278 prior.copyFromDynamicVector(posterior);//try the otehr way
279
280 //bayesianStruct.copyPriorToPosterior();
281 //need to get new MAP position and set the offset of the arrays
282 //currently bestEstimate is the approx for the new MAP position
283 // int tmpMap = bayesianStruct.posterior.getMAPestimate();
284
285 double timeDifference = newEventTime - lastEventTime;
286 // printf("updating distributions at time %f diff %f offset %f tmpmap est %i\n", newEventTime, timeDifference, bayesianStruct.posterior.offset, tmpMap);
287
288 //addnoise to the tempo distribution
289 //bayesianStruct.decaySpeedDistribution(timeDifference);
290
291 if (timeDifference > 50){
292 addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.);
293 }
294
295 printPostOffset();
296
297 updateBestEstimate(timeDifference);
298 lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed);
299
300
301 setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2)));
302 crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference);
303
304 //i.e. using the same offset as prior
305 posterior.offset = prior.offset;//
306
307 // float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));// prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));
308 // printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset);
309
310 lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis();
311
268 } 312 }
269 313
270 314
271 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ 315 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){
272 //set the cutoff for offset of position first! XXX 316 //set the cutoff for offset of position first! XXX
600 } 644 }
601 645
602 } 646 }
603 647
604 648
649 void BayesianArrayStructure::printPostOffset(){
650 double tmp = posterior.getMAPestimate();
651 printf(" MAP index %i post offset %f == %f ms\n", posterior.MAPestimate, posterior.offset, posterior.getIndexInRealTerms(posterior.MAPestimate));
652 }
653
605 /* 654 /*
606 655
607 void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){ 656 void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){
608 //speedratio is speed of played relative to the recording 657 //speedratio is speed of played relative to the recording
609 658