comparison src/AudioEventMatcher.cpp @ 4:45b5cf9be377

checking through Bayesian update procedure - working without cross update method.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 02 Feb 2012 12:13:44 +0000
parents 5e188c0035b6
children 5ef00d1dfe68
comparison
equal deleted inserted replaced
3:5e188c0035b6 4:45b5cf9be377
50 ofSetColor(255); 50 ofSetColor(255);
51 // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow); 51 // bayesianStruct.relativeSpeedPrior.drawVector(0, 200, bayesTempoWindow);
52 52
53 double screenWidthMillis = recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.framesToMillis(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.amplitudeNumber); 53 double screenWidthMillis = recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.framesToMillis(recordedTracks.loadedAudioFiles[0].fileLoader.onsetDetect.amplitudeNumber);
54 54
55 bayesianStruct.posterior.drawVector(0, bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow);
56
57 // bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow);
58
59
55 bayesianStruct.likelihood.drawVector(bayesianStruct.likelihood.getRealTermsAsIndex(0), bayesianStruct.likelihood.getRealTermsAsIndex(screenWidthMillis), bayesLikelihoodWindow); 60 bayesianStruct.likelihood.drawVector(bayesianStruct.likelihood.getRealTermsAsIndex(0), bayesianStruct.likelihood.getRealTermsAsIndex(screenWidthMillis), bayesLikelihoodWindow);
56 61
57 bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow); 62 bayesianStruct.relativeSpeedPosterior.drawVector(0, bayesianStruct.relativeSpeedPosterior.getRealTermsAsIndex(2), bayesTempoWindow);
58 63
59 bayesianStruct.posterior.drawVector(bayesianStruct.posterior.getRealTermsAsIndex(0), bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis), bayesPositionWindow); 64
60
61 string tmpStr = "zero is "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(0)); 65 string tmpStr = "zero is "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(0));
62 tmpStr += " offsetis "+ofToString(bayesianStruct.posterior.offset); 66 tmpStr += " offsetis "+ofToString(bayesianStruct.posterior.offset);
63 tmpStr += " screenWidth = "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis)); 67 tmpStr += " screenWidth = "+ofToString(bayesianStruct.posterior.getRealTermsAsIndex(screenWidthMillis));
64 ofDrawBitmapString(tmpStr, 20,140); 68 ofDrawBitmapString(tmpStr, 20,140);
65 tmpStr = "best est "+ofToString(bayesianStruct.bestEstimate); 69 tmpStr = "best est "+ofToString(bayesianStruct.bestEstimate);
71 } 75 }
72 76
73 77
74 void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){ 78 void AudioEventMatcher::newPitchEvent(const double& pitchIn, const double& timeIn){
75 liveInput.addPitchEvent(pitchIn, timeIn); 79 liveInput.addPitchEvent(pitchIn, timeIn);
80
81 //tmp print stuff
82 printf("New pitch MAP post estimate now %i, ", bayesianStruct.posterior.MAPestimate);
83 double tmp = bayesianStruct.posterior.getMAPestimate();
84 printf(" getting it %f and offset %f == %f ms\n", tmp, bayesianStruct.posterior.offset, bayesianStruct.posterior.getIndexInRealTerms(tmp));
85
76 matchNewPitchEvent(0, pitchIn, timeIn); 86 matchNewPitchEvent(0, pitchIn, timeIn);
77 } 87 }
78 88
79 void AudioEventMatcher::newKickEvent(const double& timeIn){ 89 void AudioEventMatcher::newKickEvent(const double& timeIn){
80 // liveInput.addKickEvent(time); 90 // liveInput.addKickEvent(time);
157 } 167 }
158 168
159 bayesianStruct.likelihood.addConstant(numberOfMatches*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length)); 169 bayesianStruct.likelihood.addConstant(numberOfMatches*(1-pitchLikelihoodToNoise)/(pitchLikelihoodToNoise*bayesianStruct.likelihood.length));
160 170
161 recordedTracks.recentPitch = pitchIn; 171 recordedTracks.recentPitch = pitchIn;
172
173
174 //tmp set likelihood constant and calculate using that
175 bayesianStruct.likelihood.zero();
176 bayesianStruct.likelihood.addConstant(1);
177
178 bayesianStruct.calculatePosterior();
179
180 //tmp print stuff
181 printf("After CALC");
182 printPostOffset();
183
162 } 184 }
163 185
164 double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){ 186 double AudioEventMatcher::getPitchDistance(const double& pitchOne, const double& pitchTwo, const double& scale){
165 187
166 double distance = abs(pitchOne - pitchTwo); 188 double distance = abs(pitchOne - pitchTwo);
193 215
194 216
195 void AudioEventMatcher::updateBayesianDistributions(const double& newEventTime){ 217 void AudioEventMatcher::updateBayesianDistributions(const double& newEventTime){
196 //MOVE INTO bayesianStruct?? XX 218 //MOVE INTO bayesianStruct?? XX
197 219
198
199
200 //NEED TO CHECK HERE THAT THEY HAVE THE SAME OFFSETS 220 //NEED TO CHECK HERE THAT THEY HAVE THE SAME OFFSETS
201 bayesianStruct.prior.copyFromDynamicVector(bayesianStruct.posterior);//try the otehr way 221 bayesianStruct.prior.copyFromDynamicVector(bayesianStruct.posterior);//try the otehr way
202 222
203 //bayesianStruct.copyPriorToPosterior(); 223 //bayesianStruct.copyPriorToPosterior();
204 //need to get new MAP position and set the offset of the arrays 224 //need to get new MAP position and set the offset of the arrays
205 //currently bestEstimate is the approx for the new MAP position 225 //currently bestEstimate is the approx for the new MAP position
206 226 int tmpMap = bayesianStruct.posterior.getMAPestimate();
227
207 double timeDifference = newEventTime - bayesianStruct.lastEventTime; 228 double timeDifference = newEventTime - bayesianStruct.lastEventTime;
208 printf("updating distributions at time %f diff %f\n", newEventTime, timeDifference); 229 printf("updating distributions at time %f diff %f offset %f tmpmap est %i\n", newEventTime, timeDifference, bayesianStruct.posterior.offset, tmpMap);
209 230
210 //addnoise to the tempo distribution 231 //addnoise to the tempo distribution
211 //bayesianStruct.decaySpeedDistribution(timeDifference); 232 //bayesianStruct.decaySpeedDistribution(timeDifference);
212 233
213 if (timeDifference > 50){ 234 if (timeDifference > 50){
214 bayesianStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.); 235 bayesianStruct.addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.);
215 } 236 }
216 237
217 bayesianStruct.updateBestEstimate(timeDifference); 238 bayesianStruct.updateBestEstimate(timeDifference);
218
219 bayesianStruct.lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed); 239 bayesianStruct.lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed);
220 240
241 // printf("set new distrb max 0 or %f\n", bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));
242
243 //tmp print stuff
244
245 printf("HALFWAY BEST ");
246 printPostOffset();
247
221 bayesianStruct.setNewDistributionOffsets(max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2))); 248 bayesianStruct.setNewDistributionOffsets(max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2)));
222
223 bayesianStruct.crossUpdateArrays(bayesianStruct.posterior, bayesianStruct.relativeSpeedPosterior, timeDifference); 249 bayesianStruct.crossUpdateArrays(bayesianStruct.posterior, bayesianStruct.relativeSpeedPosterior, timeDifference);
224 250
225 bayesianStruct.posterior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));// bayesianStruct.prior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2)); 251 //i.e. using the same offset as prior
226 252 bayesianStruct.posterior.offset = bayesianStruct.prior.offset;//
253
254 // float tmpPrior = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));// bayesianStruct.prior.offset = max(0., bayesianStruct.bestEstimate - (bayesianStruct.prior.scalar*bayesianStruct.prior.arraySize/2));
255 // printf("Using prior offset of %f not %f\n", tmpPrior, bayesianStruct.prior.offset);
256
227 bayesianStruct.lastEventTime = newEventTime;//bayesianStruct.lastEventTime = ofGetElapsedTimeMillis(); 257 bayesianStruct.lastEventTime = newEventTime;//bayesianStruct.lastEventTime = ofGetElapsedTimeMillis();
228 } 258
259
260 }
261
262 void AudioEventMatcher::printPostOffset(){
263 double tmp = bayesianStruct.posterior.getMAPestimate();
264 printf(" MAP index %i post offset %f == %f ms\n", bayesianStruct.posterior.MAPestimate, bayesianStruct.posterior.offset, bayesianStruct.posterior.getIndexInRealTerms(bayesianStruct.posterior.MAPestimate));
265 }