Basic Image AlgorithmS Library
2.8.0
|
CONDENSATION (CONditional DENSity EstimATION) is a state estimator very similiar to the Kalman Filter, not only for Gaussian-, but also for any multi-modal distribution. More...
#include <StateEstimator/Condensation.hh>
Public Member Functions | |
void | AddDebugLevel (const long int lv) |
void | AddDebugLevel (const std::string &name) |
Condensation () | |
bool | DebugLevelIsSet (const long int lv) const |
bool | DebugLevelIsSet (const std::string &name) const |
virtual void | EvaluateImportanceWeights () |
If you want to use importance sampling, then overload this function, which is the importance function. More... | |
virtual void | EvaluateObservationDensities ()=0 |
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... | |
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 ()=0 |
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)=0 |
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 | 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 | 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... | |
virtual | ~Condensation () |
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 |
std::vector< double > | correctionOfImportanceWeights_ |
std::vector< double > | cumulProbArray_ |
std::vector< double > | cumulProbArrayImportance_ |
double | defaultInitFraction_ |
Vector< double > | diffusionSigma_ |
Process parameters. More... | |
double | importanceFraction_ |
std::vector< unsigned int > | indexTminus2_ |
bool | initial_ |
Vector< double > | mean_ |
Vector< double > | meanTminus1_ |
unsigned int | Nsamples_ |
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 |
CONDENSATION (CONditional DENSity EstimATION) is a state estimator very similiar to the Kalman Filter, not only for Gaussian-, but also for any multi-modal distribution.
Also it is a rather simple algorithm.
The current state of a system, described by a state vector, is estimated using a certain number of samples, which approximate the real densities. This is done by incorporating measurements ( p(Z|X) ) with a prior distribution p(X)= p(X_t-1 | z_t).
Usage:
In the loop:
Definition at line 81 of file Condensation.hh.
Condensation::Condensation | ( | ) |
Definition at line 38 of file Condensation.cpp.
|
virtual |
Definition at line 53 of file Condensation.cpp.
|
inlineinherited |
Definition at line 355 of file Debug.hh.
Referenced by BIAS::GLProjectionParametersBase::AddDebugLevel(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::FilterBase< InputStorageType, OutputStorageType >::FilterBase(), BIAS::ShowCamWxVideoSourceFactory::OpenDevice(), and BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph().
|
inlineinherited |
|
protectedvirtual |
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.
|
protectedvirtual |
adds offSet_ to the samplePosNew_, can be overwritten if some other offset mechanism is needed
Definition at line 292 of file Condensation.cpp.
|
protectedvirtual |
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().
|
inlineprotected |
Definition at line 324 of file Condensation.hh.
References BIAS::TimeMeasure::GetRealTime(), mean_, BIAS::Vector< T >::MultiplyIP(), Nsamples_, samplePosOld_, sampleWeights_, BIAS::Vector< T >::Set(), BIAS::TimeMeasure::Start(), BIAS::TimeMeasure::Stop(), and sumOfWeights_.
|
inlinestaticprotected |
Definition at line 252 of file Condensation.hh.
|
inlineprotectedinherited |
|
inlineinherited |
Definition at line 341 of file Debug.hh.
Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateStatic2DPoints(), BIAS::UnscentedTransform::ComputeSigmaPoints_(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::GenSynthMatches::GetGTNormalizedF(), BIAS::MonteCarloTransform::GetSamples_(), and BIAS::MonteCarloTransform::Transform().
|
inlineinherited |
|
inlinevirtual |
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 in BIAS::CondensImg.
Definition at line 177 of file Condensation.hh.
|
pure 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
Implemented in BIAS::CondensHisto, and BIAS::CondensImg.
|
inlineinherited |
Definition at line 332 of file Debug.hh.
Referenced by BIAS::listenthread(), BIAS::Image< StorageType >::operator=(), and BIAS::ImageBase::operator=().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inline |
returns the mean state of the density distribution
Definition at line 115 of file Condensation.hh.
double Condensation::GetMeanWeight | ( | ) | const |
Returns the mean weight of all samples.
Initialization samples and importance samples are not used in calculation.
Definition at line 432 of file Condensation.cpp.
|
inline |
Definition at line 107 of file Condensation.hh.
double Condensation::GetVariance | ( | ) | const |
returns the weighted variance as a scalar
Definition at line 375 of file Condensation.cpp.
bool Condensation::GetVariance | ( | Vector< double > & | var | ) | const |
Returns the variance of the sample positions in var.
Initialization samples and importance samples are not used in calculation.
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 |
Returns the "weighted variance" of the sample positions in var.
Initialization samples and importance samples are not used in calculation.
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 | ) |
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.
Definition at line 58 of file Condensation.cpp.
|
pure virtual |
Here u can specify the model and process defaults.
Implemented in BIAS::CondensHisto, and BIAS::CondensImg.
int Condensation::InitPrior | ( | ) |
sets the sample positions for first time step
Definition at line 113 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
pure 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 ...
Implemented in BIAS::CondensHisto, and BIAS::CondensImg.
|
inlineinherited |
|
inlineinherited |
creates a new debuglevel
Definition at line 474 of file Debug.hh.
Referenced by BIAS::COSAC< SolutionType >::COSAC(), BIAS::ProjectionParametersPerspectiveDepth::Init(), BIAS::MonteCarloTransform::MonteCarloTransform(), BIAS::PMatrixEstimation::PMatrixEstimation(), BIAS::PreemptiveRANSAC< SolutionType >::PreemptiveRANSAC(), BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge(), BIAS::ROI::ROI(), BIAS::RotationAveraging::RotationAveraging(), BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph(), BIAS::ThreeDOutOpenSceneGraph::ThreeDOutOpenSceneGraph(), BIAS::Triangulation::Triangulation(), and BIAS::UnscentedTransform::UnscentedTransform().
|
inlineprotected |
Definition at line 282 of file Condensation.hh.
References cumulProbArrayImportance_, BIAS::Random::GetUniformDistributed(), Nsamples_, random_, and sumOfImportanceWeights_.
|
inlineprotected |
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 cumulProbArray_, BIAS::Random::GetUniformDistributed(), Nsamples_, random_, and sumOfWeights_.
int Condensation::PredictNewSamplePositions | ( | ) |
now pick samples from the last time step using the weights
most probably from the process model
most probably gaussian noise
Definition at line 142 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
inlineinherited |
void Condensation::Process | ( | ) |
This really does one iteration of Condensation.
It calls PredictSamplePosition() and EvaluateObservationDensity() in the necessary order.
Definition at line 332 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
inlineinherited |
|
inlineinherited |
|
inlineprotected |
question: real pos_tminus2 of each sample or better old mean value for all samples?
Definition at line 303 of file Condensation.hh.
References indexTminus2_, processFirstOrderScale_, processMean_, processSecondOrderScale_, samplePosOld_, samplePosTminus2_, and stateDim_.
|
inlineinherited |
Definition at line 318 of file Debug.hh.
Referenced by BIAS::ShowCamWxVideoSourceFactory::CreateBumbleBee(), BIAS::ShowCamWxVideoSourceFactory::CreateDCAM(), BIAS::VideoSource_MDcam::ScanBus(), BIAS::GLProjectionParametersBase::SetDebugLevel(), BIAS::VideoSource_Disk::VideoSource_Disk(), BIAS::VideoSource_DV2::VideoSource_DV2(), BIAS::VideoSource_DV::VideoSource_DV_Internal_Init_(), and BIAS::VideoSource_V4L::VideoSource_V4L().
|
inlineinherited |
|
inlineinherited |
void Condensation::SetDefaultInitFraction | ( | double | fraction | ) |
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.
|
inlinestaticinherited |
void Condensation::SetImportanceSampleFraction | ( | double | fraction | ) |
Only specifiy a value unlike zero, if EvaluateImportanceWeights() is overloaded.
Definition at line 268 of file Condensation.cpp.
|
inline |
all samples are moved by this offset at the prediction step
Definition at line 103 of file Condensation.hh.
|
inline |
set a new processMean for the PredictSamplePosition step, see SecondOrderARP_()
Definition at line 152 of file Condensation.hh.
|
inlineinherited |
|
protected |
Definition at line 177 of file Condensation.hh.
|
protectedinherited |
Definition at line 510 of file Debug.hh.
Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().
|
protectedinherited |
new concept, debuglevel are managed here in the debug class
Definition at line 516 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protected |
Definition at line 249 of file Condensation.hh.
|
protectedinherited |
Definition at line 517 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
staticprotectedinherited |
Definition at line 511 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protected |
Definition at line 236 of file Condensation.hh.
|
protected |
Definition at line 234 of file Condensation.hh.
Referenced by PickOneSample_().
|
protected |
Definition at line 235 of file Condensation.hh.
Referenced by PickImportanceSample_().
|
protected |
Definition at line 245 of file Condensation.hh.
|
protected |
Process parameters.
Definition at line 241 of file Condensation.hh.
|
staticprotectedinherited |
|
protected |
Definition at line 246 of file Condensation.hh.
|
protected |
Definition at line 230 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 244 of file Condensation.hh.
|
protected |
Definition at line 232 of file Condensation.hh.
Referenced by CalculateMean_().
|
protected |
Definition at line 232 of file Condensation.hh.
|
protected |
Definition at line 223 of file Condensation.hh.
Referenced by CalculateMean_(), PickImportanceSample_(), and PickOneSample_().
|
protected |
Definition at line 250 of file Condensation.hh.
|
protected |
Definition at line 230 of file Condensation.hh.
|
protected |
Definition at line 242 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 241 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 242 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 248 of file Condensation.hh.
Referenced by PickImportanceSample_(), and PickOneSample_().
|
protected |
Definition at line 235 of file Condensation.hh.
|
protected |
Definition at line 225 of file Condensation.hh.
|
protected |
Definition at line 226 of file Condensation.hh.
Referenced by CalculateMean_(), and SecondOrderARP_().
|
protected |
Definition at line 227 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 234 of file Condensation.hh.
Referenced by CalculateMean_().
|
protected |
Definition at line 224 of file Condensation.hh.
Referenced by SecondOrderARP_().
|
protected |
Definition at line 238 of file Condensation.hh.
Referenced by PickImportanceSample_().
|
protected |
Definition at line 238 of file Condensation.hh.
Referenced by CalculateMean_(), and PickOneSample_().