Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpStatisticalTestEWMA Class Reference

#include <vpStatisticalTestEWMA.h>

Inheritance diagram for vpStatisticalTestEWMA:

Public Types

enum  vpMeanDriftType {
  MEAN_DRIFT_NONE = 0 , MEAN_DRIFT_DOWNWARD = 1 , MEAN_DRIFT_UPWARD = 2 , MEAN_DRIFT_BOTH = 3 ,
  MEAN_DRIFT_COUNT = 4 , MEAN_DRIFT_UNKNOWN = MEAN_DRIFT_COUNT
}
typedef enum vpStatisticalTestAbstract::vpMeanDriftType vpMeanDriftType

Public Member Functions

 vpStatisticalTestEWMA (const float &alpha=0.1f)
float getAlpha () const
float getWt () const
void init (const float &alpha)
void init (const float &alpha, const float &mean, const float &stdev)
void setAlpha (const float &alpha)
void getLimits (float &limitDown, float &limitUp) const
float getMean () const
float getStdev () const
void init ()
void setMinStdev (const float &stdevmin)
void setNbSamplesForStat (const unsigned int &nbSamples)
vpMeanDriftType testDownUpwardMeanDrift (const float &signal)
vpMeanDriftType testDownwardMeanDrift (const float &signal)
vpMeanDriftType testUpwardMeanDrift (const float &signal)

Static Public Member Functions

static std::string vpMeanDriftTypeToString (const vpMeanDriftType &type)
static vpMeanDriftType vpMeanDriftTypeFromString (const std::string &name)
static std::string getAvailableMeanDriftType (const std::string &prefix="<", const std::string &sep=" , ", const std::string &suffix=">")
static void print (const vpMeanDriftType &type)

Protected Member Functions

virtual void computeDeltaAndLimits ()
virtual vpMeanDriftType detectDownwardMeanDrift () VP_OVERRIDE
virtual vpMeanDriftType detectUpwardMeanDrift () VP_OVERRIDE
virtual bool updateStatistics (const float &signal) VP_OVERRIDE
virtual void updateTestSignals (const float &signal) VP_OVERRIDE

Protected Attributes

float m_alpha
float m_wt
float m_wtprev
bool m_areStatisticsComputed
float m_count
float m_limitDown
float m_limitUp
float m_mean
unsigned int m_nbSamplesForStatistics
float * m_s
float m_stdev
float m_stdevmin
float m_sumForMean

Detailed Description

Class that permits to perform Exponentially Weighted Moving Average mean drft tests.

The EWMA test is designed to detect drift in the mean $ \mu $ of an observed signal $ s(t) $.

The test signal $ w(t) $ is computed as follow:

$ w(0) = \mu $

$ w(t) = \alpha s(t) + ( 1 - \alpha ) * w(t-1) $

Be $ \sigma $ the standard deviation of the input signal $ s(t) $.

A downward alarm is raised if: $ w(t) <= \mu - 3 * \sigma * \sqrt{ \frac{\alpha}{2 - \alpha}}$

An upward alarm is raised if: $ w(t) >= \mu + 3 * \sigma * \sqrt{ \frac{\alpha}{2 - \alpha}}$

To detect only downward drifts of the input signal $ s(t) $ use testDownwardMeanDrift().To detect only upward drifts in $ s(t) $ use testUpwardMeanDrift(). To detect both, downward and upward drifts use testDownUpwardMeanDrift().

Tutorials & Examples

Tutorials
If you are interested in using Statistical Process Control methods, you may have a look at:

Examples
testSPC.cpp, and tutorial-meandrift.cpp.

Definition at line 77 of file vpStatisticalTestEWMA.h.

Member Typedef Documentation

◆ vpMeanDriftType

Enum that indicates if a drift of the mean occurred.

Member Enumeration Documentation

◆ vpMeanDriftType

Enum that indicates if a drift of the mean occurred.

Enumerator
MEAN_DRIFT_NONE 

No mean drift occurred

