Mercurial > hg > midi-score-follower
comparison 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 |
comparison
equal
deleted
inserted
replaced
45:90ad1817ca56 | 46:43edc8abe2a7 |
---|---|
45 array.push_back(0); | 45 array.push_back(0); |
46 } | 46 } |
47 length = len; | 47 length = len; |
48 arraySize = array.size(); | 48 arraySize = array.size(); |
49 integratedEstimate = length/2; | 49 integratedEstimate = length/2; |
50 MAPestimate = length/2; | |
51 printf("array size is %i\n", arraySize); | |
50 } | 52 } |
51 | 53 |
52 | 54 |
53 double DynamicVector::getMaximum(){ | 55 double DynamicVector::getMaximum(){ |
54 int i; | 56 int i; |
59 MAPestimate = i; | 61 MAPestimate = i; |
60 } | 62 } |
61 } | 63 } |
62 maximumValue = max; | 64 maximumValue = max; |
63 return max; | 65 return max; |
66 } | |
67 | |
68 int DynamicVector::getMAPestimate(){ | |
69 int i; | |
70 double max = 0; | |
71 for (i=0;i < length;i++){ | |
72 if (array[i] > max){ | |
73 max = array[i]; | |
74 MAPestimate = i; | |
75 } | |
76 } | |
77 maximumValue = max; | |
78 return MAPestimate; | |
64 } | 79 } |
65 | 80 |
66 double DynamicVector::getIntegratedEstimate(){ | 81 double DynamicVector::getIntegratedEstimate(){ |
67 //returns the index of the integrated average - where the probability distribution is centred | 82 //returns the index of the integrated average - where the probability distribution is centred |
68 integratedEstimate = 0; | 83 integratedEstimate = 0; |
137 | 152 |
138 void DynamicVector::printArray(){ | 153 void DynamicVector::printArray(){ |
139 for (int i = 0;i < arraySize;i++){ | 154 for (int i = 0;i < arraySize;i++){ |
140 printf("[%i] = %f\n", i, array[i]); | 155 printf("[%i] = %f\n", i, array[i]); |
141 } | 156 } |
157 printf("Offset %f map estimate %i == %f ms\n", offset, MAPestimate, getIndexInRealTerms(MAPestimate)); | |
142 } | 158 } |
143 | 159 |
144 void DynamicVector::translateDistribution(int translationIndex){ | 160 void DynamicVector::translateDistribution(int translationIndex){ |
145 int tmpIndex; | 161 int tmpIndex; |
146 DoubleVector tmpArray; | 162 DoubleVector tmpArray; |
157 tmpArray.clear(); | 173 tmpArray.clear(); |
158 //now delete tmp array | 174 //now delete tmp array |
159 } | 175 } |
160 | 176 |
161 void DynamicVector::addGaussianShape(const double& mean, const double& StdDev, double factor){ | 177 void DynamicVector::addGaussianShape(const double& mean, const double& StdDev, double factor){ |
162 | 178 //USES THE INDICES OF THE MATRIX AS MEAN AND STD DEV |
163 int i; | 179 int i; |
164 double std_dev_factor = (2*StdDev*StdDev); | 180 double std_dev_factor = (2*StdDev*StdDev); |
165 factor *= (1/(StdDev*sqrt(2*PI))); | 181 factor *= (1/(StdDev*sqrt(2*PI))); |
166 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); | 182 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); |
167 int minVal = max(0, (int)(mean - 4.8*StdDev)); | 183 int minVal = max(0, (int)(mean - 4.8*StdDev)); |
173 // addGaussianShapeByLookupTable(mean, StdDev, factor); | 189 // addGaussianShapeByLookupTable(mean, StdDev, factor); |
174 } | 190 } |
175 | 191 |
176 | 192 |
177 void DynamicVector::addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor){ | 193 void DynamicVector::addGaussianShapeFromRealTime(const double& actualTime, const double& StdDev, double factor){ |
178 | 194 //USES THE ACTUAL VALUES IN MS AS MEAN (TIME) AND STD DEV |
195 | |
196 double StdDevAsIndex = StdDev/scalar; | |
179 double mean = getRealTermsAsIndex(actualTime); | 197 double mean = getRealTermsAsIndex(actualTime); |
180 printf("Gaussian realtime %f at index %f\n", actualTime, mean); | 198 // printf("Gaussian realtime %f at index %f std dev %f in index %f \n", actualTime, mean, StdDev, StdDevAsIndex); |
181 int i; | 199 int i; |
182 double std_dev_factor = (2*StdDev*StdDev); | 200 double std_dev_factor = (2*StdDevAsIndex*StdDevAsIndex); |
183 factor *= (1/(StdDev*sqrt(2*PI))); | 201 factor *= (1/(StdDevAsIndex*sqrt(2*PI))); |
184 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev)); | 202 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDevAsIndex)); |
185 int minVal = max(0, (int)(mean - 4.8*StdDev)); | 203 int minVal = max(0, (int)(mean - 4.8*StdDevAsIndex)); |
186 | 204 |
187 for (i=minVal;i < maxVal;i++){ | 205 for (i=minVal;i < maxVal;i++){ |
188 array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); | 206 array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor)); |
189 } | 207 } |
190 | 208 |
250 value -= offset; | 268 value -= offset; |
251 value /= scalar; | 269 value /= scalar; |
252 | 270 |
253 return value; | 271 return value; |
254 | 272 |
273 } | |
274 | |
275 double DynamicVector::millisToVectorUnits(const double& millis){ | |
276 return millis/scalar; | |
255 } | 277 } |
256 | 278 |
257 double DynamicVector::getValueAtMillis(const double& millis){ | 279 double DynamicVector::getValueAtMillis(const double& millis){ |
258 | 280 |
259 int index = round(getRealTermsAsIndex(millis)); | 281 int index = round(getRealTermsAsIndex(millis)); |