Mercurial > hg > midi-score-follower
comparison src/BayesianArrayStructure.cpp @ 3:de86d77f2612
added speed prior setting. needs some cleaning
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Fri, 19 Aug 2011 02:36:34 +0100 |
parents | 5581023e0de4 |
children | 4a8e6a6cd224 |
comparison
equal
deleted
inserted
replaced
2:5581023e0de4 | 3:de86d77f2612 |
---|---|
5 * Created by Andrew on 17/07/2011. | 5 * Created by Andrew on 17/07/2011. |
6 * Copyright 2011 QMUL. All rights reserved. | 6 * Copyright 2011 QMUL. All rights reserved. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 //look at reset speed to one - what does this do? - get rid of? | |
11 | |
12 | |
10 #include "BayesianArrayStructure.h" | 13 #include "BayesianArrayStructure.h" |
11 | 14 |
12 BayesianArrayStructure::BayesianArrayStructure(){ | 15 BayesianArrayStructure::BayesianArrayStructure(){ |
13 printf("Bayesian structure: DeFault constructor called"); | 16 printf("Bayesian structure: DeFault constructor called"); |
14 | 17 |
15 prior.createVector(1); | 18 prior.createVector(1); |
16 likelihood.createVector(1); | 19 likelihood.createVector(1); |
17 posterior.createVector(1); | 20 posterior.createVector(1); |
18 | 21 |
19 | 22 speedPriorValue = 1.0; |
23 | |
20 lastEventTime = ofGetElapsedTimeMillis(); | 24 lastEventTime = ofGetElapsedTimeMillis(); |
21 | 25 |
22 /* | 26 /* |
23 tmpPrior.createVector(240); | 27 tmpPrior.createVector(240); |
24 tmpPrior.addGaussianShape(100, 40, 1); | 28 tmpPrior.addGaussianShape(100, 40, 1); |
68 // relativeSpeedPosterior.addToIndex(100, 1); | 72 // relativeSpeedPosterior.addToIndex(100, 1); |
69 //relativeSpeedPosterior.addToIndex(50, 1); | 73 //relativeSpeedPosterior.addToIndex(50, 1); |
70 relativeSpeedPosterior.renormalise(); | 74 relativeSpeedPosterior.renormalise(); |
71 relativeSpeedPosterior.getMaximum(); | 75 relativeSpeedPosterior.getMaximum(); |
72 | 76 |
77 setSpeedPrior(speedPriorValue); | |
78 | |
73 prior.zero(); | 79 prior.zero(); |
74 posterior.zero(); | 80 posterior.zero(); |
75 // posterior.offset = - 200; | 81 // posterior.offset = - 200; |
76 // posterior.addGaussianShape(200, 40, 1); | 82 // posterior.addGaussianShape(200, 40, 1); |
77 posterior.addToIndex(0, 1); | 83 posterior.addToIndex(0, 1); |
79 | 85 |
80 //acceleration.addGaussianShape(2000, 20, 0.8); | 86 //acceleration.addGaussianShape(2000, 20, 0.8); |
81 | 87 |
82 } | 88 } |
83 | 89 |
90 void BayesianArrayStructure::setSpeedPrior(double f){ | |
91 speedPriorValue = f; | |
92 int index = relativeSpeedPosterior.getRealTermsAsIndex(speedPriorValue); | |
93 relativeSpeedPosterior.zero(); | |
94 relativeSpeedPosterior.addGaussianShape(index, 20, 0.8); | |
95 relativeSpeedPosterior.renormalise(); | |
96 relativeSpeedPosterior.getMaximum(); | |
97 relativeSpeedPrior.copyFromDynamicVector(relativeSpeedPosterior); | |
98 printf("BAYES STRUCTU ' SPEED PRIOR %f . index %i\n", speedPriorValue, index); | |
99 | |
100 } | |
101 | |
84 void BayesianArrayStructure::resetSpeedSize(int length){ | 102 void BayesianArrayStructure::resetSpeedSize(int length){ |
85 printf("BAYESIAN SPEED size is : %i\n", length); | 103 printf("BAYESIAN SPEED size is : %i\n", length); |
86 | 104 |
87 relativeSpeedPrior.createVector(length); | 105 relativeSpeedPrior.createVector(length); |
88 relativeSpeedLikelihood.createVector(length); | 106 relativeSpeedLikelihood.createVector(length); |
163 updateCounter = 0; | 181 updateCounter = 0; |
164 | 182 |
165 bestEstimate = 0; | 183 bestEstimate = 0; |
166 // lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); | 184 // lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); |
167 | 185 |
186 setSpeedPrior(speedPriorValue); | |
168 } | 187 } |
169 | 188 |
170 void BayesianArrayStructure::zeroArrays(){ | 189 void BayesianArrayStructure::zeroArrays(){ |
171 prior.zero(); | 190 prior.zero(); |
172 likelihood.zero(); | 191 likelihood.zero(); |
184 | 203 |
185 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;//lastBestEstimateUpdateTime; | 204 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;//lastBestEstimateUpdateTime; |
186 | 205 |
187 tmpBestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDifference*relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate); | 206 tmpBestEstimate = posterior.getIndexInRealTerms(posterior.MAPestimate) + timeDifference*relativeSpeedPosterior.getIndexInRealTerms(relativeSpeedPosterior.MAPestimate); |
188 // | 207 // |
189 printf("tmp best %f and best %f time diff %f posterior MAP %f\n", tmpBestEstimate, bestEstimate, timeDifference, posterior.getIndexInRealTerms(posterior.MAPestimate)); | 208 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.MAPestimate)); |
190 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); | 209 //lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); |
191 } | 210 } |
192 | 211 |
193 void BayesianArrayStructure::updateBestEstimate(){ | 212 void BayesianArrayStructure::updateBestEstimate(){ |
194 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;// | 213 // double timeDiff = ofGetElapsedTimeMillis() - lastEventTime;// |