MEAN_DRIFT_DOWNWARD 

A downward drift of the mean occurred.

MEAN_DRIFT_UPWARD 

An upward drift of the mean occurred.

MEAN_DRIFT_BOTH 

Both an aupward and a downward drifts occurred.

MEAN_DRIFT_COUNT 
MEAN_DRIFT_UNKNOWN 
Examples
testSPC.cpp, and tutorial-meandrift.cpp.

Definition at line 69 of file vpStatisticalTestAbstract.h.

Constructor & Destructor Documentation

◆ vpStatisticalTestEWMA()

vpStatisticalTestEWMA::vpStatisticalTestEWMA ( const float & alpha = 0.1f)

Construct a new vpStatisticalTestEWMA object.

Parameters
[in]alphaThe forgetting factor.

Definition at line 90 of file vpStatisticalTestEWMA.cpp.

References vpStatisticalTestAbstract::init(), m_alpha, m_wt, m_wtprev, and vpStatisticalTestAbstract::vpStatisticalTestAbstract().

Member Function Documentation

◆ computeDeltaAndLimits()

BEGIN_VISP_NAMESPACE void vpStatisticalTestEWMA::computeDeltaAndLimits ( )
protectedvirtual

Compute the upper and lower limits of the test signal.

Definition at line 42 of file vpStatisticalTestEWMA.cpp.

References m_alpha, vpStatisticalTestAbstract::m_limitDown, vpStatisticalTestAbstract::m_limitUp, vpStatisticalTestAbstract::m_mean, and vpStatisticalTestAbstract::m_stdev.

Referenced by init(), and updateStatistics().

◆ detectDownwardMeanDrift()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestEWMA::detectDownwardMeanDrift ( )
protectedvirtual

Detects if a downward mean drift occurred.

Returns
vpMeanDriftType::MEAN_DRIFT_DOWNWARD if a downward mean drift occurred, vpMeanDriftType::MEAN_DRIFT_NONE otherwise.
See also
detectUpwardMeanDrift()

Implements vpStatisticalTestAbstract.

Definition at line 49 of file vpStatisticalTestEWMA.cpp.

References vpStatisticalTestAbstract::m_limitDown, m_wt, vpStatisticalTestAbstract::MEAN_DRIFT_DOWNWARD, and vpStatisticalTestAbstract::MEAN_DRIFT_NONE.

◆ detectUpwardMeanDrift()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestEWMA::detectUpwardMeanDrift ( )
protectedvirtual

Detects if an upward mean drift occurred on the mean.

Returns
vpMeanDriftType::MEAN_DRIFT_UPWARD if an upward mean drift occurred, vpMeanDriftType::MEAN_DRIFT_NONE otherwise.
See also
detectDownwardMeanDrift()

Implements vpStatisticalTestAbstract.

Definition at line 59 of file vpStatisticalTestEWMA.cpp.

References vpStatisticalTestAbstract::m_limitUp, m_wt, vpStatisticalTestAbstract::MEAN_DRIFT_NONE, and vpStatisticalTestAbstract::MEAN_DRIFT_UPWARD.

◆ getAlpha()

float vpStatisticalTestEWMA::getAlpha ( ) const
inline

Get the forgetting factor of the algorithm.

Returns
float The forgetting factor.

Definition at line 135 of file vpStatisticalTestEWMA.h.

References getAlpha(), and m_alpha.

Referenced by getAlpha().

◆ getAvailableMeanDriftType()

std::string vpStatisticalTestAbstract::getAvailableMeanDriftType ( const std::string & prefix = "<",
const std::string & sep = " , ",
const std::string & suffix = ">" )
staticinherited

Get the list of available vpMeanDriftType objects that are handled.

Parameters
[in]prefixThe prefix that should be placed before the list.
[in]sepThe separator between each element of the list.
[in]suffixThe suffix that should terminate the list.
Returns
std::string The list of handled type of process tests, presented as a string.
Examples
tutorial-meandrift.cpp.

