Mercurial > hg > midi-score-follower
diff src/DynamicVector.cpp @ 9:75dcd1308658
looked at tempo process, likelihood function changed and improved. Now drawing using constrained vector function. Good working version.
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Tue, 23 Aug 2011 11:20:44 +0100 |
parents | 4a8e6a6cd224 |
children | 9860abc92a30 |
line wrap: on
line diff
--- a/src/DynamicVector.cpp Fri Aug 19 19:45:46 2011 +0100 +++ b/src/DynamicVector.cpp Tue Aug 23 11:20:44 2011 +0100 @@ -17,6 +17,7 @@ MAPestimate = 0; offset = 0; scalar = 1; + integratedEstimate = length/2; gaussianLookupMean = (double) GAUSSIAN_LOOKUP_LENGTH/2; gaussianLookupStdDev = (double)(GAUSSIAN_LOOKUP_LENGTH/16); @@ -44,6 +45,7 @@ } length = len; arraySize = array.size(); + integratedEstimate = length/2; } @@ -62,18 +64,33 @@ double DynamicVector::getIntegratedEstimate(){ //returns the index of the integrated average - where the probability distribution is centred - double estimate = 0; + integratedEstimate = 0; double integratedTotal = 0; for (int i = 0;i < length;i++){ - estimate += array[i]*i; + integratedEstimate += array[i]*i; integratedTotal += array[i]; } if (integratedTotal > 0){ - estimate /= integratedTotal; + integratedEstimate /= integratedTotal; } - return estimate; + return integratedEstimate; } +void DynamicVector::updateIntegratedEstimate(){ + //returns the index of the integrated average - where the probability distribution is centred + integratedEstimate = 0; + double integratedTotal = 0; + for (int i = 0;i < length;i++){ + integratedEstimate += array[i]*i; + integratedTotal += array[i]; + } + if (integratedTotal > 0){ + integratedEstimate /= integratedTotal; + } + +} + + void DynamicVector::zero(){ for (int i = 0;i < array.size();i++) array[i] = 0; @@ -123,12 +140,16 @@ void DynamicVector::addGaussianShape(double mean, double StdDev, double factor){ int i; + double std_dev_factor = (2*StdDev*StdDev); factor *= (1/(StdDev*sqrt(2*PI))); - for (i=0;i<array.size();i++){ - array[i] += factor*exp(-1*(i-mean)*(i-mean)/(2*StdDev*StdDev)); + int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); + int minVal = max(0, (int)(mean - 4.8*StdDev)); + + for (i=minVal;i < maxVal;i++){ + array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); } - //addGaussianShapeByLookupTable(mean, StdDev, factor); +// addGaussianShapeByLookupTable(mean, StdDev, factor); } void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double& factor){ @@ -206,8 +227,9 @@ double stepSize = ofGetWidth() / (double)(maxIndex - minIndex); - double screenHeight = ofGetHeight(); + double screenHeight = (double) ofGetHeight(); double maxVal = getMaximum(); + int startInt = max(1,minIndex+1); int endInt = min(maxIndex, (int)array.size()); double heightConstant = screenHeight / maxVal;