Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BIAS::CondensImg Class Reference

example class for condensation with a 2-dim state vector. More...

#include <StateEstimator/CondensImg.hh>

+ Inheritance diagram for BIAS::CondensImg:
+ Collaboration diagram for BIAS::CondensImg:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
 CondensImg ()
 u have to set the stateDim in the constructor! More...
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
void DrawMean (BIAS::Image< unsigned char > &img)
 Draws the mean as a cross, which size is proportional to the variance. More...
 
void DrawPosteriorDistribution (BIAS::Image< unsigned char > &img)
 Draws the samples with their weight as greyvalue, the weight is distributed to the 4 pixels around the sample postion. More...
 
double DrawPosteriorDistribution (BIAS::Image< float > &img)
 same as above but float precision and returns the maximum value also. More...
 
void DrawSamples (Image< unsigned char > &img, unsigned char value=255)
 this draws the sample weights as circles More...
 
virtual void EvaluateImportanceWeights ()
 If you want to use importance sampling, then overload this function, which is the importance function. More...
 
virtual void EvaluateObservationDensities ()
 most important function, here u have to calculate a probability for each sample position based on your observations and assign this prob. More...
 
int GetDebugLevel () const
 
std::ostream & GetDebugStream () const
 
void GetDebugStream (std::ostream &os) const
 
Vector< double > GetMean ()
 returns the mean state of the density distribution More...
 
double GetMeanWeight () const
 Returns the mean weight of all samples. More...
 
void GetSamplePositions (Image< unsigned char > &sampleImg)
 
const std::vector
< BIAS::Vector< double > > & 
GetSamplePositions ()
 
double GetVariance () const
 returns the weighted variance as a scalar More...
 
bool GetVariance (Vector< double > &var) const
 Returns the variance of the sample positions in var. More...
 
bool GetWeightedVariance (Vector< double > &var) const
 Returns the "weighted variance" of the sample positions in var. More...
 
int Init (unsigned int nrSmaples)
 Init the Condensation directly after constructor, with the desired amount of Samples, there more the better the approximation of the real densities. More...
 
virtual void InitModelDefaults ()
 Here u can specify the model and process defaults. More...
 
int InitPrior ()
 sets the sample positions for first time step More...
 
virtual void InitPriorPositions (unsigned int nrOfInitSamples)
 The Prior condition is used to init the first sample positions. More...
 
long int Name2DebugLevel (const std::string &name) const
 looks up a debuglevel in the internal map, returns 0 if not found More...
 
long int NewDebugLevel (const std::string &name)
 creates a new debuglevel More...
 
int PredictNewSamplePositions ()
 
void PrintDebugLevel (std::ostream &os=std::cout) const
 
void Process ()
 This really does one iteration of Condensation. More...
 
void RemoveDebugLevel (const long int lv)
 
void RemoveDebugLevel (const std::string &name)
 
void SetArea (Vector2< double > min, Vector2< double > max)
 The area for the initial uniform distribution. More...
 
void SetDebugLevel (const long int lv)
 
void SetDebugLevel (const std::string &name)
 
void SetDebugStream (const std::ostream &os)
 
void SetDefaultInitFraction (double fraction)
 Set the amount of samples, whose position is always taken by the prior distribution. More...
 
void SetImportanceSampleFraction (double fraction)
 Only specifiy a value unlike zero, if EvaluateImportanceWeights() is overloaded. More...
 
void SetObservation (Image< unsigned char > &osbImg)
 converts to Image<float> and calls the function above More...
 
void SetPredictionOffset (const BIAS::Vector< double > &offSet)
 all samples are moved by this offset at the prediction step More...
 
void SetProcessMean (const BIAS::Vector< double > &newProcessMean)
 set a new processMean for the PredictSamplePosition step, see SecondOrderARP_() More...
 
void ShowDebugLevel (std::ostream &os=std::cout) const
 prints all internally known debuglevels More...
 

Static Public Member Functions

static long int GetGlobalDebugLevel ()
 
static void SetGlobalDebugLevel (long int lev)
 

Protected Member Functions

