comparison src/BayesianArrayStructure.cpp @ 22:9860abc92a30

follower has confidence measure now just using best match. Difficulty in visualising the speed likelihood fn
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Wed, 30 Nov 2011 11:48:35 +0000
parents 11e3119ce6b4
children 032edf186a68
comparison
equal deleted inserted replaced
21:11e3119ce6b4 22:9860abc92a30
13 #include "BayesianArrayStructure.h" 13 #include "BayesianArrayStructure.h"
14 14
15 BayesianArrayStructure::BayesianArrayStructure(){ 15 BayesianArrayStructure::BayesianArrayStructure(){
16 printf("Bayesian structure: DeFault constructor called"); 16 printf("Bayesian structure: DeFault constructor called");
17 17
18 relativeSpeedLikelihoodStdDev = 5.0;
19
18 prior.createVector(1); 20 prior.createVector(1);
19 likelihood.createVector(1); 21 likelihood.createVector(1);
20 posterior.createVector(1); 22 posterior.createVector(1);
21 23 tmpPrior.createVector(1);
24
22 speedPriorValue = 1.0; 25 speedPriorValue = 1.0;
23 speedEstimate = speedPriorValue; 26 speedEstimate = speedPriorValue;
24 27
25 lastEventTime = 0;//ofGetElapsedTimeMillis(); 28 lastEventTime = 0;//ofGetElapsedTimeMillis();
26 29
27 tmpBestEstimate = 0; 30 tmpBestEstimate = 0;
28 crossUpdateTimeThreshold = 100; 31 crossUpdateTimeThreshold = 60;
29 priorWidth = 50; 32 priorWidth = 50;
30 } 33 }
31 34
32 BayesianArrayStructure::BayesianArrayStructure(int length){ 35 BayesianArrayStructure::BayesianArrayStructure(int length){
33 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length); 36 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length);
34 //this constructor isnt called it seems 37 //this constructor isnt called it seems
35 prior.createVector(length); 38 prior.createVector(length);
36 likelihood.createVector(length); 39 likelihood.createVector(length);
37 posterior.createVector(length); 40 posterior.createVector(length);
41 tmpPrior.createVector(length);
38 42
39 lastEventTime = 0; 43 lastEventTime = 0;
40 usingIntegratedTempoEstimate = false;//use max index 44 usingIntegratedTempoEstimate = true;//use max index
41 45
42 } 46 }
43 47
44 48
45 49
47 printf("BAYESIAN STRUCTURE size is : %i\n", length); 51 printf("BAYESIAN STRUCTURE size is : %i\n", length);
48 52
49 prior.createVector(length); 53 prior.createVector(length);
50 likelihood.createVector(length); 54 likelihood.createVector(length);
51 posterior.createVector(length); 55 posterior.createVector(length);
52
53 56
54 acceleration.createVector(length); 57 acceleration.createVector(length);
55 58
56 } 59 }
57 60
74 posterior.zero(); 77 posterior.zero();
75 78
76 posterior.addToIndex(0, 1); 79 posterior.addToIndex(0, 1);
77 posterior.renormalise(); 80 posterior.renormalise();
78 81
82
79 //acceleration.addGaussianShape(2000, 20, 0.8); 83 //acceleration.addGaussianShape(2000, 20, 0.8);
80 84
81 } 85 }
82 86
83 void BayesianArrayStructure::setSpeedPrior(double f){ 87 void BayesianArrayStructure::setSpeedPrior(double f){
97 101
98 relativeSpeedPrior.createVector(length); 102 relativeSpeedPrior.createVector(length);
99 relativeSpeedLikelihood.createVector(length); 103 relativeSpeedLikelihood.createVector(length);
100 relativeSpeedPosterior.createVector(length); 104 relativeSpeedPosterior.createVector(length);
101 tmpPosteriorForStorage.createVector(length); 105 tmpPosteriorForStorage.createVector(length);
106
107 tmpPrior.createVector(length);
108 tmpPrior.zero();
109 tmpPrior.addConstant(0.1);
110 tmpPrior.addGaussianShape(130, 10, 0.2);
111 printf("TMP PRIOR TEST VECTOR\n");
112 tmpPrior.printArray();
102 113
103 114
104 } 115 }
105 116
106 void BayesianArrayStructure::setRelativeSpeedScalar(double f){ 117 void BayesianArrayStructure::setRelativeSpeedScalar(double f){
407 //speedratio is speed of played relative to the recording 418 //speedratio is speed of played relative to the recording
408 419
409 double index = relativeSpeedLikelihood.getRealTermsAsIndex(speedRatio); 420 double index = relativeSpeedLikelihood.getRealTermsAsIndex(speedRatio);
410 // printf("index of likelihood would be %f for ratio %f\n", index, speedRatio); 421 // printf("index of likelihood would be %f for ratio %f\n", index, speedRatio);
411 if (index >= 0 && index < relativeSpeedPrior.length){ 422 if (index >= 0 && index < relativeSpeedPrior.length){
412 relativeSpeedLikelihood.addGaussianShape(index , 5, matchFactor); 423 relativeSpeedLikelihood.addGaussianShape(index , relativeSpeedLikelihoodStdDev, matchFactor);
413 } 424 }
414 } 425 }
415 426
416 427
428
417 void BayesianArrayStructure::updateTempoDistribution(){ 429 void BayesianArrayStructure::updateTempoDistribution(){
418 430
419 //copy posterior to prior 431 //copy posterior to prior
420 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); 432 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior);
421 433
459 likelihood.drawVector(0, displaySize); 471 likelihood.drawVector(0, displaySize);
460 ofSetColor(255,0,255); 472 ofSetColor(255,0,255);
461 posterior.drawVector(0, displaySize); 473 posterior.drawVector(0, displaySize);
462 474
463 475
464 // ofSetColor(255,255,255);
465 // tmpPrior.drawVector(0,300);
466 476
467 } 477 }
468 478
469 479
470 void BayesianArrayStructure::drawTempoArrays(){ 480 void BayesianArrayStructure::drawTempoArrays(){
471 ofSetColor(0,0,255); 481 ofSetColor(0,0,255);
472 // relativeSpeedPrior.drawVector(0, relativeSpeedPrior.arraySize); 482 // relativeSpeedPrior.drawVector(0, relativeSpeedPrior.arraySize);
473 483
474 ofSetColor(255,0,255); 484 ofSetColor(0,150,255);
475 relativeSpeedLikelihood.drawVector(0, relativeSpeedLikelihood.arraySize); 485 relativeSpeedLikelihood.drawVector(0, relativeSpeedLikelihood.arraySize);
486
476 // relativeSpeedLikelihood.drawConstrainedVector(0, 199, 0, 1000);// relativeSpeedLikelihood.arraySize); 487 // relativeSpeedLikelihood.drawConstrainedVector(0, 199, 0, 1000);// relativeSpeedLikelihood.arraySize);
477 ofSetColor(255,0,0); 488 ofSetColor(255,0,0);
478 relativeSpeedPosterior.drawVector(0, relativeSpeedPosterior.arraySize); 489 relativeSpeedPosterior.drawVector(0, relativeSpeedPosterior.arraySize);
479 490
480 // ofSetColor(0,0,255); 491 // ofSetColor(0,0,255);
481 // tmpPosteriorForStorage.drawVector(0, tmpPosteriorForStorage.arraySize); 492 // tmpPosteriorForStorage.drawVector(0, tmpPosteriorForStorage.arraySize);
482 493
483 ofSetColor(255,255, 255); 494 ofSetColor(255,255, 255);
484 ofLine(screenWidth/2, 0, screenWidth/2, ofGetHeight());//middle of screen 495 ofLine(screenWidth/2, 0, screenWidth/2, ofGetHeight());//middle of screen
485 496
486 ofSetColor(155,255, 0); 497 ofSetColor(25, 0, 250);
487 double fractionOfScreen = ((double)relativeSpeedPosterior.integratedEstimate / relativeSpeedPosterior.length); 498 double fractionOfScreen = ((double)relativeSpeedPosterior.integratedEstimate / relativeSpeedPosterior.length);
488 ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight()); 499 ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight());
489 500
490 ofSetColor(0,255, 255); 501 ofSetColor(255, 0, 20);
491 fractionOfScreen = ((double)relativeSpeedPosterior.MAPestimate / relativeSpeedPosterior.length); 502 fractionOfScreen = ((double)relativeSpeedPosterior.MAPestimate / relativeSpeedPosterior.length);
492 ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight()); 503 ofLine(screenWidth * fractionOfScreen, 0, screenWidth * fractionOfScreen, ofGetHeight());
504
493 505
494 } 506 }
495 507
496 508
497 void BayesianArrayStructure::drawArraysRelativeToTimeframe(const double& startTimeMillis, const double& endTimeMillis){ 509 void BayesianArrayStructure::drawArraysRelativeToTimeframe(const double& startTimeMillis, const double& endTimeMillis){
522 string relativeString = " offset "+ofToString(prior.offset, 1);//starttimes("+ofToString(startTimeMillis)+", "+ofToString(endTimeMillis); 534 string relativeString = " offset "+ofToString(prior.offset, 1);//starttimes("+ofToString(startTimeMillis)+", "+ofToString(endTimeMillis);
523 relativeString += ": index "+ofToString(startArrayIndex)+" , "+ofToString(endArrayIndex)+" ["; 535 relativeString += ": index "+ofToString(startArrayIndex)+" , "+ofToString(endArrayIndex)+" [";
524 // relativeString += ofToString(prior.getIndexInRealTerms(endArrayIndex), 3)+"] (sc-width:"+ofToString(screenWidthMillis, 1)+") "; 536 // relativeString += ofToString(prior.getIndexInRealTerms(endArrayIndex), 3)+"] (sc-width:"+ofToString(screenWidthMillis, 1)+") ";
525 relativeString += " mapped to screen "+ofToString(startScreenPosition)+" , "+ofToString(endScreenPosition); 537 relativeString += " mapped to screen "+ofToString(startScreenPosition)+" , "+ofToString(endScreenPosition);
526 // ofDrawBitmapString(relativeString, 100, 180); 538 // ofDrawBitmapString(relativeString, 100, 180);
527 539
528 ofSetColor(255, 255, 0); 540
541
542 ofSetColor(100,100,100);//255, 255, 0);
529 likelihood.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition); 543 likelihood.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition);
530 544
531 ofSetColor(0,0,200); 545 // ofSetColor(0,0,200);
546 ofSetColor(170,170,170);//00,200);
532 prior.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition); 547 prior.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition);
533 548
534 ofSetColor(200, 0, 0); 549 ofSetColor(0,0,150);
550 // ofSetColor(200, 0, 0);
535 posterior.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition); 551 posterior.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition);
536 552
537 553
538 // ofSetColor(0, 200, 255); 554 // ofSetColor(0, 200, 255);
539 // acceleration.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition); 555 // acceleration.drawConstrainedVector(startArrayIndex, endArrayIndex, startScreenPosition, endScreenPosition);