Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F27037304
Confidence.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
Confidence.hpp
View Options
/***************************************************************************//**
*
* \file rosa/agent/Confidence.hpp
*
* \author David Juhasz (david.juhasz@tuwien.ac.at)
*
* \date 2017
*
* \brief Definition of the *confidence* *functionality*.
*
******************************************************************************/
#ifndef ROSA_AGENT_CONFIDENCE_HPP
#define ROSA_AGENT_CONFIDENCE_HPP
#include
"rosa/agent/History.hpp"
#include
"rosa/support/debug.hpp"
#include
<limits>
namespace
rosa
{
namespace
agent
{
/// Confidence validator.
///
/// Checks the plausibility of given values by validating if a valid region
/// contains them. It also capable of checking consistency by validating the
/// rate of change recorded by a `rosa::agent::History` object against a maximal
/// absolute valid rate of change.
///
/// \tparam T type of values to validate
///
/// \note The template is defined only for arithmetic types.
///
/// \note The lower bound is inclusive and the upper bound is exclusive.
///
/// \invariant The bounds are defined in a meaningful way:\code
/// LowerBound <= UpperBound
/// \endcode
template
<
typename
T
>
class
Confidence
:
public
Module
{
// Make sure the actual type argument is an arithmetic type.
STATIC_ASSERT
(
std
::
is_arithmetic
<
T
>::
value
,
"not arithmetic Confidence"
);
public
:
/// Unsigned type corresponding to `T`.
using
UT
=
unsigned_t
<
T
>
;
/// The minimal value of type `T`.
/// \note Not exist `V` of type `T` such that `V < Min`.
static
constexpr
T
Min
=
std
::
is_integral
<
T
>::
value
?
std
::
numeric_limits
<
T
>::
min
()
:
std
::
numeric_limits
<
T
>::
lowest
();
/// The maximal value of type `T`.
/// \note Not exist `V` of type `T` such that `V > Max`.
static
constexpr
T
Max
=
(
std
::
is_integral
<
T
>::
value
||
!
std
::
numeric_limits
<
T
>::
has_infinity
)
?
std
::
numeric_limits
<
T
>::
max
()
:
std
::
numeric_limits
<
T
>::
infinity
();
/// The maximal value of type `UT`.
/// \note Not exist `V` of type `UT` such that `V > UnsignedMax`.
static
constexpr
UT
UnsignedMax
=
(
std
::
is_integral
<
UT
>::
value
||
!
std
::
numeric_limits
<
UT
>::
has_infinity
)
?
std
::
numeric_limits
<
UT
>::
max
()
:
std
::
numeric_limits
<
UT
>::
infinity
();
private
:
/// The inclusive lower bound for plausibility check.
T
LowerBound
;
/// The exclusive upper bound for plausibility check.
T
UpperBound
;
/// The maximal absolute rate of change for consistency check.
UT
ChangeRate
;
public
:
/// Creates an instance by setting the validator variables.
///
/// \param LowerBound the lower bound for plausability check
/// \param UpperBound the upper bound for plausability check
/// \param ChangeRate maximal absolute rate of change for consistency check
///
/// \pre The bounds are defined in a meaningful way:\code
/// LowerBound <= UpperBound
/// \endcode
Confidence
(
const
T
LowerBound
=
Min
,
const
T
UpperBound
=
Max
,
const
UT
ChangeRate
=
UnsignedMax
)
noexcept
:
LowerBound
(
LowerBound
),
UpperBound
(
UpperBound
),
ChangeRate
(
ChangeRate
)
{
// Make sure Confidence is created in a valid state.
if
(
LowerBound
>
UpperBound
)
{
ROSA_CRITICAL
(
"Confidence with LowerBound higher than UpperBound"
);
}
}
/// Destroys `this` object.
~
Confidence
(
void
)
=
default
;
/// Gives a snapshot of the current state of the validator variables.
///
/// \param [out] LowerBound to copy `rosa::agent::Confidence::LowerBound` into
/// \param [out] UpperBound to copy `rosa::agent::Confidence::UpperBound` into
/// \param [out] ChangeRate to copy `rosa::agent::Confidence::ChangeRate` into
void
getParameters
(
T
&
LowerBound
,
T
&
UpperBound
,
UT
&
ChangeRate
)
const
noexcept
{
// Copy members to the given references.
LowerBound
=
this
->
LowerBound
;
UpperBound
=
this
->
UpperBound
;
ChangeRate
=
this
->
ChangeRate
;
}
/// Sets the lower bound for plausability check.
///
/// Beyond setting the lower bound, the function also adjusts the upper bound
/// to the given lower bound if the new lower bound would be higher than the
/// upper bound.
///
/// \param LowerBound the new lower bound to set
void
setLowerBound
(
const
T
LowerBound
)
noexcept
{
// Adjust UpperBound if necessary, then set LowerBound.
if
(
UpperBound
<
LowerBound
)
{
UpperBound
=
LowerBound
;
}
this
->
LowerBound
=
LowerBound
;
}
/// Sets the upper bound for plausability check.
///
/// Beyond setting the upper bound, the function also adjusts the lower bound
/// to the given upper bound if the new upper bound would be lower than the
/// lower bound.
///
/// \param UpperBound the new upper bound to set
void
setUpperBound
(
const
T
UpperBound
)
noexcept
{
// Adjust LowerBound if necessary, then set UpperBound.
if
(
UpperBound
<
LowerBound
)
{
LowerBound
=
UpperBound
;
}
this
->
UpperBound
=
UpperBound
;
}
/// Sets the maximal rate of change for consistency check.
///
/// \param ChangeRate the new rate of change to set
void
setChangeRate
(
const
UT
ChangeRate
)
noexcept
{
// Set ChangeRate.
this
->
ChangeRate
=
ChangeRate
;
}
/// Tells the binary confidence on the plausibility of a value.
///
/// \param V value to check
///
/// \return whether `V` is within the range defined by
/// `rosa::agent::Confidence::LowerBound` and
/// `rosa::agent::Confidence::UpperBound`.
bool
operator
()(
const
T
V
)
const
noexcept
{
// Return if V is plausible.
return
LowerBound
<=
V
&&
V
<
UpperBound
;
}
/// Tells the binary confidence on the plausibility and consistency of the
/// last value recorded by a `rosa::agent::History` instance.
///
/// Consistency of the last value is checked by validating the difference with
/// its preceding entry.
///
/// \note The `rosa::agent::History` instance needs to store values of type
/// `T`.
///
/// \note An empty `rosa::agent::History` instance results in full confidence.
///
/// \tparam N number of values `H` is able to store
/// \tparam P retention policy followed by `H` when capacity is reached
///
/// \param H *history* whose last entry to check
template
<
size_t
N
,
HistoryPolicy
P
>
bool
operator
()(
const
History
<
T
,
N
,
P
>
&
H
)
const
noexcept
{
if
(
H
.
empty
())
{
// No entry to validate.
return
true
;
}
else
{
// Validate the last entry and the one step average absolute difference.
return
(
*
this
)(
H
.
entry
())
&&
H
.
averageAbsDiff
(
1
)
<=
ChangeRate
;
}
}
};
}
// End namespace agent
}
// End namespace rosa
#endif
// ROSA_AGENT_CONFIDENCE_HPP
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Tue, Oct 27, 8:36 PM (20 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
411481
Default Alt Text
Confidence.hpp (6 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline