comparison bayesianArraySrc/BayesianArrayStructure.cpp @ 8:572564b7cb85

added calculation posterior into both onset and pitch processes
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 03 Feb 2012 13:28:59 +0000
parents 33dedfe32893
children cbadb9d05d29
comparison
equal deleted inserted replaced
7:33dedfe32893 8:572564b7cb85
163 setNewDistributionOffsets(0); 163 setNewDistributionOffsets(0);
164 164
165 int zeroIndex = posterior.getRealTermsAsIndex(0); 165 int zeroIndex = posterior.getRealTermsAsIndex(0);
166 printf("ZERO INDEX %i\n", zeroIndex); 166 printf("ZERO INDEX %i\n", zeroIndex);
167 167
168 posterior.addGaussianShapeFromRealTime(0, 60, 1);//one way to add at x msec 168 posterior.addGaussianShapeFromRealTime(0, 300, 1);//one way to add at x msec
169 // posterior.addGaussianShape(posterior.getRealTermsAsIndex(10), 50, 1);//alternative way 169 // posterior.addGaussianShape(posterior.getRealTermsAsIndex(10), 50, 1);//alternative way
170 170
171 //posterior.addToIndex(0, 1);
172 likelihood.addConstant(1); 171 likelihood.addConstant(1);
173 172
174 updateCounter = 0; 173 updateCounter = 0;
175 174
176 175
297 printPostOffset(); 296 printPostOffset();
298 297
299 updateBestEstimate(timeDifference); 298 updateBestEstimate(timeDifference);
300 lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); 299 lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed);
301 300
302 301 //set TARGETS - commented tenmporarily
303 setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); 302 setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2)));
303
304 crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference); 304 crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference);
305 305
306 //i.e. using the same offset as prior 306 //i.e. using the same offset as prior
307 posterior.offset = prior.offset;// 307 posterior.offset = prior.offset;//
308 308
313 313
314 } 314 }
315 315
316 316
317 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ 317 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){
318
318 //set the cutoff for offset of position first! XXX 319 //set the cutoff for offset of position first! XXX
319
320 // printf("time difference %f, ", timeDifference);
321 320
322 double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; 321 double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar;
323 322
324 printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); 323 printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits);
325 prior.zero();//kill prior 324 prior.zero();//kill prior
333 else 332 else
334 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); 333 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits);
335 334
336 335
337 updateCounter++; 336 updateCounter++;
338 prior.renormalise(); 337 prior.renormalise();//not strictly necessary??
339 338
340 } 339 }
341 340
342 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ 341 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){
343 342
399 398
400 399
401 400
402 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ 401 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){
403 402
403
404 int distanceMoved, newPriorIndex; 404 int distanceMoved, newPriorIndex;
405 405 double speedIndex = getSpeedEstimateIndex();
406 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.integratedEstimate); 406 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(speedIndex);
407
408 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.integratedEstimate);
409
407 //so for scalar 0.01, 50 -> speed value of 0.5 410 //so for scalar 0.01, 50 -> speed value of 0.5
408 double speedContribution = relativeSpeedPosterior.array[relativeSpeedPosterior.integratedEstimate]; 411 double speedContribution = relativeSpeedPosterior.array[(int)round(speedIndex)];
409 //so we have moved 412 //so we have moved
410 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value 413 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value
411 // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); 414
415 // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits);
412 416
413 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ 417 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){
414 //old posterior contributing to new prior 418 //old posterior contributing to new prior
415 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; 419 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved;
416 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ 420 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){