Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpStatisticalTestEWMA.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/vpStatisticalTestEWMA.h>
40
41
BEGIN_VISP_NAMESPACE
42
void
vpStatisticalTestEWMA::computeDeltaAndLimits
()
43
{
44
float
delta = 3.f *
m_stdev
* std::sqrt(
m_alpha
/ (2.f -
m_alpha
));
45
m_limitDown
=
m_mean
- delta;
46
m_limitUp
=
m_mean
+ delta;
47
}
48
49
vpStatisticalTestAbstract::vpMeanDriftType
vpStatisticalTestEWMA::detectDownwardMeanDrift
()
50
{
51
if
(
m_wt
<=
m_limitDown
) {
52
return
MEAN_DRIFT_DOWNWARD
;
53
}
54
else
{
55
return
MEAN_DRIFT_NONE
;
56
}
57
}
58
59
vpStatisticalTestAbstract::vpMeanDriftType
vpStatisticalTestEWMA::detectUpwardMeanDrift
()
60
{
61
if
(
m_wt
>=
m_limitUp
) {
62
return
MEAN_DRIFT_UPWARD
;
63
}
64
else
{
65
return
MEAN_DRIFT_NONE
;
66
}
67
}
68
69
bool
vpStatisticalTestEWMA::updateStatistics
(
const
float
&signal)
70
{
71
bool
areStatsReady =
vpStatisticalTestAbstract::updateStatistics
(signal);
72
if
(areStatsReady) {
73
// Computation of the limits
74
computeDeltaAndLimits
();
75
76
// Initialize first value
77
m_wt
=
m_mean
;
78
}
79
return
areStatsReady;
80
}
81
82
void
vpStatisticalTestEWMA::updateTestSignals
(
const
float
&signal)
83
{
84
// Update last value
85
m_wtprev
=
m_wt
;
86
// w(t) = alpha * s(t) + (1 - alpha) * w(t- 1);
87
m_wt
=
m_wtprev
+
m_alpha
* (signal -
m_wtprev
);
88
}
89
90
vpStatisticalTestEWMA::vpStatisticalTestEWMA
(
const
float
&alpha)
91
:
vpStatisticalTestAbstract
()
92
,
m_alpha
(0.f)
93
,
m_wt
(0.f)
94
,
m_wtprev
(0.f)
95
{
96
init
(alpha);
97
}
98
99
void
vpStatisticalTestEWMA::init
(
const
float
&alpha)
100
{
101
vpStatisticalTestAbstract::init
();
102
m_alpha
= alpha;
103
unsigned
int
nbRequiredSamples =
static_cast<
unsigned
int
>
(std::ceil(3.f /
m_alpha
));
104
setNbSamplesForStat
(nbRequiredSamples);
105
m_wt
= 0.f;
106
m_wtprev
= 0.f;
107
}
108
109
void
vpStatisticalTestEWMA::init
(
const
float
&alpha,
const
float
&mean,
const
float
&stdev)
110
{
111
vpStatisticalTestAbstract::init
();
112
m_alpha
= alpha;
113
m_mean
= mean;
114
unsigned
int
nbRequiredSamples =
static_cast<
unsigned
int
>
(std::ceil(3.f /
m_alpha
));
115
setNbSamplesForStat
(nbRequiredSamples);
116
m_stdev
= stdev;
117
m_wt
= mean;
118
m_wtprev
= 0.f;
119
120
// Computation of the limits
121
computeDeltaAndLimits
();
122
m_areStatisticsComputed
=
true
;
123
}
124
125
void
vpStatisticalTestEWMA::setAlpha
(
const
float
&alpha)
126
{
127
init
(alpha);
128
}
129
END_VISP_NAMESPACE
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
vpStatisticalTestEWMA::m_wt
float m_wt
Definition
vpStatisticalTestEWMA.h:81
vpStatisticalTestEWMA::vpStatisticalTestEWMA
vpStatisticalTestEWMA(const float &alpha=0.1f)
Construct a new vpStatisticalTestEWMA object.
Definition
vpStatisticalTestEWMA.cpp:90
vpStatisticalTestEWMA::updateTestSignals
virtual void updateTestSignals(const float &signal) VP_OVERRIDE
Update the test signals.
Definition
vpStatisticalTestEWMA.cpp:82
vpStatisticalTestEWMA::m_wtprev
float m_wtprev
Definition
vpStatisticalTestEWMA.h:82
vpStatisticalTestEWMA::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
vpStatisticalTestEWMA.cpp:69
vpStatisticalTestEWMA::computeDeltaAndLimits
virtual void computeDeltaAndLimits()
Compute the upper and lower limits of the test signal.
Definition
vpStatisticalTestEWMA.cpp:42
vpStatisticalTestEWMA::m_alpha
float m_alpha
Definition
vpStatisticalTestEWMA.h:80
vpStatisticalTestEWMA::setAlpha
void setAlpha(const float &alpha)
Set the forgetting factor.
Definition
vpStatisticalTestEWMA.cpp:125
vpStatisticalTestEWMA::detectUpwardMeanDrift
virtual vpMeanDriftType detectUpwardMeanDrift() VP_OVERRIDE
Detects if an upward mean drift occurred on the mean.
Definition
vpStatisticalTestEWMA.cpp:59
vpStatisticalTestEWMA::detectDownwardMeanDrift
virtual vpMeanDriftType detectDownwardMeanDrift() VP_OVERRIDE
Detects if a downward mean drift occurred.
Definition
vpStatisticalTestEWMA.cpp:49
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
core
src
math
misc
vpStatisticalTestEWMA.cpp
Generated by
1.17.0