OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::util::ExponentialMovingAverage< T, S > Class Template Reference

Exponential moving average. More...

#include <benchmarkUtil.h>

+ Inheritance diagram for olb::util::ExponentialMovingAverage< T, S >:
+ Collaboration diagram for olb::util::ExponentialMovingAverage< T, S >:

Public Member Functions

 ExponentialMovingAverage (const std::function< T(int)> smoothingFactorFunction=[](int i) -> T { return 2./(1+i);})
 (constructor)
 
void takeValue (const T val)
 compute next EMA with given value
 
void resetNoOfEntries ()
 reset number of entries
 
bool operator() (T output[], const S x[]) override
 has to be implemented for 'every' derived class
 
- Public Member Functions inherited from olb::AnalyticalF< 1, T, S >
AnalyticalF< D, T, S > & operator- (AnalyticalF< D, T, S > &rhs)
 
AnalyticalF< D, T, S > & operator+ (AnalyticalF< D, T, S > &rhs)
 
AnalyticalF< D, T, S > & operator* (AnalyticalF< D, T, S > &rhs)
 
AnalyticalF< D, T, S > & operator/ (AnalyticalF< D, T, S > &rhs)
 
- Public Member Functions inherited from olb::GenericF< T, S >
virtual ~GenericF ()=default
 
int getSourceDim () const
 read only access to member variable _m
 
int getTargetDim () const
 read only access to member variable _n
 
std::string & getName ()
 read and write access to name
 
std::string const & getName () const
 read only access to name
 
bool operator() (T output[])
 wrapper that call the pure virtual operator() (T output[], const S input[]) from above
 
bool operator() (T output[], S input0)
 
bool operator() (T output[], S input0, S input1)
 
bool operator() (T output[], S input0, S input1, S input2)
 
bool operator() (T output[], S input0, S input1, S input2, S input3)
 

Additional Inherited Members

- Public Types inherited from olb::AnalyticalF< 1, T, S >
using identity_functor_type
 
- Public Types inherited from olb::GenericF< T, S >
using targetType = T
 
using sourceType = S
 
- Public Attributes inherited from olb::GenericF< T, S >
std::shared_ptr< GenericF< T, S > > _ptrCalcC
 memory management, frees resouces (calcClass)
 
- Static Public Attributes inherited from olb::AnalyticalF< 1, T, S >
static constexpr unsigned dim
 
- Protected Member Functions inherited from olb::AnalyticalF< 1, T, S >
 AnalyticalF (int n)
 
- Protected Member Functions inherited from olb::GenericF< T, S >
 GenericF (int targetDim, int sourceDim)
 

Detailed Description

template<typename T, typename S>
class olb::util::ExponentialMovingAverage< T, S >

Exponential moving average.

Compute the exponential moving average of given values $y_t$ with smoothing factor $\alpha$. $ EMA = \alpha \cdot y_t + (1-\alpha) \cdot EMA_{t-1} $ for noOfEntries $ t > 1 $

Definition at line 180 of file benchmarkUtil.h.

Constructor & Destructor Documentation

◆ ExponentialMovingAverage()

template<typename T , typename S >
olb::util::ExponentialMovingAverage< T, S >::ExponentialMovingAverage ( const std::function< T(int)> smoothingFactorFunction = [](int i) -> T { return 2. / (1 + i); })

(constructor)

Parameters
smoothingFactorFunction$\alpha$ between 0 and 1. function object e.g. a lambda expression of type <T(int)> (return type T, int argument to process number of entries inside lambda)

Definition at line 374 of file benchmarkUtil.hh.

376 : AnalyticalF1D<T,S>(1),
377 _smoothingFactorFunction(smoothingFactorFunction),
378 _EMA(0),
379 _noOfEntries(0) {}

Member Function Documentation

◆ operator()()

template<typename T , typename S >
bool olb::util::ExponentialMovingAverage< T, S >::operator() ( T output[],
const S input[] )
overridevirtual

has to be implemented for 'every' derived class

Implements olb::GenericF< T, S >.

Definition at line 404 of file benchmarkUtil.hh.

405{
406 output[0] = _EMA;
407 return true;
408}

◆ resetNoOfEntries()

template<typename T , typename S >
void olb::util::ExponentialMovingAverage< T, S >::resetNoOfEntries ( )

reset number of entries

Definition at line 397 of file benchmarkUtil.hh.

398{
399 _noOfEntries = 0;
400}

◆ takeValue()

template<typename T , typename S >
void olb::util::ExponentialMovingAverage< T, S >::takeValue ( const T val)

compute next EMA with given value

Definition at line 382 of file benchmarkUtil.hh.

383{
384 if (_noOfEntries == 0) {
385 _noOfEntries++;
386 _EMA = val;
387
388 }
389 else {
390 _noOfEntries++;
391 S smoothingFactor = _smoothingFactorFunction(_noOfEntries);
392 _EMA = val* smoothingFactor + _EMA * (1 - smoothingFactor);
393 }
394}

The documentation for this class was generated from the following files: