comparison bayesianArraySrc/BayesianArrayStructure.cpp @ 3:5e188c0035b6

checking the offsets of the arrays
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Wed, 01 Feb 2012 16:05:26 +0000
parents c4f9e49226eb
children 45b5cf9be377
comparison
equal deleted inserted replaced
2:179c09199b3c 3:5e188c0035b6
28 28
29 lastEventTime = 0;//ofGetElapsedTimeMillis(); 29 lastEventTime = 0;//ofGetElapsedTimeMillis();
30 30
31 tmpBestEstimate = 0; 31 tmpBestEstimate = 0;
32 crossUpdateTimeThreshold = 60; 32 crossUpdateTimeThreshold = 60;
33 priorWidth = 50; 33 priorWidth = 20;
34 34
35 } 35 }
36 36
37 BayesianArrayStructure::BayesianArrayStructure(int length){ 37 BayesianArrayStructure::BayesianArrayStructure(int length){
38 printf("BAYESIAN STURCTURE CREATED LENGTH: %i\n", length); 38 printf("BAYESIAN STURCTURE CREATED LENGTH: %i\n", length);
134 void BayesianArrayStructure::setStartPlaying(){ 134 void BayesianArrayStructure::setStartPlaying(){
135 135
136 lastEventTime = 0; 136 lastEventTime = 0;
137 bestEstimate = 0; 137 bestEstimate = 0;
138 lastBestEstimateUpdateTime = 0; 138 lastBestEstimateUpdateTime = 0;
139
139 if (*realTimeMode) 140 if (*realTimeMode)
140 lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 141 lastBestEstimateUpdateTime = ofGetElapsedTimeMillis();
141 //cannot just be zero - offline bug 142 //cannot just be zero - offline bug
142 //printf("start playing - best estimate %f\n", lastBestEstimateUpdateTime); 143 //printf("start playing - best estimate %f\n", lastBestEstimateUpdateTime);
143 144
155 156
156 posterior.offset = -1000; 157 posterior.offset = -1000;
157 setNewDistributionOffsets(0); 158 setNewDistributionOffsets(0);
158 159
159 int zeroIndex = posterior.getRealTermsAsIndex(0); 160 int zeroIndex = posterior.getRealTermsAsIndex(0);
160 161 printf("ZERO INDEX %i\n", zeroIndex);
161 posterior.addGaussianShape(zeroIndex, 500, 1); 162
162 // posterior.addToIndex(0, 1); 163 posterior.addGaussianShapeFromRealTime(0, 500, 1);//one way to add at x msec
164 posterior.addGaussianShape(posterior.getRealTermsAsIndex(10), 50, 1);//alternative way
165
166 //posterior.addToIndex(0, 1);
163 likelihood.addConstant(1); 167 likelihood.addConstant(1);
164 168
165 updateCounter = 0; 169 updateCounter = 0;
166 170
167 171
168 printf("bayes reset arrays - best estimate %f\n", lastBestEstimateUpdateTime); 172 printf("bayes reset arrays - best estimate %f\n", lastBestEstimateUpdateTime);
169 173
170 setSpeedPrior(speedPriorValue); 174 setSpeedPrior(speedPriorValue);
175 relativeSpeedPosterior.copyFromDynamicVector(relativeSpeedPrior);
176
171 } 177 }
172 178
173 179
174 void BayesianArrayStructure::zeroArrays(){ 180 void BayesianArrayStructure::zeroArrays(){
175 prior.zero(); 181 prior.zero();
197 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 203 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis();
198 } 204 }
199 205
200 void BayesianArrayStructure::updateBestEstimate(const double& timeDifference){ 206 void BayesianArrayStructure::updateBestEstimate(const double& timeDifference){
201 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;// 207 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;//
208 double tmp = bestEstimate;
209 printf("post offest %i\n", posterior.offset);
202 210
203 double timeDiff = timeDifference; 211 double timeDiff = timeDifference;
204 212
205 //Using timedifferencfe here will make it go wrong. Is time since beginning of playing 213 //Using timedifferencfe here will make it go wrong. Is time since beginning of playing
206 214
215 speedEstimateIndex = relativeSpeedPosterior.MAPestimate; 223 speedEstimateIndex = relativeSpeedPosterior.MAPestimate;
216 224
217 speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimateIndex); 225 speedEstimate = relativeSpeedPosterior.getIndexInRealTerms(speedEstimateIndex);
218 bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate; 226 bestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDiff*speedEstimate;
219 227
228 printf("best estimate update from %f to %f; time diff %f MAP %i = %f ms speed %f\n", tmp, bestEstimate, timeDiff,
229 posterior.MAPestimate, posterior.getIndexInRealTerms(posterior.MAPestimate), speedEstimate);
220 } 230 }
221 231
222 void BayesianArrayStructure::calculatePosterior(){ 232 void BayesianArrayStructure::calculatePosterior(){
223 //posterior.doProduct(prior, likelihood); 233 //posterior.doProduct(prior, likelihood);
224 234