Mercurial > hg > multitrack-audio-matcher
diff bayesianArraySrc/BayesianArrayStructure.cpp @ 10:cbadb9d05d29
Using timestamps for the scrolling alignment time
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sat, 04 Feb 2012 19:59:27 +0000 |
parents | 572564b7cb85 |
children | 9a2b008c4706 |
line wrap: on
line diff
--- a/bayesianArraySrc/BayesianArrayStructure.cpp Fri Feb 03 17:53:14 2012 +0000 +++ b/bayesianArraySrc/BayesianArrayStructure.cpp Sat Feb 04 19:59:27 2012 +0000 @@ -211,7 +211,7 @@ void BayesianArrayStructure::updateBestEstimate(const double& timeDifference){ // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;// double tmp = bestEstimate; - printf("best est routine: posterior offset %f\n", posterior.offset); +// printf("best est routine: posterior offset %f\n", posterior.offset); double timeDiff = timeDifference; @@ -232,10 +232,12 @@ speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimateIndex); bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate; - printf("best estimate update from %f to %f; time diff %f MAP %i = %f ms speed index %f est %f SpeedxTime %f\n", tmp, bestEstimate, timeDiff, - posterior.MAPestimate, posterior.getIndexInRealTerms(posterior.MAPestimate), speedEstimateIndex, speedEstimate, timeDiff*speedEstimate); +// printf("best estimate update from %f to %f; time diff %f MAP %i = %f ms speed index %f est %f SpeedxTime %f\n", tmp, bestEstimate, timeDiff, +// posterior.MAPestimate, posterior.getIndexInRealTerms(posterior.MAPestimate), speedEstimateIndex, speedEstimate, timeDiff*speedEstimate); + printf("BEST ESTIMATE %f\n", bestEstimate); } + void BayesianArrayStructure::calculatePosterior(){ //posterior.doProduct(prior, likelihood); assert(posterior.offset == prior.offset); @@ -284,7 +286,7 @@ // int tmpMap = bayesianStruct.posterior.getMAPestimate(); double timeDifference = newEventTime - lastEventTime; -// printf("updating distributions at time %f diff %f offset %f tmpmap est %i\n", newEventTime, timeDifference, bayesianStruct.posterior.offset, tmpMap); + printf("updating distributions at time %f diff %f offset %f\n", newEventTime, timeDifference, posterior.offset); //addnoise to the tempo distribution //bayesianStruct.decaySpeedDistribution(timeDifference); @@ -314,6 +316,8 @@ } + + void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ //set the cutoff for offset of position first! XXX @@ -657,6 +661,155 @@ printf(" MAP index %i post offset %f == %f ms\n", posterior.MAPestimate, posterior.offset, posterior.getIndexInRealTerms(posterior.MAPestimate)); } +//PROJECT PRIOR CODE +/* +void BayesianArrayStructure::projectDistribution(const double& newEventTime, DynamicVector& projectedPrior){ + + projectedPrior.copyFromDynamicVector(posterior); + + double timeDifference = newEventTime - lastEventTime; + +// if (timeDifference > 50 && updatingSpeedDistribution){ +// addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.); +// } + + + updateBestEstimate(timeDifference); + lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); + + //set TARGETS - commented tenmporarily + setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); + + crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference); + + //i.e. using the same offset as prior + posterior.offset = prior.offset;// + + // float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));// prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2)); + // printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset); + + lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis(); + +} + + + + +void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){ + + //set the cutoff for offset of position first! XXX + + double timeDifferenceInPositionVectorUnits = timeDifference / prior.scalar; + + printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); + prior.zero();//kill prior + + // calculateNewPriorOffset(timeDifference);//dioesnt do anything + + // printf("new prior offset %f and post offset %f\n", prior.offset, posterior.offset); + + if (timeDifferenceInPositionVectorUnits > crossUpdateTimeThreshold) + complexCrossUpdate(timeDifferenceInPositionVectorUnits); + else + translateByMaximumSpeed(timeDifferenceInPositionVectorUnits); + + + updateCounter++; + prior.renormalise();//not strictly necessary?? + +} + +void BayesianArrayStructure::complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits){ + + + printf("before cross c : posterior map is %i = %f ms time diff pos vec %f\n", posterior.getMAPestimate(), posterior.getIndexInRealTerms(prior.getMAPestimate()), timeDifferenceInPositionVectorUnits); + + int distanceMoved, newPriorIndex; + + double speedValue = relativeSpeedPosterior.offset; + + for (int i = 0;i < relativeSpeedPosterior.arraySize;i++){ + + // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 + + //so we have moved + distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value + // printf("Speed value %f time %f gives distance %i\n", speedValue, timeDifferenceInPositionVectorUnits, distanceMoved); + + if (relativeSpeedPosterior.array[i] != 0){ + + double speedContribution = relativeSpeedPosterior.array[i]; + + // printf("speed [%i](val[%f]) gives %f moved %i in %f units \n", i, relativeSpeedPosterior.array[i], speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); + + //1/2/12 deleted line + newPriorIndex = posterior.offset - prior.offset + distanceMoved;//i.e. where post[0] goes to in terms of prior at this speed + int postIndex = 0;//index of posterior that will contribute + + while (postIndex < posterior.arraySize && newPriorIndex < prior.arraySize){ + + //did use a for loop + // for (postIndex = 0;postIndex < posterior.arraySize;postIndex++){ + //old posterior contributing to new prior + + //would use this method + //newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; + + if (newPriorIndex >= 0){ + prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); + // printf("speed index %i new prior index %i post val %f speed contrib %f dist %i\n", i, newPriorIndex, posterior.array[postIndex], speedContribution, distanceMoved); + } + //but we actually do this for simplicity + newPriorIndex++; + postIndex++; + }//end for. now while + + + }//if not zero + + speedValue += relativeSpeedPosterior.scalar;//optimised line + //as we wanted: + // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(i);//so for scalar 0.01, 50 -> speed value of 0.5 + + }//end speed + + + printf("after cross c : prior map is %i = %f ms\n", prior.getMAPestimate(), prior.getIndexInRealTerms(prior.getMAPestimate())); +} + + + +void BayesianArrayStructure::translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits){ + + + int distanceMoved, newPriorIndex; + double speedIndex = getSpeedEstimateIndex(); + double speedValue = relativeSpeedPosterior.getIndexInRealTerms(speedIndex); + + // double speedValue = relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.integratedEstimate); + + //so for scalar 0.01, 50 -> speed value of 0.5 + double speedContribution = relativeSpeedPosterior.array[(int)round(speedIndex)]; + //so we have moved + distanceMoved = round(timeDifferenceInPositionVectorUnits * speedValue);//round the value + + // printf("speed [%i] gives %f moved %i in %f units \n", i, speedValue, distanceMoved, timeDifferenceInPositionVectorUnits); + + for (int postIndex = 0;postIndex < posterior.arraySize;postIndex++){ + //old posterior contributing to new prior + newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; + if (newPriorIndex >= 0 && newPriorIndex < prior.arraySize){ + prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); + } + + } + +} + */ + +//END PROJECT PRIOR CODE + + /* void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){