StatisticalTestHinkley¶
- class StatisticalTestHinkley(*args, **kwargs)¶
Bases:
StatisticalTestAbstract
This class implements the Hinkley’s cumulative sum test.
The Hinkley’s cumulative sum test is designed to detect drift in the mean of an observed signal \(s(t)\) . It is known to be robust (by taking into account all the past of the observed quantity), efficient, and inducing a very low computational load. The other attractive features of this test are two-fold. First, it can straightforwardly and accurately provide the drift instant. Secondly, due to its formulation (cumulative sum test), it can simultaneously handle both very abrupt and important changes, and gradual smaller ones without adapting the involved thresholds.
Two tests are performed in parallel to look for downwards or upwards drifts in \(s(t)\) , respectively defined by:
\[S_k = \sum_{t=0}^{k} (s(t) - m_0 + \frac{\delta}{2}) \]\[M_k = \max_{0 \leq i \leq k} S_i\]\[T_k = \sum_{t=0}^{k} (s(t) - m_0 - \frac{\delta}{2}) \]\[N_k = \min_{0 \leq i \leq k} T_i\]In which \(m_o\) is computed on-line and corresponds to the mean of the signal \(s(t)\) we want to detect a drift. \(m_o\) is re-initialized at zero after each drift detection. \(\delta\) denotes the drift minimal magnitude that we want to detect and \(\alpha\) is a predefined threshold. These values are set by default to 0.2 in the default constructor vpHinkley(). To modify the default values use setAlpha() and setDelta() or the vpHinkley(double alpha, double delta) constructor.
A downward drift is detected if \(M_k - S_k > \alpha\) . A upward drift is detected if \(T_k - N_k > \alpha\) .
To detect only downward drifts in \(s(t)\) use testDownwardMeanDrift() .To detect only upward drifts in \(s(t)\) use testUpwardMeanDrift() . To detect both, downward and upward drifts use testDownUpwardMeanDrift() .
If a drift is detected, the drift location is given by the last instant \(k^{'}\) when \(M_{k^{'}} - S_{k^{'}} = 0\) , or \(T_{k^{'}} - N_{k^{'}} = 0\) .
Overloaded function.
__init__(self: visp._visp.core.StatisticalTestHinkley) -> None
Construct a new vpStatisticalTestHinkley object. Call init() to initialise the Hinkley’s test and set \(\alpha\) and \(\delta\) to default values.
By default \(\delta = 0.2\) and \(\alpha = 0.2\) . Use setDelta() and setAlpha() to modify these values.
__init__(self: visp._visp.core.StatisticalTestHinkley, alpha: float, delta: float, nbSamplesForInit: int = 30) -> None
Call init() to initialise the Hinkley’s test and set \(\alpha\) and \(\delta\) thresholds.
Note
See setAlpha() , setDelta()
- Parameters:
- alpha
math:alpha threshold indicating that a mean drift occurs.
- delta
math:delta denotes the drift minimal magnitude that we want to detect.
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
__init__(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, computeAlphaDeltaFromStdev: bool, nbSamplesForInit: int = 30) -> None
Construct a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- computeAlphaDeltaFromStdev
must be equal to true, otherwise throw a vpException .
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
__init__(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, mean: float, stdev: float) -> None
Construct a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- mean
the expected mean of the signal.
- stdev
the expected standard deviation of the signal.
Methods
Overloaded function.
Get the \(\alpha\) threshold indicating that a mean drift occurs.
Get the maximum of the test signal for downward mean drift \(S_k\) .
Get the minimum of the test signal for upward mean drift \(T_k\) .
Get the test signal for downward mean drift.
Get the test signal for upward mean drift..
Overloaded function.
The threshold indicating that a mean drift occurs.
Set the drift minimal magnitude that we want to detect.
Inherited Methods
MEAN_DRIFT_NONE
Get the mean used as reference.
Set the number of samples required to compute the mean and standard deviation of the signal and allocate the memory accordingly.
MEAN_DRIFT_DOWNWARD
MEAN_DRIFT_BOTH
MEAN_DRIFT_COUNT
Get the upper and lower limits of the test signal.
Cast a string into a vpMeanDriftType .
MEAN_DRIFT_UNKNOWN
Set the minimum value of the standard deviation that is expected.
Get the standard deviation used as reference.
Enum that indicates if a drift of the mean occurred.
MEAN_DRIFT_UPWARD
Test if a downward or an upward mean drift occurred according to the new value of the signal.
Test if a downward mean drift occurred according to the new value of the signal.
Get the list of available vpMeanDriftType objects that are handled.
Test if an upward mean drift occurred according to the new value of the signal.
Operators
__doc__
Overloaded function.
__module__
Attributes
MEAN_DRIFT_BOTH
MEAN_DRIFT_COUNT
MEAN_DRIFT_DOWNWARD
MEAN_DRIFT_NONE
MEAN_DRIFT_UNKNOWN
MEAN_DRIFT_UPWARD
__annotations__
- class MeanDriftType(self, value: int)¶
Bases:
pybind11_object
Enum that indicates if a drift of the mean occurred.
Values:
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
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.StatisticalTestHinkley) -> None
Construct a new vpStatisticalTestHinkley object. Call init() to initialise the Hinkley’s test and set \(\alpha\) and \(\delta\) to default values.
By default \(\delta = 0.2\) and \(\alpha = 0.2\) . Use setDelta() and setAlpha() to modify these values.
__init__(self: visp._visp.core.StatisticalTestHinkley, alpha: float, delta: float, nbSamplesForInit: int = 30) -> None
Call init() to initialise the Hinkley’s test and set \(\alpha\) and \(\delta\) thresholds.
Note
See setAlpha() , setDelta()
- Parameters:
- alpha
math:alpha threshold indicating that a mean drift occurs.
- delta
math:delta denotes the drift minimal magnitude that we want to detect.
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
__init__(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, computeAlphaDeltaFromStdev: bool, nbSamplesForInit: int = 30) -> None
Construct a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- computeAlphaDeltaFromStdev
must be equal to true, otherwise throw a vpException .
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
__init__(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, mean: float, stdev: float) -> None
Construct a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- mean
the expected mean of the signal.
- stdev
the expected standard deviation of the signal.
- getAlpha(self) float ¶
Get the \(\alpha\) threshold indicating that a mean drift occurs.
- Returns:
The \(\alpha\) threshold.
- static getAvailableMeanDriftType(prefix: str = <, sep: str =, suffix: str = >) str ¶
Get the list of available vpMeanDriftType objects that are handled.
- Parameters:
- prefix
The prefix that should be placed before the list.
- sep
The separator between each element of the list.
- suffix
The suffix that should terminate the list.
- Returns:
std::string The list of handled type of process tests, presented as a string.
- getLimits(self, limitDown: float, limitUp: float) tuple[float, float] ¶
Get the upper and lower limits of the test signal.
- getMk(self) float ¶
Get the maximum of the test signal for downward mean drift \(S_k\) .
- Returns:
The value of \(M_k\) , the maximum value of \(S_k\) .
- getNk(self) float ¶
Get the minimum of the test signal for upward mean drift \(T_k\) .
- Returns:
The value of \(N_k\) , the minimum value of \(T_k\) .
- getSk(self) float ¶
Get the test signal for downward mean drift.
- Returns:
The value of \(S_k = \sum_{t=0}^{k} (s(t) - m_0 + \frac{\delta}{2})\) .
- getStdev(self) float ¶
Get the standard deviation used as reference.
- Returns:
float The standard deviation.
- getTk(self) float ¶
Get the test signal for upward mean drift..
- Returns:
The value of \(T_k = \sum_{t=0}^{k} (s(t) - m_0 - \frac{\delta}{2})\) .
- init(*args, **kwargs)¶
Overloaded function.
init(self: visp._visp.core.StatisticalTestHinkley) -> None
Initialise the Hinkley’s test by setting the mean signal value \(m_0\) to zero as well as \(S_k, M_k, T_k, N_k\) .
init(self: visp._visp.core.StatisticalTestHinkley, alpha: float, delta: float, nbSamplesForInit: int) -> None
Call init() to initialise the Hinkley’s test and set \(\alpha\) and \(\delta\) thresholds.
- Parameters:
- alpha
The threshold indicating that a mean drift occurs.
- delta
The drift minimal magnitude that we want to detect.
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
init(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, computeAlphaDeltaFromStdev: bool, nbSamplesForInit: int) -> None
(Re)Initialize a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- computeAlphaDeltaFromStdev
must be equal to true, otherwise throw a vpException .
- nbSamplesForInit
number of signal samples to initialize the mean of the signal.
init(self: visp._visp.core.StatisticalTestHinkley, alpha: float, delta: float, mean: float) -> None
Call init() to initialise the Hinkley’s test, set \(\alpha\) and \(\delta\) thresholds, and the mean of the signal \(m_0\) .
- Parameters:
- alpha
The threshold indicating that a mean drift occurs.
- delta
The drift minimal magnitude that we want to detect.
- mean
The expected value of the mean.
init(self: visp._visp.core.StatisticalTestHinkley, h: float, k: float, mean: float, stdev: float) -> None
(Re)Initialize a new vpStatisticalTestHinkley object. \(\alpha\) and \(\delta\) will be computed from the standard deviation of the signal.
- Parameters:
- h
the alarm factor that permits to compute \(\alpha\) from the standard deviation.
- k
the detection factor that permits to compute \(\delta\) from the standard deviation.
- mean
the expected mean of the signal.
- stdev
the expected standard deviation of the signal.
init(self: visp._visp.core.StatisticalTestAbstract) -> None
(Re)Initialize the algorithm.
- static print(type: visp._visp.core.StatisticalTestAbstract.MeanDriftType) None ¶
- setMinStdev(self, stdevmin: float) None ¶
Set the minimum value of the standard deviation that is expected. The computed standard deviation cannot be lower this value if set.
- setNbSamplesForStat(self, nbSamples: int) None ¶
Set the number of samples required to compute the mean and standard deviation of the signal and allocate the memory accordingly.
- testDownUpwardMeanDrift(self, signal: float) visp._visp.core.StatisticalTestAbstract.MeanDriftType ¶
Test if a downward or an upward mean drift occurred according to the new value of the signal.
Note
See testDownwardMeanDrift() testUpwardMeanDrift()
- testDownwardMeanDrift(self, signal: float) visp._visp.core.StatisticalTestAbstract.MeanDriftType ¶
Test if a downward mean drift occurred according to the new value of the signal.
Note
See testUpwardMeanDrift()
- testUpwardMeanDrift(self, signal: float) visp._visp.core.StatisticalTestAbstract.MeanDriftType ¶
Test if an upward mean drift occurred according to the new value of the signal.
Note
See testDownwardMeanDrift()
- static vpMeanDriftTypeFromString(name: str) visp._visp.core.StatisticalTestAbstract.MeanDriftType ¶
Cast a string into a vpMeanDriftType .
- static vpMeanDriftTypeToString(type: visp._visp.core.StatisticalTestAbstract.MeanDriftType) str ¶