Definition at line 85 of file vpStatisticalTestAbstract.cpp.

References MEAN_DRIFT_COUNT, and vpMeanDriftTypeToString().

◆ getLimits()

void vpStatisticalTestAbstract::getLimits ( float & limitDown,
float & limitUp ) const
inlineinherited

Get the upper and lower limits of the test signal.

Parameters
[out]limitDownThe lower limit.
[out]limitUpThe upper limit.
Examples
testSPC.cpp, and tutorial-meandrift.cpp.

Definition at line 181 of file vpStatisticalTestAbstract.h.

References m_limitDown, and m_limitUp.

◆ getMean()

float vpStatisticalTestAbstract::getMean ( ) const
inlineinherited

Get the mean used as reference.

Returns
float The mean.
Examples
tutorial-meandrift.cpp.

Definition at line 192 of file vpStatisticalTestAbstract.h.

References m_mean.

◆ getStdev()

float vpStatisticalTestAbstract::getStdev ( ) const
inlineinherited

Get the standard deviation used as reference.

Returns
float The standard deviation.
Examples
tutorial-meandrift.cpp.

Definition at line 202 of file vpStatisticalTestAbstract.h.

References m_stdev.

◆ getWt()

float vpStatisticalTestEWMA::getWt ( ) const
inline

Get the current value of the test signal.

Returns
float The current value of the test signal.
Examples
tutorial-meandrift.cpp.

Definition at line 145 of file vpStatisticalTestEWMA.h.

References m_wt.

◆ init() [1/3]

◆ init() [2/3]

void vpStatisticalTestEWMA::init ( const float & alpha)

Initialize the EWMA algorithm.

Parameters
[in]alphaThe forgetting factor.

Definition at line 99 of file vpStatisticalTestEWMA.cpp.

References vpStatisticalTestAbstract::init(), m_alpha, m_wt, m_wtprev, and vpStatisticalTestAbstract::setNbSamplesForStat().

◆ init() [3/3]

void vpStatisticalTestEWMA::init ( const float & alpha,
const float & mean,
const float & stdev )

Initialize the EWMA algorithm.

Parameters
[in]alphaThe forgetting factor.
[in]meanThe expected mean of the signal to monitor.
[in]stdevThe expected standard deviation of the signal to monitor.

Definition at line 109 of file vpStatisticalTestEWMA.cpp.

References computeDeltaAndLimits(), vpStatisticalTestAbstract::init(), m_alpha, vpStatisticalTestAbstract::m_areStatisticsComputed, vpStatisticalTestAbstract::m_mean, vpStatisticalTestAbstract::m_stdev, m_wt, m_wtprev, and vpStatisticalTestAbstract::setNbSamplesForStat().

◆ print()

void vpStatisticalTestAbstract::print ( const vpMeanDriftType & type)
staticinherited

Print the message corresponding to the type of mean drift.

Parameters
[in]typeThe type of mean drift.

Definition at line 98 of file vpStatisticalTestAbstract.cpp.

References vpMeanDriftTypeToString().

◆ setAlpha()

void vpStatisticalTestEWMA::setAlpha ( const float & alpha)

Set the forgetting factor.

Parameters
[in]alphaThe forgetting factor.

Definition at line 125 of file vpStatisticalTestEWMA.cpp.

References vpStatisticalTestAbstract::init().

◆ setMinStdev()

void vpStatisticalTestAbstract::setMinStdev ( const float & stdevmin)
inlineinherited

Set the minimum value of the standard deviation that is expected. The computed standard deviation cannot be lower this value if set.

Parameters
[in]stdevminThe minimum value of the standard deviation that is expected.

Definition at line 226 of file vpStatisticalTestAbstract.h.

References m_stdevmin.

◆ setNbSamplesForStat()

void vpStatisticalTestAbstract::setNbSamplesForStat ( const unsigned int & nbSamples)
inherited

Set the number of samples required to compute the mean and standard deviation of the signal and allocate the memory accordingly.

