comparison 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
comparison
equal deleted inserted replaced
8:d9a3613e7264 9:75dcd1308658
15 arraySize = 0; 15 arraySize = 0;
16 maximumValue = 0; 16 maximumValue = 0;
17 MAPestimate = 0; 17 MAPestimate = 0;
18 offset = 0; 18 offset = 0;
19 scalar = 1; 19 scalar = 1;
20 integratedEstimate = length/2;
20 21
21 gaussianLookupMean = (double) GAUSSIAN_LOOKUP_LENGTH/2; 22 gaussianLookupMean = (double) GAUSSIAN_LOOKUP_LENGTH/2;
22 gaussianLookupStdDev = (double)(GAUSSIAN_LOOKUP_LENGTH/16); 23 gaussianLookupStdDev = (double)(GAUSSIAN_LOOKUP_LENGTH/16);
23 double factor = 1.0;//(1.0 / (gaussianLookupStdDev*sqrt(2*PI)) );//1.0;//-1.0/(2*PI*sqrt(gaussianLookupStdDev)); 24 double factor = 1.0;//(1.0 / (gaussianLookupStdDev*sqrt(2*PI)) );//1.0;//-1.0/(2*PI*sqrt(gaussianLookupStdDev));
24 for (int i = 0;i < GAUSSIAN_LOOKUP_LENGTH;i++){ 25 for (int i = 0;i < GAUSSIAN_LOOKUP_LENGTH;i++){
42 for (int i = 0; i < len;i++){ 43 for (int i = 0; i < len;i++){
43 array.push_back(0); 44 array.push_back(0);
44 } 45 }
45 length = len; 46 length = len;
46 arraySize = array.size(); 47 arraySize = array.size();
48 integratedEstimate = length/2;
47 } 49 }
48 50
49 51
50 double DynamicVector::getMaximum(){ 52 double DynamicVector::getMaximum(){
51 int i; 53 int i;
60 return max; 62 return max;
61 } 63 }
62 64
63 double DynamicVector::getIntegratedEstimate(){ 65 double DynamicVector::getIntegratedEstimate(){
64 //returns the index of the integrated average - where the probability distribution is centred 66 //returns the index of the integrated average - where the probability distribution is centred
65 double estimate = 0; 67 integratedEstimate = 0;
66 double integratedTotal = 0; 68 double integratedTotal = 0;
67 for (int i = 0;i < length;i++){ 69 for (int i = 0;i < length;i++){
68 estimate += array[i]*i; 70 integratedEstimate += array[i]*i;
69 integratedTotal += array[i]; 71 integratedTotal += array[i];
70 } 72 }
71 if (integratedTotal > 0){ 73 if (integratedTotal > 0){
72 estimate /= integratedTotal; 74 integratedEstimate /= integratedTotal;
73 } 75 }
74 return estimate; 76 return integratedEstimate;
75 } 77 }
78
79 void DynamicVector::updateIntegratedEstimate(){
80 //returns the index of the integrated average - where the probability distribution is centred
81 integratedEstimate = 0;
82 double integratedTotal = 0;
83 for (int i = 0;i < length;i++){
84 integratedEstimate += array[i]*i;
85 integratedTotal += array[i];
86 }
87 if (integratedTotal > 0){
88 integratedEstimate /= integratedTotal;
89 }
90
91 }
92
76 93
77 void DynamicVector::zero(){ 94 void DynamicVector::zero(){
78 for (int i = 0;i < array.size();i++) 95 for (int i = 0;i < array.size();i++)
79 array[i] = 0; 96 array[i] = 0;
80 } 97 }
121 } 138 }
122 139
123 void DynamicVector::addGaussianShape(double mean, double StdDev, double factor){ 140 void DynamicVector::addGaussianShape(double mean, double StdDev, double factor){
124 141
125 int i; 142 int i;
143 double std_dev_factor = (2*StdDev*StdDev);
126 factor *= (1/(StdDev*sqrt(2*PI))); 144 factor *= (1/(StdDev*sqrt(2*PI)));
127 for (i=0;i<array.size();i++){ 145 int maxVal = min((int) array.size(), (int)(mean + 4.8*StdDev));
128 array[i] += factor*exp(-1*(i-mean)*(i-mean)/(2*StdDev*StdDev)); 146 int minVal = max(0, (int)(mean - 4.8*StdDev));
129 } 147
130 148 for (i=minVal;i < maxVal;i++){
131 //addGaussianShapeByLookupTable(mean, StdDev, factor); 149 array[i] += factor*exp(-1*(i-mean)*(i-mean)/(std_dev_factor));
150 }
151
152 // addGaussianShapeByLookupTable(mean, StdDev, factor);
132 } 153 }
133 154
134 void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double& factor){ 155 void DynamicVector::addGaussianShapeByLookupTable(double& mean, double& StdDev, double& factor){
135 int i; 156 int i;
136 int lookupIndex ; 157 int lookupIndex ;
204 225
205 void DynamicVector::drawVector(const int& minIndex, const int& maxIndex){ 226 void DynamicVector::drawVector(const int& minIndex, const int& maxIndex){
206 227
207 228
208 double stepSize = ofGetWidth() / (double)(maxIndex - minIndex); 229 double stepSize = ofGetWidth() / (double)(maxIndex - minIndex);
209 double screenHeight = ofGetHeight(); 230 double screenHeight = (double) ofGetHeight();
210 double maxVal = getMaximum(); 231 double maxVal = getMaximum();
232
211 int startInt = max(1,minIndex+1); 233 int startInt = max(1,minIndex+1);
212 int endInt = min(maxIndex, (int)array.size()); 234 int endInt = min(maxIndex, (int)array.size());
213 double heightConstant = screenHeight / maxVal; 235 double heightConstant = screenHeight / maxVal;
214 int lastHeightPixel = heightConstant * (1 - array[startInt-1]); 236 int lastHeightPixel = heightConstant * (1 - array[startInt-1]);
215 int newHeightPixel; 237 int newHeightPixel;