comparison src/BayesianArrayStructure.cpp @ 14:3f103cf78148

Checking to allow offline version
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 10 Nov 2011 17:29:45 +0000
parents 75dcd1308658
children c7107e5c8f03
comparison
equal deleted inserted replaced
13:bba4a9da57f1 14:3f103cf78148
20 posterior.createVector(1); 20 posterior.createVector(1);
21 21
22 speedPriorValue = 1.0; 22 speedPriorValue = 1.0;
23 speedEstimate = speedPriorValue; 23 speedEstimate = speedPriorValue;
24 24
25 lastEventTime = ofGetElapsedTimeMillis(); 25 lastEventTime = 0;//ofGetElapsedTimeMillis();
26 26
27 /* 27 /*
28 tmpPrior.createVector(240); 28 tmpPrior.createVector(240);
29 tmpPrior.addGaussianShape(100, 40, 1); 29 tmpPrior.addGaussianShape(100, 40, 1);
30 tmpPrior.addGaussianShape(200, 10, 0.2); 30 tmpPrior.addGaussianShape(200, 10, 0.2);
31 tmpPrior.translateDistribution(20); 31 tmpPrior.translateDistribution(20);
32 */ 32 */
33 tmpBestEstimate = 0; 33 tmpBestEstimate = 0;
34 crossUpdateTimeThreshold = 100; 34 crossUpdateTimeThreshold = 100;
35 priorWidth = 30;
35 } 36 }
36 37
37 BayesianArrayStructure::BayesianArrayStructure(int length){ 38 BayesianArrayStructure::BayesianArrayStructure(int length){
38 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length); 39 printf("BAYESIAN STURTUCRE CREATED LENGTH: %i\n", length);
39 //this constructor isnt called it seems 40 //this constructor isnt called it seems
92 93
93 void BayesianArrayStructure::setSpeedPrior(double f){ 94 void BayesianArrayStructure::setSpeedPrior(double f){
94 speedPriorValue = f; 95 speedPriorValue = f;
95 int index = relativeSpeedPosterior.getRealTermsAsIndex(speedPriorValue); 96 int index = relativeSpeedPosterior.getRealTermsAsIndex(speedPriorValue);
96 relativeSpeedPosterior.zero(); 97 relativeSpeedPosterior.zero();
97 relativeSpeedPosterior.addGaussianShape(index, 20, 0.8); 98 relativeSpeedPosterior.addGaussianShape(index, priorWidth, 0.8);
98 relativeSpeedPosterior.renormalise(); 99 relativeSpeedPosterior.renormalise();
99 relativeSpeedPosterior.getMaximum(); 100 relativeSpeedPosterior.getMaximum();
100 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); 101 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior);
101 printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); 102 printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index);
102 103
156 } 157 }
157 158
158 void BayesianArrayStructure::setStartPlaying(){ 159 void BayesianArrayStructure::setStartPlaying(){
159 lastEventTime = 0;//ofGetElapsedTimeMillis(); 160 lastEventTime = 0;//ofGetElapsedTimeMillis();
160 bestEstimate = 0; 161 bestEstimate = 0;
161 lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 162 lastBestEstimateUpdateTime = lastEventTime;
162 163 //bug somewhere here that prevented offline
164 //ofGetElapsedTimeMillis();//lastEventTime;//
165 printf("start playing - best estimate %f\n", lastBestEstimateUpdateTime);
163 resetArrays(); 166 resetArrays();
164 } 167 }
165 168
166 void BayesianArrayStructure::resetArrays(){ 169 void BayesianArrayStructure::resetArrays(){
167 //called when we start playing 170 //called when we start playing
182 likelihood.addConstant(1); 185 likelihood.addConstant(1);
183 186
184 updateCounter = 0; 187 updateCounter = 0;
185 188
186 bestEstimate = 0; 189 bestEstimate = 0;
187 // lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 190 lastBestEstimateUpdateTime = ofGetElapsedTimeMillis();
191 //cannot just be zero - offline bug
192
193 printf("bayes reset arrays - best estimate %f\n", lastBestEstimateUpdateTime);
188 194
189 setSpeedPrior(speedPriorValue); 195 setSpeedPrior(speedPriorValue);
190 } 196 }
191 197
192 void BayesianArrayStructure::zeroArrays(){ 198 void BayesianArrayStructure::zeroArrays(){
210 // 216 //
211 //printf("tmp best %f and best %f time diff %f posterior MAP %f at speed %f\n", tmpBestEstimate, bestEstimate, timeDifference, posterior.getIndexInRealTerms(posterior.MAPestimate), relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.integratedEstimate)); 217 //printf("tmp best %f and best %f time diff %f posterior MAP %f at speed %f\n", tmpBestEstimate, bestEstimate, timeDifference, posterior.getIndexInRealTerms(posterior.MAPestimate), relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.integratedEstimate));
212 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 218 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis();
213 } 219 }
214 220
215 void BayesianArrayStructure::updateBestEstimate(){ 221 void BayesianArrayStructure::updateBestEstimate(const double& timeDifference){
216 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;// 222 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;//
217 double timeDiff = ofGetElapsedTimeMillis() - lastBestEstimateUpdateTime; 223
224 double timeDiff = timeDifference;
225
226 //Using timedifferencfe here will make it go wrong. Is time since beginning of playing
227
228 //if (*realTimeMode)
229 timeDiff = ofGetElapsedTimeMillis() - lastBestEstimateUpdateTime;
218 230
219 double speedEstimate = relativeSpeedPosterior.getIntegratedEstimate(); 231 double speedEstimate = relativeSpeedPosterior.getIntegratedEstimate();
220 speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimate); 232 speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimate);
221 //relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate) 233 //relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate)
222 bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate; 234 bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate;