diff bayesianArraySrc/BayesianArrayStructure.cpp @ 6:746a5af43c02

windowed bayesian distributions - drawn within constrained portion of the screen
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 02 Feb 2012 17:52:08 +0000
parents 5ef00d1dfe68
children 33dedfe32893
line wrap: on
line diff
--- a/bayesianArraySrc/BayesianArrayStructure.cpp	Thu Feb 02 12:45:36 2012 +0000
+++ b/bayesianArraySrc/BayesianArrayStructure.cpp	Thu Feb 02 17:52:08 2012 +0000
@@ -246,6 +246,10 @@
 	
 	posterior.renormalise();
 	
+	//tmp print stuff
+	printf("After CALC");
+	printPostOffset();	
+	
 }
 
 
@@ -268,6 +272,46 @@
 }
 
 
+void BayesianArrayStructure::updateBayesianDistributions(const double& newEventTime){
+	
+	//NEED TO CHECK HERE THAT THEY HAVE THE SAME OFFSETS
+	prior.copyFromDynamicVector(posterior);//try the otehr way
+	
+	//bayesianStruct.copyPriorToPosterior();
+	//need to get new MAP position and set the offset of the arrays
+	//currently bestEstimate is the approx for the new MAP position
+//	int tmpMap = bayesianStruct.posterior.getMAPestimate();
+	
+	double timeDifference = newEventTime - lastEventTime; 
+//	printf("updating distributions at time %f diff %f offset %f tmpmap est %i\n", newEventTime, timeDifference, bayesianStruct.posterior.offset, tmpMap);
+	
+	//addnoise to the tempo distribution
+	//bayesianStruct.decaySpeedDistribution(timeDifference);
+	
+	if (timeDifference > 50){
+		addGaussianNoiseToSpeedPosterior(timeDifference * 10.0 / 100.);
+	}
+
+	printPostOffset();
+	
+	updateBestEstimate(timeDifference);
+	lastBestEstimateUpdateTime = newEventTime;//getTimeNow(timePlayed);
+
+	
+	setNewDistributionOffsets(max(0., bestEstimate - (prior.scalar*prior.arraySize/2)));
+	crossUpdateArrays(posterior, relativeSpeedPosterior, timeDifference);
+	
+	//i.e. using the same offset as prior
+	posterior.offset = prior.offset;// 
+	
+	//	float tmpPrior = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));//	prior.offset = max(0., bestEstimate - (prior.scalar*prior.arraySize/2));
+	//	printf("Using prior offset of %f not %f\n", tmpPrior, prior.offset);
+	
+	lastEventTime = newEventTime;//lastEventTime = ofGetElapsedTimeMillis();
+	
+}
+
+
 void BayesianArrayStructure::crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference){
 	//set the cutoff for offset of position first! XXX
 	
@@ -602,6 +646,11 @@
 }
 
 
+void BayesianArrayStructure::printPostOffset(){
+	double tmp = posterior.getMAPestimate();
+	printf(" MAP index %i post offset %f == %f ms\n", posterior.MAPestimate, posterior.offset, posterior.getIndexInRealTerms(posterior.MAPestimate));
+}
+
 /*
  
  void BayesianArrayStructure::updateTempoDistribution(const double& speedRatio, const double& matchFactor){