Mercurial > hg > multitrack-audio-matcher
changeset 46:ba36a1721538
Added abs median calculation, match forwards and backwards paths
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 08 May 2012 23:16:00 +0100 |
parents | d23685b9e766 |
children | 689704aa55d5 |
files | annotationCalculatorSrc/BeatAnnotationReader.cpp annotationCalculatorSrc/BeatAnnotationReader.h annotationCalculatorSrc/Histogram.cpp annotationCalculatorSrc/MatchMultitrackAnnotationReader.cpp annotationCalculatorSrc/MatchMultitrackAnnotationReader.h annotationCalculatorSrc/testApp.cpp annotationCalculatorSrc/testApp.h |
diffstat | 7 files changed, 62 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/annotationCalculatorSrc/BeatAnnotationReader.cpp Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/BeatAnnotationReader.cpp Tue May 08 23:16:00 2012 +0100 @@ -42,25 +42,14 @@ beatTimes.push_back(newBeatTime); } lineCount++; - /* - string::size_type end = firstpart.find_first_of(" ,\t\v\n"); - string part = firstpart.substr(0, end); - string secondpart = firstpart.substr(end, string::npos); - start = secondpart.find_first_not_of(" ,\t\v\n"); - secondpart = secondpart.substr(start , string::npos); - // printf("part:%s,%s\n", part.c_str(), secondpart.c_str()); - MatchNotation n; - n.audioTime = atof(part.c_str()); - n.midiTime = atof(secondpart.c_str()); - matchData.push_back(n); - */ + }//end while reading line iss.clear(); }//end while - printBeatTimes(); + // printBeatTimes(); // printf("There are %i MATCH annotations\n", (int)matchData.size()); } @@ -100,19 +89,19 @@ //printf("%s\n", firstpart.c_str()); if (lineCount == 0){ - printf("First part of align found '%s'\n", part.c_str()); + // printf("First part of align found '%s'\n", part.c_str()); double newBeatTime = atof(part.c_str()); liveFileTimes.push_back(newBeatTime); } if (lineCount == 1){ - printf("Second part of align found '%s'\n", part.c_str()); + // printf("Second part of align found '%s'\n", part.c_str()); double newAlignTime = atof(part.c_str()); multialignTimes.push_back(newAlignTime); } if (lineCount == 2){ - printf("Third part of align found '%s'\n", part.c_str()); + // printf("Third part of align found '%s'\n", part.c_str()); double newAlignTime = atof(part.c_str()); playedAlignTimes.push_back(newAlignTime); @@ -134,6 +123,7 @@ double BeatAnnotationReader::calculateMedianError(const DoubleVector& liveBeatTimes, const DoubleVector& groundTruthAlignment){ //use our alignment Times to calculate error rekative to these ground truth times errors.clear(); + absoluteErrors.clear(); int alignmentLiveIndex = 0; for (int i = 0;i < liveBeatTimes.size() && i < groundTruthAlignment.size();i++){ @@ -169,8 +159,11 @@ // printf("aligns to above %.4f below %.4f\n", alignmentTimes[1][alignmentLiveIndex+1], alignmentTimes[1][alignmentLiveIndex]); errors.push_back(error); + absoluteErrors.push_back(fabs(error)); } - + std::sort(absoluteErrors.begin(), absoluteErrors.end());//sort vector + double median = absoluteErrors[(int)(absoluteErrors.size()/2)]; + printf("median is %f\n", median); } @@ -178,6 +171,7 @@ double BeatAnnotationReader::calculateMedianError(const DoubleVector& liveBeatTimes, const DoubleVector& groundTruthAlignment, const DoubleVector& alignmentLiveTimes, const DoubleVector& alignmentRehearsalTimes){ //use our alignment Times to calculate error rekative to these ground truth times errors.clear(); + absoluteErrors.clear(); int alignmentLiveIndex = 0; for (int i = 0;i < liveBeatTimes.size() && i < groundTruthAlignment.size();i++){ @@ -199,22 +193,22 @@ double fractionOfNext = 0; if (alignmentLiveIndex < alignmentLiveTimes.size() + 1 && time > alignmentLiveTimes[alignmentLiveIndex]){ - double numerator = time - alignmentLiveTimes[alignmentLiveIndex]; - double denom = alignmentLiveTimes[alignmentLiveIndex+1] - alignmentLiveTimes[alignmentLiveIndex]; - //printf("num %f / demon %f \n", numerator, denom); + // double numerator = time - alignmentLiveTimes[alignmentLiveIndex]; + // double denom = alignmentLiveTimes[alignmentLiveIndex+1] - alignmentLiveTimes[alignmentLiveIndex]; + fractionOfNext = (time - alignmentLiveTimes[alignmentLiveIndex])/(alignmentLiveTimes[alignmentLiveIndex+1] - alignmentLiveTimes[alignmentLiveIndex]); result += fractionOfNext * (alignmentRehearsalTimes[alignmentLiveIndex+1] - alignmentRehearsalTimes[alignmentLiveIndex]); } double error = result - groundTruthAlignment[i];//error relative to ground truth error *= 1000.0;//now in ms - printf("live time %.4f align time %f ground truth %.3f error %.1f\n", time, result, groundTruthAlignment[i], error); - // printf("time %.4f align time %f frac %.3f albelow %.4f above %.4f error %.2f\n", time, result, fractionOfNext, alignmentLiveTimes[alignmentLiveIndex], alignmentLiveTimes[alignmentLiveIndex+1], error); - - // printf("aligns to above %.4f below %.4f\n", alignmentRehearsalTimes[alignmentLiveIndex+1], alignmentRehearsalTimes[alignmentLiveIndex]); + // printf("live time %.4f align time %f ground truth %.3f error %.1f\n", time, result, groundTruthAlignment[i], error); errors.push_back(error); + absoluteErrors.push_back(fabs(error)); } - + std::sort(absoluteErrors.begin(), absoluteErrors.end());//sort vector + double median = absoluteErrors[(int)(absoluteErrors.size()/2)]; + printf("median abs error is %f\n", median); }
--- a/annotationCalculatorSrc/BeatAnnotationReader.h Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/BeatAnnotationReader.h Tue May 08 23:16:00 2012 +0100 @@ -23,6 +23,7 @@ typedef std::vector<double> DoubleVector; DoubleVector beatTimes; DoubleVector errors; + DoubleVector absoluteErrors; typedef std::vector<DoubleVector> DoubleMatrix; DoubleMatrix alignmentTimes;
--- a/annotationCalculatorSrc/Histogram.cpp Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/Histogram.cpp Tue May 08 23:16:00 2012 +0100 @@ -37,7 +37,7 @@ bin++; } - printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); + // printf("data pt %f bin %i binPt %.1f\n", data[i], bin, binPoint); if (data[i] <= binPoint + binWidth){//in case outside range histogram[bin]++;
--- a/annotationCalculatorSrc/MatchMultitrackAnnotationReader.cpp Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/MatchMultitrackAnnotationReader.cpp Tue May 08 23:16:00 2012 +0100 @@ -9,7 +9,9 @@ #include "MatchMultitrackAnnotationReader.h" - +#include <iostream> +#include <algorithm> +#include <vector> void MatchMultitrackAnnotationReader::readInMatchFile(std::string& pathName){ @@ -58,6 +60,12 @@ } +void MatchMultitrackAnnotationReader::reverseAnnotations(){ + //when its the forwards path + reverse(matchLiveTimes.begin(),matchLiveTimes.end()); + reverse(matchRehearsalTimes.begin(),matchRehearsalTimes.end()); +} + void MatchMultitrackAnnotationReader::printAnnotations(){ //rwcAnnotations.size() for (int i = 0;i < min(200, (int)matchData.size());i++){
--- a/annotationCalculatorSrc/MatchMultitrackAnnotationReader.h Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/MatchMultitrackAnnotationReader.h Tue May 08 23:16:00 2012 +0100 @@ -37,5 +37,7 @@ DoubleVector matchLiveTimes; DoubleVector matchRehearsalTimes; + void reverseAnnotations(); + }; #endif \ No newline at end of file
--- a/annotationCalculatorSrc/testApp.cpp Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/testApp.cpp Tue May 08 23:16:00 2012 +0100 @@ -3,6 +3,8 @@ //-------------------------------------------------------------- void testApp::setup(){ ofBackground(255); + histogramWidth = 10; + histogramBinNumber = 25; std::string path = "../../../data/marbleArch_4_beats.txt"; // path = "../../../data/marbleArchKick_take4.txt"; @@ -30,19 +32,23 @@ //then calculate the error histogram etc beatReader.readInMultiAlignmentFile(path); + printf("\n\nMultitrack Alignment\n"); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], beatReader.alignmentTimes[0], beatReader.alignmentTimes[1]); + multiHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); - beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], beatReader.alignmentTimes[0], beatReader.alignmentTimes[1]); - - histogramWidth = 10; - histogramBinNumber = 25; + printf("\n\nMATCH BACKWARDS\n"); matchPath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OB.out"; - matchNotations.readInMatchFile(matchPath); - multiHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); + matchBackwardsNotations.readInMatchFile(matchPath); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchBackwardsNotations.matchLiveTimes, matchBackwardsNotations.matchRehearsalTimes); + matchBackwardsHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); - printf("\n\nGET ERRORS FOR MATCH\n\n"); - beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchNotations.matchLiveTimes, matchNotations.matchRehearsalTimes); - matchHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); + printf("\n\nMATCH FORWARDS\n"); + matchPath = "../../../data/MatchAlignments/marbleArchlive4_reh6_match_OF.out"; + matchForwardNotations.readInMatchFile(matchPath); + matchForwardNotations.reverseAnnotations(); + beatReader.calculateMedianError(GroundTruth[0], GroundTruth[1], matchForwardNotations.matchLiveTimes, matchForwardNotations.matchRehearsalTimes); + matchForwardHistogram.createHistogram(histogramWidth, histogramBinNumber, beatReader.errors); screenToDraw = 1; @@ -70,8 +76,13 @@ break; case 2: ofSetColor(0,255,0); - matchHistogram.plotHistogram(); + matchBackwardsHistogram.plotHistogram(); + break; + case 3: + ofSetColor(0,155,0); + matchForwardHistogram.plotHistogram(); break; + } } @@ -94,7 +105,10 @@ plotter.plotTwoVectors(beatReader.alignmentTimes[0], beatReader.alignmentTimes[2], xPlotMin, xPlotMax, yPlotMin, yPlotMax, false); ofSetColor(0,200,0); - plotter.plotTwoVectors(matchNotations.matchLiveTimes, matchNotations.matchRehearsalTimes, xPlotMin, xPlotMax, yPlotMin, yPlotMax, false); + plotter.plotTwoVectors(matchBackwardsNotations.matchLiveTimes, matchBackwardsNotations.matchRehearsalTimes, xPlotMin, xPlotMax, yPlotMin, yPlotMax, false); + + ofSetColor(0,200, 200); + plotter.plotTwoVectors(matchForwardNotations.matchLiveTimes, matchForwardNotations.matchRehearsalTimes, xPlotMin, xPlotMax, yPlotMin, yPlotMax, false); }
--- a/annotationCalculatorSrc/testApp.h Tue May 08 21:53:11 2012 +0100 +++ b/annotationCalculatorSrc/testApp.h Tue May 08 23:16:00 2012 +0100 @@ -6,7 +6,7 @@ #include "MatchMultitrackAnnotationReader.h" #include "Histogram.h" -#define NUMBER_OF_SCREENS 3 +#define NUMBER_OF_SCREENS 4 class testApp : public ofBaseApp{ public: @@ -39,10 +39,12 @@ void printPlotValues(); std::string matchPath; - MatchMultitrackAnnotationReader matchNotations; + MatchMultitrackAnnotationReader matchBackwardsNotations; + MatchMultitrackAnnotationReader matchForwardNotations; Histogram multiHistogram; - Histogram matchHistogram; + Histogram matchBackwardsHistogram; + Histogram matchForwardHistogram; int screenToDraw; int histogramWidth, histogramBinNumber;