Parameters
[in]nbSamplesThe number of samples we want to use.

Definition at line 193 of file vpStatisticalTestAbstract.cpp.

References m_nbSamplesForStatistics, and m_s.

Referenced by vpStatisticalTestEWMA::init(), vpStatisticalTestEWMA::init(), vpStatisticalTestHinkley::init(), vpStatisticalTestHinkley::init(), vpStatisticalTestHinkley::init(), vpStatisticalTestMeanAdjustedCUSUM::init(), vpStatisticalTestMeanAdjustedCUSUM::init(), vpStatisticalTestSigma::init(), and operator=().

◆ testDownUpwardMeanDrift()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestAbstract::testDownUpwardMeanDrift ( const float & signal)
inherited

Test if a downward or an upward mean drift occurred according to the new value of the signal.

Parameters
[in]signalThe new value of the signal.
Returns
vpMeanDriftType The type of mean drift that occurred.
See also
testDownwardMeanDrift() testUpwardMeanDrift()
Examples
testSPC.cpp, and tutorial-meandrift.cpp.

Definition at line 202 of file vpStatisticalTestAbstract.cpp.

References detectDownwardMeanDrift(), detectUpwardMeanDrift(), m_areStatisticsComputed, MEAN_DRIFT_BOTH, MEAN_DRIFT_NONE, updateStatistics(), and updateTestSignals().

◆ testDownwardMeanDrift()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestAbstract::testDownwardMeanDrift ( const float & signal)
inherited

Test if a downward mean drift occurred according to the new value of the signal.

Parameters
[in]signalThe new value of the signal.
Returns
vpMeanDriftType The type of mean drift that occurred.
See also
testUpwardMeanDrift()

Definition at line 227 of file vpStatisticalTestAbstract.cpp.

References detectDownwardMeanDrift(), m_areStatisticsComputed, MEAN_DRIFT_NONE, updateStatistics(), and updateTestSignals().

◆ testUpwardMeanDrift()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestAbstract::testUpwardMeanDrift ( const float & signal)
inherited

Test if an upward mean drift occurred according to the new value of the signal.

Parameters
[in]signalThe new value of the signal.
Returns
vpMeanDriftType The type of mean drift that occurred.
See also
testDownwardMeanDrift()

Definition at line 239 of file vpStatisticalTestAbstract.cpp.

References detectUpwardMeanDrift(), m_areStatisticsComputed, MEAN_DRIFT_NONE, updateStatistics(), and updateTestSignals().

◆ updateStatistics()

bool vpStatisticalTestEWMA::updateStatistics ( const float & signal)
protectedvirtual

Update m_s and if enough values are available, compute the mean, the standard deviation and the limits.

Parameters
[in]signalThe new value of the signal to monitor.

Reimplemented from vpStatisticalTestAbstract.

Definition at line 69 of file vpStatisticalTestEWMA.cpp.

References computeDeltaAndLimits(), vpStatisticalTestAbstract::m_mean, m_wt, and vpStatisticalTestAbstract::updateStatistics().

◆ updateTestSignals()

void vpStatisticalTestEWMA::updateTestSignals ( const float & signal)
protectedvirtual

Update the test signals.

Parameters
[in]signalThe new value of the signal to monitor.

Implements vpStatisticalTestAbstract.

Definition at line 82 of file vpStatisticalTestEWMA.cpp.

References m_alpha, m_wt, and m_wtprev.

◆ vpMeanDriftTypeFromString()

vpStatisticalTestAbstract::vpMeanDriftType vpStatisticalTestAbstract::vpMeanDriftTypeFromString ( const std::string & name)
staticinherited

Cast a string into a vpMeanDriftType.

Parameters
[in]nameThe name of the mean drift.
Returns
vpMeanDriftType The corresponding vpMeanDriftType.
Examples
tutorial-meandrift.cpp.

Definition at line 68 of file vpStatisticalTestAbstract.cpp.

