Mercurial > hg > midi-score-follower
diff jnmr/DynamicVector.cpp @ 46:43edc8abe2a7
Fixed bug in complex update due to mismatch between ms and vector units
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Sun, 05 Feb 2012 19:40:21 +0000 |
parents | 6c8a048720c3 |
children |
line wrap: on
line diff
--- a/jnmr/DynamicVector.cpp Sun Feb 05 10:00:34 2012 +0000 +++ b/jnmr/DynamicVector.cpp Sun Feb 05 19:40:21 2012 +0000 @@ -47,6 +47,8 @@ length = len; arraySize = array.size(); integratedEstimate = length/2; + MAPestimate = length/2; + printf("array size is %i\n", arraySize); } @@ -63,6 +65,19 @@ return max; } +int DynamicVector::getMAPestimate(){ + int i; + double max = 0; + for (i=0;i < length;i++){ + if (array[i] > max){ + max = array[i]; + MAPestimate = i; + } + } + maximumValue = max; + return MAPestimate; +} + double DynamicVector::getIntegratedEstimate(){ //returns the index of the integrated average - where the probability distribution is centred integratedEstimate = 0; @@ -139,6 +154,7 @@ for (int i = 0;i < arraySize;i++){ printf("[%i] = %f\n", i, array[i]); } + printf("Offset %f map estimate %i == %f ms\n", offset, MAPestimate, getIndexInRealTerms(MAPestimate)); } void DynamicVector::translateDistribution(int translationIndex){ @@ -159,7 +175,7 @@ } void DynamicVector::addGaussianShape(const double& mean, const double& StdDev, double factor){ - + //USES THE INDICES OF THE MATRIX AS MEAN AND STD DEV int i; double std_dev_factor = (2*StdDev*StdDev); factor *= (1/(StdDev*sqrt(2*PI))); @@ -175,14 +191,16 @@ void DynamicVector::addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor){ + //USES THE ACTUAL VALUES IN MS AS MEAN (TIME) AND STD DEV + double StdDevAsIndex = StdDev/scalar; double mean = getRealTermsAsIndex(actualTime); - printf("Gaussian realtime %f at index %f\n", actualTime, mean); +// printf("Gaussian realtime %f at index %f std dev %f in index %f \n", actualTime, mean, StdDev, StdDevAsIndex); int i; - double std_dev_factor = (2*StdDev*StdDev); - factor *= (1/(StdDev*sqrt(2*PI))); - int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); - int minVal = max(0, (int)(mean - 4.8*StdDev)); + double std_dev_factor = (2*StdDevAsIndex*StdDevAsIndex); + factor *= (1/(StdDevAsIndex*sqrt(2*PI))); + int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDevAsIndex)); + int minVal = max(0, (int)(mean - 4.8*StdDevAsIndex)); for (i=minVal;i < maxVal;i++){ array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); @@ -254,6 +272,10 @@ } +double DynamicVector::millisToVectorUnits(const double& millis){ + return millis/scalar; +} + double DynamicVector::getValueAtMillis(const double& millis){ int index = round(getRealTermsAsIndex(millis));