virtual void AddDiffusions_ ()
 Adds gaussian noise to the position, can be overwritten if some other (i.e. More...
 
virtual void AddOffsets_ ()
 adds offSet_ to the samplePosNew_, can be overwritten if some other offset mechanism is needed More...
 
virtual void CalculateBaseWeights_ ()
 Once all the unweighted sample positions have been computed using predict_new_bases, this routine computes the weights by evaluating the observation density at each of the positions. More...
 
void CalculateMean_ ()
 
long ConsumeNextFreeDebuglevel_ ()
 returns the next available debuglevel More...
 
unsigned int PickImportanceSample_ ()
 
unsigned int PickOneSample_ ()
 The process model for a first-order auto-regressive process is:
x_{t+1} - mean = (x_t - mean)*scaling + sigma*w_t
where w_t is unit iid Gaussian noise, which is added by AddDiffusion. More...
 
void SecondOrderARP_ (unsigned int indexOldSample, Vector< double > &newSample)
 question: real pos_tminus2 of each sample or better old mean value for all samples? More...
 

Static Protected Member Functions

static int compdouble (const void *l, const void *r)
 

Protected Attributes

bool _doSecondOrderARP
 
long int _liDebugLevel
 
long int _liNextDebugLevel
 new concept, debuglevel are managed here in the debug class More...
 
double * _randomArray
 
std::map< std::string, long int > _String2Debuglevel
 
Vector< double > areaMax_
 
Vector< double > areaMin_
 
std::vector< double > correctionOfImportanceWeights_
 
std::vector< double > cumulProbArray_
 
std::vector< double > cumulProbArrayImportance_
 
double defaultInitFraction_
 
Vector< double > diffusionSigma_
 Process parameters. More...
 
BIAS::Image< float > fImg_
 
double importanceFraction_
 
std::vector< unsigned int > indexTminus2_
 
bool initial_
 
Vector< double > mean_
 
Vector< double > meanTminus1_
 
unsigned int Nsamples_
 
Image< unsigned char > obsImg_
 
BIAS::Vector< double > offSet_
 
std::vector< unsigned int > oldIndices_
 
Vector< double > processFirstOrderScale_
 
Vector< double > processMean_
 
Vector< double > processSecondOrderScale_
 
Random random_
 
std::vector< double > sampleImportanceWeights_
 
std::vector< Vector< double > > samplePosNew_
 
std::vector< Vector< double > > samplePosOld_
 
std::vector< Vector< double > > samplePosTminus2_
 
std::vector< double > sampleWeights_
 
unsigned int stateDim_
 
double sumOfImportanceWeights_
 
double sumOfWeights_
 

Static Protected Attributes

static std::ostream _zDebugStream
 
static long int GlobalDebugLevel = 0
 

Detailed Description

example class for condensation with a 2-dim state vector.

The observation p(Z|X) is simply an image, where the greyvalue represents the probabilty.
See condensImgExample.cpp also!

Author
Daniel Grest, Feb. 2004
Examples:
ExampleCondensImg.cpp.

Definition at line 44 of file CondensImg.hh.

Constructor & Destructor Documentation

BIAS::CondensImg::CondensImg ( )
inline

u have to set the stateDim in the constructor!

Definition at line 49 of file CondensImg.hh.

Member Function Documentation

void BIAS::Debug::AddDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::AddDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 362 of file Debug.hh.

void Condensation::AddDiffusions_ ( )
protectedvirtualinherited

Adds gaussian noise to the position, can be overwritten if some other (i.e.

non gaussian) noise is needed

Definition at line 275 of file Condensation.cpp.

void Condensation::AddOffsets_ ( )
protectedvirtualinherited

adds offSet_ to the samplePosNew_, can be overwritten if some other offset mechanism is needed

Definition at line 292 of file Condensation.cpp.

void Condensation::CalculateBaseWeights_ ( )
protectedvirtualinherited

Once all the unweighted sample positions have been computed using predict_new_bases, this routine computes the weights by evaluating the observation density at each of the positions.

Cumulative probabilities are also computed at the same time, to permit an efficient implementation of pick_base_sample using binary search.

Definition at line 301 of file Condensation.cpp.

References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().

void BIAS::Condensation::CalculateMean_ ( )
inlineprotectedinherited
static int BIAS::Condensation::compdouble ( const void *  l,
const void *  r 
)
inlinestaticprotectedinherited

Definition at line 252 of file Condensation.hh.

long BIAS::Debug::ConsumeNextFreeDebuglevel_ ( )
inlineprotectedinherited

returns the next available debuglevel

Author
woelk 09/2006

Definition at line 521 of file Debug.hh.

bool BIAS::Debug::DebugLevelIsSet ( const long int  lv) const
inlineinherited
bool BIAS::Debug::DebugLevelIsSet ( const std::string &  name) const
inlineinherited

Definition at line 350 of file Debug.hh.

void CondensImg::DrawMean ( BIAS::Image< unsigned char > &  img)

Draws the mean as a cross, which size is proportional to the variance.

Definition at line 190 of file CondensImg.cpp.

References BIAS::ImageDraw< StorageType >::LineGrey(), and BIAS::Vector< T >::ScalarProduct().

void CondensImg::DrawPosteriorDistribution ( BIAS::Image< unsigned char > &  img)

Draws the samples with their weight as greyvalue, the weight is distributed to the 4 pixels around the sample postion.

Image has to be initialized with correct size and channelcount !

Definition at line 131 of file CondensImg.cpp.

References BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageData(), BIAS::ImageBase::GetPixelCount(), and BIAS::ImageBase::GetWidth().

double CondensImg::DrawPosteriorDistribution ( BIAS::Image< float > &  img)

same as above but float precision and returns the maximum value also.

Definition at line 153 of file CondensImg.cpp.

References BIAS::Image< StorageType >::FillImageWithConstValue(), BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageDataArray(), and BIAS::ImageBase::GetWidth().

void CondensImg::DrawSamples ( Image< unsigned char > &  img,
unsigned char  value = 255 
)
void CondensImg::EvaluateImportanceWeights ( )
virtual

If you want to use importance sampling, then overload this function, which is the importance function.

It should be a density distribution, which gives hint where to measure the object state.
Evaluate here the samplePosOld_, not the new ones
IMPORTANT: the scale of the importance weights must be equal to the normal weights, like in EvaluateObservationDensities()

Reimplemented from BIAS::Condensation.

Definition at line 81 of file CondensImg.cpp.

void CondensImg::EvaluateObservationDensities ( )
virtual

most important function, here u have to calculate a probability for each sample position based on your observations and assign this prob.

as a weight to the sample

Implements BIAS::Condensation.

Definition at line 65 of file CondensImg.cpp.

int BIAS::Debug::GetDebugLevel ( ) const
inlineinherited
std::ostream& BIAS::Debug::GetDebugStream ( ) const
inlineinherited

Definition at line 405 of file Debug.hh.

void BIAS::Debug::GetDebugStream ( std::ostream &  os) const
inlineinherited

Definition at line 414 of file Debug.hh.

static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

Vector<double> BIAS::Condensation::GetMean ( void  )
inlineinherited

returns the mean state of the density distribution

Examples:
ExampleCondensImg.cpp.

Definition at line 115 of file Condensation.hh.

double Condensation::GetMeanWeight ( ) const
inherited

Returns the mean weight of all samples.

Initialization samples and importance samples are not used in calculation.

Author
woelk 12/2004

Definition at line 432 of file Condensation.cpp.

void BIAS::CondensImg::GetSamplePositions ( Image< unsigned char > &  sampleImg)
const std::vector<BIAS::Vector<double> >& BIAS::Condensation::GetSamplePositions ( )
inlineinherited

Definition at line 107 of file Condensation.hh.

double Condensation::GetVariance ( ) const
inherited

returns the weighted variance as a scalar

Author
grest

Definition at line 375 of file Condensation.cpp.

bool Condensation::GetVariance ( Vector< double > &  var) const
inherited

Returns the variance of the sample positions in var.

Initialization samples and importance samples are not used in calculation.

Author
woelk 12/2004

Definition at line 412 of file Condensation.cpp.

References BIAS::Vector< T >::ElementwiseProduct(), TNT::Vector< T >::newsize(), and BIAS::Vector< T >::SetZero().

bool Condensation::GetWeightedVariance ( Vector< double > &  var) const
inherited

Returns the "weighted variance" of the sample positions in var.

Initialization samples and importance samples are not used in calculation.

Author
woelk 12/2004

Definition at line 390 of file Condensation.cpp.

References BIAS::Vector< T >::ElementwiseProduct(), TNT::Vector< T >::newsize(), and BIAS::Vector< T >::SetZero().

int Condensation::Init ( unsigned int  nrSmaples)
inherited

Init the Condensation directly after constructor, with the desired amount of Samples, there more the better the approximation of the real densities.

The other Init functions are called here also.

Examples:
ExampleCondensHisto.cpp, and ExampleCondensImg.cpp.

Definition at line 58 of file Condensation.cpp.

void CondensImg::InitModelDefaults ( )
virtual

Here u can specify the model and process defaults.

Implements BIAS::Condensation.

Definition at line 32 of file CondensImg.cpp.

int Condensation::InitPrior ( )
inherited

sets the sample positions for first time step

Examples:
ExampleCondensHisto.cpp, and ExampleCondensImg.cpp.

Definition at line 113 of file Condensation.cpp.

References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().

void CondensImg::InitPriorPositions ( unsigned int  nrOfInitSamples)
virtual

The Prior condition is used to init the first sample positions.

Calculates a initial pos for all samples. The prior cond. maybe defined by an image (if state vector is 2-dim) or by a mixture of gaussions or Uniform_distributed or ... or ...

Implements BIAS::Condensation.

Definition at line 54 of file CondensImg.cpp.

long int BIAS::Debug::Name2DebugLevel ( const std::string &  name) const
inlineinherited

looks up a debuglevel in the internal map, returns 0 if not found

Author
woelk 09/2006

Definition at line 454 of file Debug.hh.

long int BIAS::Debug::NewDebugLevel ( const std::string &  name)
inlineinherited
unsigned int BIAS::Condensation::PickImportanceSample_ ( )
inlineprotectedinherited
unsigned int BIAS::Condensation::PickOneSample_ ( )
inlineprotectedinherited

The process model for a first-order auto-regressive process is:
x_{t+1} - mean = (x_t - mean)*scaling + sigma*w_t
where w_t is unit iid Gaussian noise, which is added by AddDiffusion.

This is binary search using cumulative probabilities to pick a base sample. The use of this routine makes Condensation O(NlogN) where N is the number of samples. It is probably better to pick base samples deterministically, since then the algorithm is O(N) and probably marginally more efficient, but this routine is kept here for conceptual simplicity and because it maps better to the published literature.

Definition at line 258 of file Condensation.hh.

References BIAS::Condensation::cumulProbArray_, BIAS::Random::GetUniformDistributed(), BIAS::Condensation::Nsamples_, BIAS::Condensation::random_, and BIAS::Condensation::sumOfWeights_.

int Condensation::PredictNewSamplePositions ( )
inherited

now pick samples from the last time step using the weights

most probably from the process model

most probably gaussian noise

Examples:
ExampleCondensHisto.cpp, and ExampleCondensImg.cpp.

Definition at line 142 of file Condensation.cpp.

References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().

void BIAS::Debug::PrintDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

Definition at line 383 of file Debug.hh.

void Condensation::Process ( )
inherited

This really does one iteration of Condensation.

It calls PredictSamplePosition() and EvaluateObservationDensity() in the necessary order.

Examples:
ExampleCondensHisto.cpp, and ExampleCondensImg.cpp.

Definition at line 332 of file Condensation.cpp.

References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().

void BIAS::Debug::RemoveDebugLevel ( const long int  lv)
inlineinherited

Definition at line 369 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 376 of file Debug.hh.

void BIAS::Condensation::SecondOrderARP_ ( unsigned int  indexOldSample,
Vector< double > &  newSample 
)
inlineprotectedinherited
void CondensImg::SetArea ( Vector2< double >  min,
Vector2< double >  max 
)

The area for the initial uniform distribution.

Probably image size...

Examples:
ExampleCondensImg.cpp.

Definition at line 94 of file CondensImg.cpp.

void BIAS::Debug::SetDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::SetDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 325 of file Debug.hh.

void BIAS::Debug::SetDebugStream ( const std::ostream &  os)
inlineinherited

Definition at line 398 of file Debug.hh.

void Condensation::SetDefaultInitFraction ( double  fraction)
inherited

Set the amount of samples, whose position is always taken by the prior distribution.

Default is 0.2.
fraction must be in [0..1];

Definition at line 260 of file Condensation.cpp.

static void BIAS::Debug::SetGlobalDebugLevel ( long int  lev)
inlinestaticinherited

Definition at line 424 of file Debug.hh.

void Condensation::SetImportanceSampleFraction ( double  fraction)
inherited

Only specifiy a value unlike zero, if EvaluateImportanceWeights() is overloaded.

Definition at line 268 of file Condensation.cpp.

void CondensImg::SetObservation ( Image< unsigned char > &  osbImg)

converts to Image<float> and calls the function above

Examples:
ExampleCondensImg.cpp.

Definition at line 101 of file CondensImg.cpp.

void BIAS::Condensation::SetPredictionOffset ( const BIAS::Vector< double > &  offSet)
inlineinherited

all samples are moved by this offset at the prediction step

Definition at line 103 of file Condensation.hh.

void BIAS::Condensation::SetProcessMean ( const BIAS::Vector< double > &  newProcessMean)
inlineinherited

set a new processMean for the PredictSamplePosition step, see SecondOrderARP_()

Definition at line 152 of file Condensation.hh.

void BIAS::Debug::ShowDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

prints all internally known debuglevels

Author
woelk 09/2006

Definition at line 496 of file Debug.hh.

Member Data Documentation

bool BIAS::Condensation::_doSecondOrderARP
protectedinherited

Definition at line 177 of file Condensation.hh.

long int BIAS::Debug::_liDebugLevel
protectedinherited

Definition at line 510 of file Debug.hh.

Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().

long int BIAS::Debug::_liNextDebugLevel
protectedinherited

new concept, debuglevel are managed here in the debug class

Definition at line 516 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

double* BIAS::Condensation::_randomArray
protectedinherited

Definition at line 249 of file Condensation.hh.

std::map<std::string, long int> BIAS::Debug::_String2Debuglevel
protectedinherited

Definition at line 517 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

std::ostream BIAS::Debug::_zDebugStream
staticprotectedinherited

Definition at line 511 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

Vector<double> BIAS::CondensImg::areaMax_
protected

Definition at line 93 of file CondensImg.hh.

Vector<double> BIAS::CondensImg::areaMin_
protected

Definition at line 93 of file CondensImg.hh.

std::vector<double> BIAS::Condensation::correctionOfImportanceWeights_
protectedinherited

Definition at line 236 of file Condensation.hh.

std::vector<double> BIAS::Condensation::cumulProbArray_
protectedinherited

Definition at line 234 of file Condensation.hh.

Referenced by BIAS::Condensation::PickOneSample_().

std::vector<double> BIAS::Condensation::cumulProbArrayImportance_
protectedinherited

Definition at line 235 of file Condensation.hh.

Referenced by BIAS::Condensation::PickImportanceSample_().

double BIAS::Condensation::defaultInitFraction_
protectedinherited

Definition at line 245 of file Condensation.hh.

Vector<double> BIAS::Condensation::diffusionSigma_
protectedinherited

Process parameters.

Definition at line 241 of file Condensation.hh.

BIAS::Image<float> BIAS::CondensImg::fImg_
protected

Definition at line 97 of file CondensImg.hh.

long int BIAS::Debug::GlobalDebugLevel = 0
staticprotectedinherited

Definition at line 513 of file Debug.hh.

double BIAS::Condensation::importanceFraction_
protectedinherited

Definition at line 246 of file Condensation.hh.

std::vector<unsigned int> BIAS::Condensation::indexTminus2_
protectedinherited

Definition at line 230 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

bool BIAS::Condensation::initial_
protectedinherited

Definition at line 244 of file Condensation.hh.

Vector<double> BIAS::Condensation::mean_
protectedinherited

Definition at line 232 of file Condensation.hh.

Referenced by BIAS::Condensation::CalculateMean_().

Vector<double> BIAS::Condensation::meanTminus1_
protectedinherited

Definition at line 232 of file Condensation.hh.

unsigned int BIAS::Condensation::Nsamples_
protectedinherited
Image<unsigned char> BIAS::CondensImg::obsImg_
protected

Definition at line 94 of file CondensImg.hh.

BIAS::Vector<double> BIAS::Condensation::offSet_
protectedinherited

Definition at line 250 of file Condensation.hh.

std::vector<unsigned int> BIAS::Condensation::oldIndices_
protectedinherited

Definition at line 230 of file Condensation.hh.

Vector<double> BIAS::Condensation::processFirstOrderScale_
protectedinherited

Definition at line 242 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

Vector<double> BIAS::Condensation::processMean_
protectedinherited

Definition at line 241 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

Vector<double> BIAS::Condensation::processSecondOrderScale_
protectedinherited

Definition at line 242 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

Random BIAS::Condensation::random_
protectedinherited
std::vector<double> BIAS::Condensation::sampleImportanceWeights_
protectedinherited

Definition at line 235 of file Condensation.hh.

std::vector<Vector<double> > BIAS::Condensation::samplePosNew_
protectedinherited

Definition at line 225 of file Condensation.hh.

std::vector<Vector<double> > BIAS::Condensation::samplePosOld_
protectedinherited
std::vector<Vector<double> > BIAS::Condensation::samplePosTminus2_
protectedinherited

Definition at line 227 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

std::vector<double> BIAS::Condensation::sampleWeights_
protectedinherited

Definition at line 234 of file Condensation.hh.

Referenced by BIAS::Condensation::CalculateMean_().

unsigned int BIAS::Condensation::stateDim_
protectedinherited

Definition at line 224 of file Condensation.hh.

Referenced by BIAS::Condensation::SecondOrderARP_().

double BIAS::Condensation::sumOfImportanceWeights_
protectedinherited

Definition at line 238 of file Condensation.hh.

Referenced by BIAS::Condensation::PickImportanceSample_().

double BIAS::Condensation::sumOfWeights_
protectedinherited

The documentation for this class was generated from the following files: