66 : m_statistic(statistic)
73 return std::move(m_statistic);
81 std::unique_ptr<Statistic> m_statistic;
101 : m_smoothFactor( smoothFactor ), m_s( initialObservation ) {}
105 m_s += m_smoothFactor * ( observation - m_s );
159 agx::Real absDeltaObservation = std::abs( m_s - observation );
160 agx::Real absStatistic = std::abs( m_s );
161 agx::Real alpha = ( absDeltaObservation > 0 && absStatistic > 0 ? absStatistic / absDeltaObservation : m_smoothFactor );
163 m_s += alpha * ( observation - m_s );
187 : m_maxHistorySize(maxHistorySize)
189 m_historyByAge.reserve(m_maxHistorySize);
190 m_historyByValue.reserve(m_maxHistorySize);
198 size_t n = this->getCurrentHistorySize();
205 size_t middle = n / 2;
208 return (m_historyByValue[middle - 1] + m_historyByValue[middle]) /
agx::Real(2.0);
211 return m_historyByValue[middle];
222 while (this->getCurrentHistorySize() >= this->getMaxHistorySize()) {
224 m_historyByAge.pop_back();
225 m_historyByValue.findAndErase(v,
false);
230 auto insertAt = lower_bound(begin(m_historyByValue), end(m_historyByValue), observation);
231 m_historyByValue.insert(insertAt, observation);
232 m_historyByAge.insert(
size_t(0), observation);
240 m_historyByAge.clear();
241 m_historyByValue.clear();
247 return m_maxHistorySize;
254 agxAssert(m_historyByAge.size() == m_historyByValue.size());
255 size_t n = m_historyByAge.size();
262 return m_historyByAge;
268 return m_historyByValue;
277 size_t m_maxHistorySize;
293 : m_maxHistorySize( maxHistorySize ) {}
297 m_values.push_back( observation );
298 if ( m_values.size() > m_maxHistorySize ) {
299 m_values.erase( m_values.begin() );
306 if ( m_values.empty() )
return 0;
311 return sum /
static_cast< agx::Real >( m_values.size() );
317 size_t maxHistorySize )
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXPHYSICS_EXPORT
Exponential moving average statistic.
ExponentialMovingAverageStatistic(agx::Real smoothFactor, agx::Real initialObservation=0)
virtual agx::Real update(agx::Real observation)
Updates the statistic given the current observation and returns the current value of this statistic.
void setSmoothFactor(agx::Real smoothFactor)
virtual agx::Real get() const
static StatisticHandleRef make_statistic(agx::Real maxSmoothingFactor, agx::Real initialObservation=0)
agx::Real getSmoothFactor() const
virtual ~ExponentialMovingAverageStatistic()
void set(agx::Real val)
Set the raw value of the statistic scalar.
Simple moving average statistic.
virtual agx::Real update(agx::Real observation)
Updates the statistic given the current observation and returns the current value of this statistic.
virtual agx::Real get() const
MovingAverageStatistic(size_t maxHistorySize)
static StatisticHandleRef make_statistic(size_t maxHistorySize)
virtual ~MovingAverageStatistic()
Extra level of indirection provided for use by garbage collected languages.
virtual ~StatisticHandle()
StatisticHandle(Statistic *statistic)
std::unique_ptr< Statistic > takeStatistic()
Pure virtual statistic class containing the fundamentals for implementing a statistics method.
virtual agx::Real get() const =0
virtual agx::Real update(agx::Real observation)=0
Updates the statistic given the current observation and returns the current value of this statistic.
Variable Smooth Factor Exponential Moving Average statistic.
virtual agx::Real update(agx::Real observation)
Updates the statistic given the current observation and returns the current value of this statistic.
static StatisticHandleRef make_statistic(agx::Real maxSmoothingFactor, agx::Real initialObservation=0)
VariableSmoothFactorEMAStatistic(agx::Real maxSmoothingFactor, agx::Real initialObservation=0)
virtual ~VariableSmoothFactorEMAStatistic()
Base class providing referencing counted objects.
Smart pointer for handling referenced counted objects.
The agxUtil namespace contain classes and methods for utility functionality.
T1 clamp(T1 v, T2 minimum, T3 maximum)