Mercurial > hg > multitrack-audio-matcher
comparison bayesianArraySrc/BayesianArrayStructure.cpp @ 11:9a2b008c4706
Priors for each channel and scrolling projection for new prior is added
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 05 Feb 2012 00:00:58 +0000 |
parents | cbadb9d05d29 |
children | 780def3a1f36 |
comparison
equal
deleted
inserted
replaced
10:cbadb9d05d29 | 11:9a2b008c4706 |
---|---|
105 relativeSpeedPosterior.zero(); | 105 relativeSpeedPosterior.zero(); |
106 relativeSpeedPosterior.addGaussianShape(index, priorWidth, 0.8); | 106 relativeSpeedPosterior.addGaussianShape(index, priorWidth, 0.8); |
107 printf("speed adding to index for 1 = %f\n", relativeSpeedPosterior.getRealTermsAsIndex(1)); | 107 printf("speed adding to index for 1 = %f\n", relativeSpeedPosterior.getRealTermsAsIndex(1)); |
108 relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1), 0.1); | 108 relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1), 0.1); |
109 relativeSpeedPosterior.addGaussianShapeFromRealTime(1, 3, 0.5); | 109 relativeSpeedPosterior.addGaussianShapeFromRealTime(1, 3, 0.5); |
110 | |
111 | |
112 //tmp debug test | |
113 //relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1.8), 0.15); | |
110 | 114 |
111 relativeSpeedPosterior.renormalise(); | 115 relativeSpeedPosterior.renormalise(); |
112 relativeSpeedPosterior.getMaximum(); | 116 relativeSpeedPosterior.getMaximum(); |
117 | |
118 | |
113 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); | 119 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); |
120 | |
121 | |
122 | |
114 printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); | 123 printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); |
115 | 124 |
116 } | 125 } |
117 | 126 |
118 | 127 |
660 double tmp = posterior.getMAPestimate(); | 669 double tmp = posterior.getMAPestimate(); |
661 printf(" MAP index %i post offset %f == %f ms\n", posterior.MAPestimate, posterior.offset, posterior.getIndexInRealTerms(posterior.MAPestimate)); | 670 printf(" MAP index %i post offset %f == %f ms\n", posterior.MAPestimate, posterior.offset, posterior.getIndexInRealTerms(posterior.MAPestimate)); |
662 } | 671 } |
663 | 672 |
664 //PROJECT PRIOR CODE | 673 //PROJECT PRIOR CODE |
665 /* | 674 |
666 void BayesianArrayStructure::projectDistribution(const double& newEventTime, DynamicVector& projectedPrior){ | 675 void BayesianArrayStructure::projectDistribution(const double& newEventTime, const double& newAlignmentPosition, DynamicVector& projectedPrior){ |
667 | 676 |
668 projectedPrior.copyFromDynamicVector(posterior); | 677 projectedPrior.copyFromDynamicVector(posterior); |
669 | 678 |
670 double timeDifference = newEventTime - lastEventTime; | 679 double timeDifference = newEventTime - lastEventTime; |
671 | 680 |
672 // if (timeDifference > 50 && updatingSpeedDistribution){ | 681 // if (timeDifference > 50 && updatingSpeedDistribution){ |
673 // addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.); | 682 // addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.); |
674 // } | 683 // } |
675 | 684 |
676 | 685 |
677 updateBestEstimate(timeDifference); | 686 // updateBestEstimate(timeDifference); |
678 lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); | 687 // lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); |
679 | 688 |
680 //set TARGETS - commented tenmporarily | 689 //set TARGETS - commented tenmporarily |
681 setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); | 690 |
682 | 691 //setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); |
683 crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference); | 692 projectedPrior.offset = posterior.offset;//max(0., newAlignmentPosition - (projectedPrior.scalar*projectedPrior.arraySize/2)); |
684 | 693 |
694 // int timeDifference = newEventTime - lastEventTime; | |
695 | |
696 double timeDifferenceInPositionVectorUnits = timeDifference / projectedPrior.scalar; | |
697 | |
698 // printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); | |
699 projectedPrior.zero();//kill prior | |
700 | |
701 // calculateNewPriorOffset(timeDifference);//dioesnt do anything | |
702 | |
703 // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); | |
704 | |
705 if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) | |
706 complexCrossUpdateProjection(projectedPrior, timeDifferenceInPositionVectorUnits); | |
707 else | |
708 translatePosteriorByMaximumSpeed(projectedPrior, timeDifferenceInPositionVectorUnits); | |
709 | |
710 | |
711 // updateCounter++; | |
712 projectedPrior.renormalise();//not strictly necessary?? | |
713 | |
714 | |
685 //i.e. using the same offset as prior | 715 //i.e. using the same offset as prior |
686 posterior.offset = prior.offset;// | 716 // posterior.offset = prior.offset;// |
687 | 717 |
688 // float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));// prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2)); | 718 // float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));// prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2)); |
689 // printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset); | 719 // printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset); |
690 | 720 |
691 lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis(); | 721 // lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis(); |
692 | 722 |
693 } | 723 } |
694 | 724 |
695 | 725 |
696 | 726 |
697 | 727 void BayesianArrayStructure::complexCrossUpdateProjection(DynamicVector& projectedPrior, const double& timeDifferenceInPositionVectorUnits){ |
698 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ | |
699 | |
700 //set the cutoff for offset of position first! XXX | |
701 | |
702 double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; | |
703 | |
704 printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); | |
705 prior.zero();//kill prior | |
706 | |
707 // calculateNewPriorOffset(timeDifference);//dioesnt do anything | |
708 | |
709 // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); | |
710 | |
711 if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) | |
712 complexCrossUpdate(timeDifferenceInPositionVectorUnits); | |
713 else | |
714 translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); | |
715 | |
716 | |
717 updateCounter++; | |
718 prior.renormalise();//not strictly necessary?? | |
719 | |
720 } | |
721 | |
722 void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ | |
723 | |
724 | |
725 printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits); | |
726 | 728 |
727 int distanceMoved, newPriorIndex; | 729 int distanceMoved, newPriorIndex; |
728 | 730 |
729 double speedValue = relativeSpeedPosterior.offset; | 731 double speedValue = relativeSpeedPosterior.offset; |
730 | 732 |
731 for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ | 733 for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ |
732 | 734 |
733 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | |
734 | |
735 //so we have moved | |
736 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value | 735 distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value |
737 // printf("Speed value %f time %f gives distance %i\n", speedValue, timeDifferenceInPositionVectorUnits, distanceMoved); | |
738 | 736 |
739 if (relativeSpeedPosterior.array[i] != 0){ | 737 if (relativeSpeedPosterior.array[i] != 0){ |
740 | 738 |
741 double speedContribution = relativeSpeedPosterior.array[i]; | 739 double speedContribution = relativeSpeedPosterior.array[i]; |
742 | 740 |
743 // printf("speed [%i](val[%f]) gives %f moved %i in %f units \n", i, relativeSpeedPosterior.array[i], speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); | 741 newPriorIndex = posterior.offset - projectedPrior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed |
744 | |
745 //1/2/12 deleted line | |
746 newPriorIndex = posterior.offset - prior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed | |
747 int postIndex = 0;//index of posterior that will contribute | 742 int postIndex = 0;//index of posterior that will contribute |
748 | 743 |
749 while (postIndex < posterior.arraySize && newPriorIndex < prior.arraySize){ | 744 while (postIndex < posterior.arraySize && newPriorIndex < projectedPrior.arraySize){ |
750 | 745 |
751 //did use a for loop | |
752 // for (postIndex = 0;postIndex < posterior.arraySize;postIndex++){ | |
753 //old posterior contributing to new prior | |
754 | |
755 //would use this method | 746 //would use this method |
756 //newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; | 747 //newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; |
757 | 748 |
758 if (newPriorIndex >= 0){ | 749 if (newPriorIndex >= 0){ |
759 prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); | 750 projectedPrior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); |
760 // printf("speed index %i new prior index %i post val %f speed contrib %f dist %i\n", i, newPriorIndex, posterior.array[postIndex], speedContribution, distanceMoved); | 751 // printf("speed index %i new prior index %i post val %f speed contrib %f dist %i\n", i, newPriorIndex, posterior.array[postIndex], speedContribution, distanceMoved); |
761 } | 752 } |
762 //but we actually do this for simplicity | 753 //but we actually do this for simplicity |
763 newPriorIndex++; | 754 newPriorIndex++; |
764 postIndex++; | 755 postIndex++; |
770 speedValue += relativeSpeedPosterior.scalar;//optimised line | 761 speedValue += relativeSpeedPosterior.scalar;//optimised line |
771 //as we wanted: | 762 //as we wanted: |
772 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 | 763 // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 |
773 | 764 |
774 }//end speed | 765 }//end speed |
775 | 766 |
776 | 767 } |
777 printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate())); | 768 |
778 } | 769 |
779 | 770 |
780 | 771 void BayesianArrayStructure::translatePosteriorByMaximumSpeed(DynamicVector& translatedPosterior, const double& timeDifferenceInPositionVectorUnits){ |
781 | |
782 void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ | |
783 | 772 |
784 | 773 |
785 int distanceMoved, newPriorIndex; | 774 int distanceMoved, newPriorIndex; |
786 double speedIndex = getSpeedEstimateIndex(); | 775 double speedIndex = getSpeedEstimateIndex(); |
787 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(speedIndex); | 776 double speedValue = relativeSpeedPosterior.getIndexInRealTerms(speedIndex); |
797 | 786 |
798 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ | 787 for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ |
799 //old posterior contributing to new prior | 788 //old posterior contributing to new prior |
800 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; | 789 newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; |
801 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ | 790 if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ |
802 prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); | 791 translatedPosterior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); |
803 } | 792 } |
804 | 793 |
805 } | 794 } |
806 | 795 |
807 } | 796 } |
808 */ | 797 |
809 | 798 |
810 //END PROJECT PRIOR CODE | 799 //END PROJECT PRIOR CODE |
800 | |
811 | 801 |
812 | 802 |
813 /* | 803 /* |
814 | 804 |
815 void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){ | 805 void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){ |