Mercurial > hg > multitrack-audio-matcher
comparison bayesianArraySrc/BayesianArrayStructure.cpp @ 5:5ef00d1dfe68
cross update checked and working
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Thu, 02 Feb 2012 12:45:36 +0000 |
parents | 45b5cf9be377 |
children | 746a5af43c02 |
comparison
equal
deleted
inserted
replaced
4:45b5cf9be377 | 5:5ef00d1dfe68 |
---|---|
27 speedEstimate = speedPriorValue; | 27 speedEstimate = speedPriorValue; |
28 | 28 |
29 lastEventTime = 0;//ofGetElapsedTimeMillis(); | 29 lastEventTime = 0;//ofGetElapsedTimeMillis(); |
30 | 30 |
31 tmpBestEstimate = 0; | 31 tmpBestEstimate = 0; |
32 crossUpdateTimeThreshold = 60000; | 32 crossUpdateTimeThreshold = 60; |
33 priorWidth = 20; | 33 priorWidth = 20; |
34 | 34 |
35 } | 35 } |
36 | 36 |
37 BayesianArrayStructure::BayesianArrayStructure(int length){ | 37 BayesianArrayStructure::BayesianArrayStructure(int length){ |
278 printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); | 278 printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); |
279 prior.zero();//kill prior | 279 prior.zero();//kill prior |
280 | 280 |
281 // calculateNewPriorOffset(timeDifference);//dioesnt do anything | 281 // calculateNewPriorOffset(timeDifference);//dioesnt do anything |
282 | 282 |
283 printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); | 283 // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); |
284 | 284 |
285 if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) | 285 if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) |
286 complexCrossUpdate(timeDifferenceInPositionVectorUnits); | 286 complexCrossUpdate(timeDifferenceInPositionVectorUnits); |
287 else | 287 else |
288 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); | 288 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); |
293 | 293 |
294 } | 294 } |
295 | 295 |
296 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ | 296 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ |
297 | 297 |
298 | |
299 printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits); | |
300 | |
298 int distanceMoved, newPriorIndex; | 301 int distanceMoved, newPriorIndex; |
299 | 302 |
300 double speedValue = relativeSpeedPosterior.offset; | 303 double speedValue = relativeSpeedPosterior.offset; |
301 | 304 |
302 for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ | 305 for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ |
303 | 306 |
304 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | 307 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 |
305 | 308 |
306 //so we have moved | 309 //so we have moved |
307 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value | 310 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value |
308 | 311 // printf("Speed value %f time %f gives distance %i\n", speedValue, timeDifferenceInPositionVectorUnits, distanceMoved); |
312 | |
309 if (relativeSpeedPosterior.array[i] != 0){ | 313 if (relativeSpeedPosterior.array[i] != 0){ |
310 | 314 |
311 double speedContribution = relativeSpeedPosterior.array[i]; | 315 double speedContribution = relativeSpeedPosterior.array[i]; |
312 | 316 |
313 // printf("speed [%i](val[%f]) gives %f moved %i in %f units \n", i, relativeSpeedPosterior.array[i], speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); | 317 // printf("speed [%i](val[%f]) gives %f moved %i in %f units \n", i, relativeSpeedPosterior.array[i], speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); |
314 | 318 |
315 //1/2/12 deleted line | 319 //1/2/12 deleted line |
316 newPriorIndex = posterior.offset - prior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed | 320 newPriorIndex = posterior.offset - prior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed |
317 int postIndex = 0; | 321 int postIndex = 0;//index of posterior that will contribute |
322 | |
318 while (postIndex < posterior.arraySize && newPriorIndex < prior.arraySize){ | 323 while (postIndex < posterior.arraySize && newPriorIndex < prior.arraySize){ |
319 | 324 |
320 //did use a for loop | 325 //did use a for loop |
321 // for (postIndex = 0;postIndex < posterior.arraySize;postIndex++){ | 326 // for (postIndex = 0;postIndex < posterior.arraySize;postIndex++){ |
322 //old posterior contributing to new prior | 327 //old posterior contributing to new prior |
333 postIndex++; | 338 postIndex++; |
334 }//end for. now while | 339 }//end for. now while |
335 | 340 |
336 | 341 |
337 }//if not zero | 342 }//if not zero |
338 speedValue += relativeSpeedPosterior.scalar; | 343 |
339 //optimised line | 344 speedValue += relativeSpeedPosterior.scalar;//optimised line |
340 //as we wanted: | 345 //as we wanted: |
341 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | 346 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 |
347 | |
342 }//end speed | 348 }//end speed |
349 | |
350 | |
351 printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate())); | |
343 } | 352 } |
344 | 353 |
345 | 354 |
346 | 355 |
347 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ | 356 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ |