Mercurial > hg > multitrack-audio-matcher
diff 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 |
line wrap: on
line diff
--- a/bayesianArraySrc/BayesianArrayStructure.cpp Sat Feb 04 19:59:27 2012 +0000 +++ b/bayesianArraySrc/BayesianArrayStructure.cpp Sun Feb 05 00:00:58 2012 +0000 @@ -107,10 +107,19 @@ printf("speed adding to index for 1 = %f\n", relativeSpeedPosterior.getRealTermsAsIndex(1)); relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1), 0.1); relativeSpeedPosterior.addGaussianShapeFromRealTime(1, 3, 0.5); + + + //tmp debug test + //relativeSpeedPosterior.addToIndex(relativeSpeedPosterior.getRealTermsAsIndex(1.8), 0.15); relativeSpeedPosterior.renormalise(); relativeSpeedPosterior.getMaximum(); + + relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); + + + printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); } @@ -662,8 +671,8 @@ } //PROJECT PRIOR CODE -/* -void BayesianArrayStructure::projectDistribution(const double& newEventTime, DynamicVector& projectedPrior){ + +void BayesianArrayStructure::projectDistribution(const double& newEventTime, const double& newAlignmentPosition, DynamicVector& projectedPrior){ projectedPrior.copyFromDynamicVector(posterior); @@ -674,89 +683,71 @@ // } - updateBestEstimate(timeDifference); - lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); +// updateBestEstimate(timeDifference); +// lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); //set TARGETS - commented tenmporarily - setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); - - crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference); - + + //setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2))); + projectedPrior.offset = posterior.offset;//max(0., newAlignmentPosition - (projectedPrior.scalar*projectedPrior.arraySize/2)); + +// int timeDifference = newEventTime - lastEventTime; + + double timeDifferenceInPositionVectorUnits = timeDifference / projectedPrior.scalar; + + // printf("CROSS UPDATE time diff %f ms is %f units; ", timeDifference, timeDifferenceInPositionVectorUnits); + projectedPrior.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) + complexCrossUpdateProjection(projectedPrior, timeDifferenceInPositionVectorUnits); + else + translatePosteriorByMaximumSpeed(projectedPrior, timeDifferenceInPositionVectorUnits); + + + // updateCounter++; + projectedPrior.renormalise();//not strictly necessary?? + + //i.e. using the same offset as prior - posterior.offset = prior.offset;// +// 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(); +// 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); +void BayesianArrayStructure::complexCrossUpdateProjection(DynamicVector& projectedPrior, const double& 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 + newPriorIndex = posterior.offset - projectedPrior.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 - + while (postIndex < posterior.arraySize && newPriorIndex < projectedPrior.arraySize){ + //would use this method //newPriorIndex = postIndex + posterior.offset - prior.offset + distanceMoved; if (newPriorIndex >= 0){ - prior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); + projectedPrior.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 @@ -772,14 +763,12 @@ // 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){ +void BayesianArrayStructure::translatePosteriorByMaximumSpeed(DynamicVector& translatedPosterior, const double& timeDifferenceInPositionVectorUnits){ int distanceMoved, newPriorIndex; @@ -799,17 +788,18 @@ //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); + translatedPosterior.addToIndex(newPriorIndex, posterior.array[postIndex]*speedContribution); } } } - */ + //END PROJECT PRIOR CODE + /* void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){