References MEAN_DRIFT_COUNT, MEAN_DRIFT_UNKNOWN, and vpMeanDriftTypeToString().

◆ vpMeanDriftTypeToString()

BEGIN_VISP_NAMESPACE std::string vpStatisticalTestAbstract::vpMeanDriftTypeToString ( const vpMeanDriftType & type)
staticinherited

Cast a vpMeanDriftType into a string.

Parameters
[in]typeThe type of mean drift.
Returns
std::string The corresponding message.
Examples
testSPC.cpp, and tutorial-meandrift.cpp.

Definition at line 42 of file vpStatisticalTestAbstract.cpp.

References vpException::fatalError, MEAN_DRIFT_BOTH, MEAN_DRIFT_DOWNWARD, MEAN_DRIFT_NONE, MEAN_DRIFT_UNKNOWN, and MEAN_DRIFT_UPWARD.

Referenced by getAvailableMeanDriftType(), print(), and vpMeanDriftTypeFromString().

Member Data Documentation

◆ m_alpha

float vpStatisticalTestEWMA::m_alpha
protected

Forgetting factor: the higher, the more weight the current signal value has.

Definition at line 80 of file vpStatisticalTestEWMA.h.

Referenced by computeDeltaAndLimits(), getAlpha(), init(), init(), updateTestSignals(), and vpStatisticalTestEWMA().

◆ m_areStatisticsComputed

◆ m_count

float vpStatisticalTestAbstract::m_count
protectedinherited

Current number of data used to compute the mean and the standard deviation.

Definition at line 115 of file vpStatisticalTestAbstract.h.

Referenced by vpStatisticalTestHinkley::computeMean(), init(), operator=(), updateStatistics(), vpStatisticalTestHinkley::updateTestSignals(), and vpStatisticalTestAbstract().

◆ m_limitDown

◆ m_limitUp

◆ m_mean

◆ m_nbSamplesForStatistics

unsigned int vpStatisticalTestAbstract::m_nbSamplesForStatistics
protectedinherited

Number of samples to use to compute the mean and the standard deviation.

Definition at line 119 of file vpStatisticalTestAbstract.h.

Referenced by init(), operator=(), setNbSamplesForStat(), updateStatistics(), and vpStatisticalTestAbstract().

◆ m_s

float* vpStatisticalTestAbstract::m_s
protectedinherited

Array that keeps the samples used to compute the mean and standard deviation.

Definition at line 120 of file vpStatisticalTestAbstract.h.

Referenced by init(), operator=(), setNbSamplesForStat(), updateStatistics(), vpStatisticalTestAbstract(), and ~vpStatisticalTestAbstract().

◆ m_stdev

◆ m_stdevmin

float vpStatisticalTestAbstract::m_stdevmin
protectedinherited

Minimum allowed standard deviation of the monitored signal.

Definition at line 122 of file vpStatisticalTestAbstract.h.

Referenced by setMinStdev(), updateStatistics(), and vpStatisticalTestAbstract().

◆ m_sumForMean

float vpStatisticalTestAbstract::m_sumForMean
protectedinherited

Sum of the samples used to compute the mean and standard deviation.

Definition at line 123 of file vpStatisticalTestAbstract.h.

Referenced by init(), vpStatisticalTestMeanAdjustedCUSUM::init(), operator=(), updateStatistics(), and vpStatisticalTestAbstract().

◆ m_wt

float vpStatisticalTestEWMA::m_wt
protected

Test signal that permits to raise an alarm.

Definition at line 81 of file vpStatisticalTestEWMA.h.

Referenced by detectDownwardMeanDrift(), detectUpwardMeanDrift(), getWt(), init(), init(), updateStatistics(), updateTestSignals(), and vpStatisticalTestEWMA().

◆ m_wtprev

float vpStatisticalTestEWMA::m_wtprev
protected

Previous value of the test signal.

Definition at line 82 of file vpStatisticalTestEWMA.h.

Referenced by init(), init(), updateTestSignals(), and vpStatisticalTestEWMA().