⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condensation.h

📁 来自美国著名大学的研究,实现动目标的自动跟踪算法
💻 H
字号:
/********************************************************************************/
/*  Program	   :  condensation.h						*/
/*  Version	   :  0.01A							*/
/*  Abstract       :  	*/
/*  Copyright      :  GuanFeng Ye						*/
/*  Creation Date  :  10/30/2005						*/
/*  Revision Date  :  10/30/2005						*/
/*										*/
/********************************************************************************/
#if !defined(_CONDENSATION_H_)
#define _CONDENSATION_H_

#include <windows.h>
#include "ModelParameters.h"

/* The state vector for this simple model is one-dimensional. In
   multiple dimensions, for example, Sample would be an array. */
typedef double Sample;

/* The process model used in this simple implementation is a
   one-dimensional first-order auto-regressive process, where

   (x_t - mean) = (x_{t-1} - mean) * scaling + sigma w_t

   and the w_t are iid unit zero-mean Gaussian noise samples. */
class ProcessModel
{
public:
	ProcessModel();
	virtual ~ProcessModel(){ };
public:
	double		first_order_arp(double previous);
	virtual double	mean(){ return m_Mean; };
	virtual double	scaling(){ return m_Scaling; };
	virtual double	sigma(){ return m_Sigma; };

private:
	double m_Mean;
	double m_Scaling;
	double m_Sigma;
};

/* This structure contains the parameters of the simulation model. The
   simulated data is produced from a model of a single particle
   following a one-dimensional 1st-order ARP whose parameters are
   stored in the structure process. Measurements are simulated by
   adding Gaussian noise with std. deviation sigma to the true
   simulated position of the particle. */
class SceneModel
{
public:
	SceneModel();
	virtual ~SceneModel(){ };
public:
	virtual double	sigma(){ return m_Sigma; };

public:
	ProcessModel process;

private:
	double m_Sigma;
};

/* The prior distribution of the state is taken to be Gaussian with
   the parameters stored in this structure. */
class PriorModel
{
public:
	PriorModel();
	virtual ~PriorModel(){ };

public:
	virtual double	mean(){ return m_Mean; };
	virtual double	sigma(){ return m_Sigma; };

private:
	double m_Mean;
	double m_Sigma;
};

/* The observation model is of Gaussian noise with std. deviation
   sigma, so

   z_t = x_t + sigma v_t

   where the v_t are assumed iid unit zero-mean Gaussian noise
   samples. In principle for this simulation, the modelled observation
   noise can be different to the simulated observation noise, hence
   the presence of a separate std. deviation parameter in the
   structure SceneModel. */
class ObservationModel
{
public:
	ObservationModel();
	virtual ~ObservationModel(){ };

public:
	virtual double	sigma(){ return m_Sigma; };

private:
	double m_Sigma;
};

/* This structure contains information about how the state
   distribution should be displayed at each timestep. The display in
   this implementation is a one-dimensional histogram, and this
   parameter sets the width of the histogram (so that the interval
   [-histogram_width, histogram_width] is displayed). */
class DisplayModel
{
public:
	DisplayModel();
	virtual ~DisplayModel(){ };

private:
	double m_HistogramWidth;
};

/* This structure contains all the parameter settings for the models
   which remain constant throughout a run of the algorithm. */
class GlobalData
{
public:
	GlobalData();
	virtual ~GlobalData(){ };

public:
	virtual int nSamples(){ return m_nSamples; };
	virtual int nIterations(){ return m_nIterations; };
public:
	/* The parameters specifying the model of the prior
	   distribution for the first timestep. */
	PriorModel prior;

	/* The parameters specifying the process model. */
	ProcessModel process;

	/* The parameters specifying the simulation model of the scene.
	   This is only used in the case of simulated data. */
	SceneModel scene;

	/* The parameters specifying the observation model. */
	ObservationModel obs;

	/* The parameters specifying how to display the state estimate at each timestep. */
	DisplayModel disp;

private:
	int m_nSamples;         /* The number of samples N. */
	int m_nIterations;      /* The number of iterations to run the filter. */
};

/* This structure contains the data for the measurements made at each
   timestep. The simulation consists of a single point-measurement.
   This structure stores the true position of the simulated particle,
   and its measured position, which is corrupted by noise. */
class MeasData
{
public:
	void SetTrueValue(double value);
	void obtain_observations(GlobalData *global);

public:
	virtual double	truevalue(){ return m_TrueValue; };
	virtual double	observed(){ return m_Observed; };

private:
	double m_TrueValue;
	double m_Observed;
};

/* This structure contains all of the information which is specific to
   a given iteration of the algorithm. */
class IterationData
{
public:
	IterationData();
	virtual ~IterationData();
public:
	virtual int	nSamples(){ return m_nSamples; };
	virtual Sample*	get_new_positions(){ return new_positions; };
	virtual Sample*	get_old_positions(){ return old_positions; };
	void		update_after_iterating(int iteration);
	void		set_up_prior_conditions(double mean, double sigma);
	int		pick_base_sample( );
	void		predict_sample_position(int new_sample, int old_sample, GlobalData *globa);
	void		predict_new_bases(GlobalData *globa);
	void		calculate_base_weights(double sigma);
	double		evaluate_observation_density(int new_sample, double sigma);
public:
	/* The measurements made in a given iteration are stored here. For
	some applications a discrete set of measurements is not
	appropriate, and this could contain, e.g. a pointer to an image
	structure. */
	MeasData meas;

private:
	int m_nSamples;
	/* The following arrays contain the sample positions for the current
	   and previous timesteps respectively. At the end of each iteration,
	   these pointers are swapped over to avoid copying data structures,
	   so their addresses should not be relied on. */
	Sample *new_positions;
	Sample *old_positions;
	
	/* The following arrays give the sample weights and cumulative probabilities,
	   as well as the largest cumulative probability. There is no stage in the
	   algorithm when the weights from both the previous and current timesteps
	   are needed. At the beginning of an iteration, sample_weights contains the
	   weights from the previous iteration, and by the end it contains the weights
	   of the current iteration. The cumulative probabilities are not normalised,
	   so largest_cumulative_prob is needed to store the largest cumulative probability
	   (for simplicity of the binary search algorithm, cumul_prob_array[0] = 0) */
	double *sample_weights;
	double *cumul_prob_array;
	double largest_cumulative_prob;
};

class Condensation
{
public:
	Condensation();
	virtual ~Condensation();

public:
	void Run(int times);

private:
	double evaluate_observation_density(int new_sample);private:
	/* All of the global information is packaged into the following two
	structures. `global' contains information which is constant over a
	run of the algorithm and `data' contains all of the current state
	at a given iteration. */
	GlobalData	global;
	IterationData	data;
};

#endif // #if !defined(_CONDENSATION_H_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -