view bayesianArraySrc/BayesianArrayStructure.h @ 56:4394c9490716 tip

minor changes
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 24 Dec 2012 18:58:39 +0000
parents 5274e3b5479d
children
line wrap: on
line source
/*
 *  BayesianArrayStructure.h
 *  midiCannamReader
 *
 *  Created by Andrew on 17/07/2011.
 *  Copyright 2011 QMUL. All rights reserved.
 *
 */
#ifndef BAYESIAN_ARRAY_STRUCTURE
#define BAYESIAN_ARRAY_STRUCTURE


#include "ofMain.h"
//#include "DynamicBayesianArray.h"
#include "DynamicVector.h"

class BayesianArrayStructure {
	
public:
//	BayesianArrayStructure();
	BayesianArrayStructure();
	BayesianArrayStructure(int length);
	
	void calculatePosterior();
	void drawArrays();
	void drawArraysRelativeToTimeframe(const double& startTimeMillis, const double& endTimeMillis);

	void drawTempoArrays();
	
	void resetSize(int length);
	void resetArrays();
	void simpleExample();
	void setStartPlaying();
	void zeroArrays();
	
	double screenWidth;
	
	void copyPriorToPosterior();
//	DynamicBayesianArray bayesArray;
	
	double lastEventTime;
	double likelihoodNoise;
	double speedLikelihoodNoise;
	
	//DynamicVector tmpPrior;
	DynamicVector tmpPosteriorForStorage;
	DynamicVector prior;
	DynamicVector posterior;
	DynamicVector likelihood;
	
	DynamicVector relativeSpeedPrior;
	DynamicVector relativeSpeedLikelihood;
	DynamicVector relativeSpeedPosterior;
	DynamicVector acceleration;
	
	double tmpBestEstimate;

//	void updateTmpBestEstimate(const double& timeDifference);
	
	int updateCounter;
	
	void setPositionDistributionScalar(double f);
	
	void resetSpeedToOne();
	void addGaussianNoiseToSpeedPosterior(const double& std_dev);
	void addTriangularNoiseToSpeedPosterior(const double& std_dev);
	
	double bestEstimate;
	void updateBestEstimate(const double& timeDifference);
	double lastBestEstimateUpdateTime;
	double speedEstimate, speedEstimateIndex;
	double getSpeedEstimateIndex();
	
	double speedDecayWidth, speedDecayAmount;
	void decaySpeedDistribution(double timeDifference);
	
	void resetSpeedSize(int length);
	void setRelativeSpeedScalar(double f);
	void setSpeedPrior(double f);
	void calculateNewPriorOffset(const double& timeDifference);
	void setNewDistributionOffsets(const double& newOffset);
	
	void setLikelihoodToConstant();
	void updateTempoLikelihood(const double& speedRatio, const double& matchFactor);
	void updateTempoDistribution();
	
	void calculateTempoUpdate();
	
	void updateBayesianDistributions(const double& newEventTime);
	void crossUpdateArrays(DynamicVector& position, DynamicVector& speed, double timeDifference);
	void complexCrossUpdate(const double& timeDifferenceInPositionVectorUnits);
	void translateByMaximumSpeed(const double& timeDifferenceInPositionVectorUnits);
	double crossUpdateTimeThreshold;//time after which we do complex update of multiple speeds
	
	double speedPriorValue;
	int priorWidth;
	bool* realTimeMode;
	bool usingIntegratedTempoEstimate;
	double relativeSpeedLikelihoodStdDev;
	
	void projectDistribution(const double& newEventTime, const double& newAlignmentPosition, DynamicVector& projectedPrior);
	void complexCrossUpdateProjection(DynamicVector& projectedPrior, const double& timeDifferenceInPositionVectorUnits);
	void translatePosteriorByMaximumSpeed(DynamicVector& translatedPosterior, const double& timeDifferenceInPositionVectorUnits);
	
	void printPostOffset();
	int startingWindowWidth, matchWindowWidth;
	bool updatingSpeedDistribution;//false for testing

	void zeroDistributionAtPosition(DynamicVector& distribution, const double& position);
};
#endif