Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpStatisticalTestMeanAdjustedCUSUM.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*/
30
38
39
#include <visp3/core/vpStatisticalTestMeanAdjustedCUSUM.h>
40
41
BEGIN_VISP_NAMESPACE
42
void
vpStatisticalTestMeanAdjustedCUSUM::computeDeltaAndLimits
()
43
{
44
setDelta
(
m_k
*
m_stdev
);
45
float
limitDown =
m_h
*
m_stdev
;
46
float
limitUp = limitDown;
47
setLimits
(limitDown, limitUp);
48
}
49
50
vpStatisticalTestAbstract::vpMeanDriftType
vpStatisticalTestMeanAdjustedCUSUM::detectDownwardMeanDrift
()
51
{
52
if
(
m_sminus
>=
m_limitDown
) {
53
return
MEAN_DRIFT_DOWNWARD
;
54
}
55
else
{
56
return
MEAN_DRIFT_NONE
;
57
}
58
}
59
60
vpStatisticalTestAbstract::vpMeanDriftType
vpStatisticalTestMeanAdjustedCUSUM::detectUpwardMeanDrift
()
61
{
62
if
(
m_splus
>=
m_limitUp
) {
63
return
MEAN_DRIFT_UPWARD
;
64
}
65
else
{
66
return
MEAN_DRIFT_NONE
;
67
}
68
}
69
70
bool
vpStatisticalTestMeanAdjustedCUSUM::updateStatistics
(
const
float
&signal)
71
{
72
bool
areStatsAvailable =
vpStatisticalTestAbstract::updateStatistics
(signal);
73
if
(areStatsAvailable) {
74
// Computation of the limits
75
if
((
m_limitDown
< 0.f) && (
m_limitUp
< 0.f)) {
76
computeDeltaAndLimits
();
77
}
78
79
// Initialize first values
80
m_sminus
= 0.f;
81
m_splus
= 0.f;
82
}
83
return
areStatsAvailable;
84
}
85
86
void
vpStatisticalTestMeanAdjustedCUSUM::updateTestSignals
(
const
float
&signal)
87
{
88
m_sminus
= std::max(0.f,
m_sminus
- (signal -
m_mean
) -
m_half_delta
);
89
m_splus
= std::max(0.f,
m_splus
+ (signal -
m_mean
) -
m_half_delta
);
90
}
91
92
vpStatisticalTestMeanAdjustedCUSUM::vpStatisticalTestMeanAdjustedCUSUM
(
const
float
&h,
const
float
&k,
const
unsigned
int
&nbPtsForStats)
93
:
vpStatisticalTestAbstract
()
94
,
m_delta
(-1.f)
95
,
m_h
(h)
96
,
m_half_delta
(-1.f)
97
,
m_k
(k)
98
,
m_sminus
(0.f)
99
,
m_splus
(0.f)
100
{
101
init
(h, k, nbPtsForStats);
102
}
103
104
void
vpStatisticalTestMeanAdjustedCUSUM::init
(
const
float
&h,
const
float
&k,
const
unsigned
int
&nbPtsForStats)
105
{
106
vpStatisticalTestAbstract::init
();
107
setNbSamplesForStat
(nbPtsForStats);
108
m_delta
= -1.f;
109
m_half_delta
= -1.f;
110
setLimits
(-1.f, -1.f);
// To compute automatically the limits once the signal statistics are available.
111
m_h
= h;
112
m_k
= k;
113
m_mean
= 0.f;
114
m_sminus
= 0.f;
115
m_splus
= 0.f;
116
m_stdev
= 0.f;
117
}
118
119
void
vpStatisticalTestMeanAdjustedCUSUM::init
(
const
float
&delta,
const
float
&limitDown,
const
float
&limitUp,
const
unsigned
int
&nbPtsForStats)
120
{
121
vpStatisticalTestAbstract::init
();
122
setDelta
(delta);
123
setLimits
(limitDown, limitUp);
124
setNbSamplesForStat
(nbPtsForStats);
125
m_sminus
= 0.f;
126
m_splus
= 0.f;
127
}
128
129
void
vpStatisticalTestMeanAdjustedCUSUM::init
(
const
float
&h,
const
float
&k,
const
float
&mean,
const
float
&stdev)
130
{
131
vpStatisticalTestAbstract::init
();
132
setLimits
(-1.f, -1.f);
// To compute automatically the limits once the signal statistics are available.
133
m_h
= h;
134
m_k
= k;
135
m_mean
= mean;
136
m_sminus
= 0.f;
137
m_splus
= 0.f;
138
m_stdev
= stdev;
139
// Compute delta and limits from m_h, m_k and m_stdev
140
computeDeltaAndLimits
();
141
m_areStatisticsComputed
=
true
;
142
}
143
144
void
vpStatisticalTestMeanAdjustedCUSUM::init
(
const
float
&delta,
const
float
&limitDown,
const
float
&limitUp,
const
float
&mean,
const
float
&stdev)
145
{
146
vpStatisticalTestAbstract::init
();
147
setDelta
(delta);
148
setLimits
(limitDown, limitUp);
149
m_mean
= mean;
150
m_sminus
= 0.f;
151
m_splus
= 0.f;
152
m_stdev
= stdev;
153
m_sumForMean
= 0.f;
154
m_areStatisticsComputed
=
true
;
155
}
156
END_VISP_NAMESPACE
vpStatisticalTestAbstract::m_sumForMean
float m_sumForMean
Definition
vpStatisticalTestAbstract.h:123
vpStatisticalTestAbstract::m_limitUp
float m_limitUp
Definition
vpStatisticalTestAbstract.h:117
vpStatisticalTestAbstract::vpMeanDriftType
vpMeanDriftType
Enum that indicates if a drift of the mean occurred.
Definition
vpStatisticalTestAbstract.h:70
vpStatisticalTestAbstract::MEAN_DRIFT_UPWARD
@ MEAN_DRIFT_UPWARD
Definition
vpStatisticalTestAbstract.h:73
vpStatisticalTestAbstract::MEAN_DRIFT_DOWNWARD
@ MEAN_DRIFT_DOWNWARD
Definition
vpStatisticalTestAbstract.h:72
vpStatisticalTestAbstract::MEAN_DRIFT_NONE
@ MEAN_DRIFT_NONE
Definition
vpStatisticalTestAbstract.h:71
vpStatisticalTestAbstract::init
void init()
(Re)Initialize the algorithm.
Definition
vpStatisticalTestAbstract.cpp:157
vpStatisticalTestAbstract::m_limitDown
float m_limitDown
Definition
vpStatisticalTestAbstract.h:116
vpStatisticalTestAbstract::vpStatisticalTestAbstract
vpStatisticalTestAbstract()
Construct a new vpStatisticalTestAbstract object.
Definition
vpStatisticalTestAbstract.cpp:131
vpStatisticalTestAbstract::updateStatistics
virtual bool updateStatistics(const float &signal)
Update m_s and if enough values are available, compute the mean, the standard deviation and the limit...
Definition
vpStatisticalTestAbstract.cpp:103
vpStatisticalTestAbstract::m_mean
float m_mean
Definition
vpStatisticalTestAbstract.h:118
vpStatisticalTestAbstract::setNbSamplesForStat
void setNbSamplesForStat(const unsigned int &nbSamples)
Set the number of samples required to compute the mean and standard deviation of the signal and alloc...
Definition
vpStatisticalTestAbstract.cpp:193
vpStatisticalTestAbstract::m_stdev
float m_stdev
Definition
vpStatisticalTestAbstract.h:121
vpStatisticalTestAbstract::m_areStatisticsComputed
bool m_areStatisticsComputed
Definition
vpStatisticalTestAbstract.h:114
vpStatisticalTestMeanAdjustedCUSUM::m_splus
float m_splus
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:96
vpStatisticalTestMeanAdjustedCUSUM::m_k
float m_k
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:94
vpStatisticalTestMeanAdjustedCUSUM::m_sminus
float m_sminus
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:95
vpStatisticalTestMeanAdjustedCUSUM::detectUpwardMeanDrift
virtual vpMeanDriftType detectUpwardMeanDrift() VP_OVERRIDE
Detects if a upward jump occurred on the mean.
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:60
vpStatisticalTestMeanAdjustedCUSUM::m_delta
float m_delta
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:90
vpStatisticalTestMeanAdjustedCUSUM::vpStatisticalTestMeanAdjustedCUSUM
vpStatisticalTestMeanAdjustedCUSUM(const float &h=4.f, const float &k=1.f, const unsigned int &nbPtsForStats=30)
Construct a new vpStatisticalTestMeanAdjustedCUSUM object.
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:92
vpStatisticalTestMeanAdjustedCUSUM::m_half_delta
float m_half_delta
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:93
vpStatisticalTestMeanAdjustedCUSUM::m_h
float m_h
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:91
vpStatisticalTestMeanAdjustedCUSUM::updateStatistics
virtual bool updateStatistics(const float &signal) VP_OVERRIDE
Update m_s and if enough values are available, compute the mean, the standard deviation and the limit...
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:70
vpStatisticalTestMeanAdjustedCUSUM::detectDownwardMeanDrift
virtual vpMeanDriftType detectDownwardMeanDrift() VP_OVERRIDE
Detects if a downward mean drift occurred.
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:50
vpStatisticalTestMeanAdjustedCUSUM::computeDeltaAndLimits
virtual void computeDeltaAndLimits()
Compute the upper and lower limits of the test signal.
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:42
vpStatisticalTestMeanAdjustedCUSUM::setDelta
void setDelta(const float &delta)
Set the slack of the CUSUM test, i.e. the minimum value of the jumps we want to detect.
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:248
vpStatisticalTestMeanAdjustedCUSUM::setLimits
void setLimits(const float &limitDown, const float &limitUp)
Set the upward and downward jump limits.
Definition
vpStatisticalTestMeanAdjustedCUSUM.h:260
vpStatisticalTestMeanAdjustedCUSUM::updateTestSignals
virtual void updateTestSignals(const float &signal) VP_OVERRIDE
Update the test signals.
Definition
vpStatisticalTestMeanAdjustedCUSUM.cpp:86
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
misc
vpStatisticalTestMeanAdjustedCUSUM.cpp
Generated by
1.17.0