Skip to content
Snippets Groups Projects
Commit 42a123e1 authored by Josselin Massot's avatar Josselin Massot Committed by BaM
Browse files

Remove useless classes

parent 31df69d0
No related branches found
No related tags found
No related merge requests found
//////////////////////////////////////////////////////////////////////////////
///// CLASS Stat<T> //////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
///// CONSTRUCTOR ////////////////////////////////////////////////////////////
template <typename T>
Stat<T>::Stat () :
fn(0) , fmin(0) , fmax(0) , fsum(0) , fsum2(0)
{ ; }
//____________________________________________________________________________
template <typename T>
Stat<T>::Stat ( const Stat<T> & a ) :
fn(a.fn) , min(a.fmin) , fmax(a.fmax) , fsum(a.fsum) , fsum2(a.fsum2)
{ ; }
//____________________________________________________________________________
template <typename T> template <typename ITR>
Stat<T>::Stat ( const ITR first , const ITR last ) :
fn(0) , fmin(*first) , fmax(*first) , fsum(0) , fsum2(0)
{
for ( ITR it = first ; it != last ; ++it ) // do all in one loop
{
if ( *it > fmax ) { fmax = *it; }
if ( *it < fmin ) { fmin = *it; }
fsum += *it;
fsum2 += (*it) * (*it);
++fn;
}
}
///// DESTRUCTOR /////////////////////////////////////////////////////////////
template <typename T>
Stat<T>::~Stat ()
{ ; }
///// OPERATOR ///////////////////////////////////////////////////////////////
template <typename T>
Stat<T> & Stat<T>::operator = ( const Stat<T> & a )
{
if ( this != &a )
{
fn = a.fn;
fmin = a.fmin; fmax = a.fmax;
fsum = a.fsum; fsum2 = a.fsum2;
}
return *this;
}
//____________________________________________________________________________
template <typename T>
Stat<T> & Stat<T>::operator += ( const T t )
{ this->add( t ); }
///// GETTER /////////////////////////////////////////////////////////////////
template <typename T> std::size_t Stat<T>::n () const { return fn; }
//____________________________________________________________________________
template <typename T> T Stat<T>::min () const { return fmin; }
//____________________________________________________________________________
template <typename T> T Stat<T>::max () const { return fmax; }
//____________________________________________________________________________
template <typename T> T Stat<T>::amp () const { return fmax - fmin; }
//____________________________________________________________________________
template <typename T> T Stat<T>::avg () const { return fsum/fn; }
//____________________________________________________________________________
template <typename T> T Stat<T>::rms () const { return std::sqrt( (fsum*fsum)/fn - fsum2/fn ); }
///// SETTER /////////////////////////////////////////////////////////////////
template <typename T>
void Stat<T>::add ( T val )
{
fn += 1;
fmin = std::min( fmin , val ); fsum += val;
fmax = std::max( fmax , val ); fsum2 += val*val;
}
#ifndef CLASS_stat_h
#define CLASS_stat_h
#include <iostream>
#include <cmath>
/*!
\class Stat<T>
\brief Class to compute stat on container or on value which arrived progressively
#
La classe permet d'effectuer des statistiques sur un échantillion lors de la
construction ou en ajoutant au fur et à mesure des données.
Cette deuxième possibilité limite les valeurs statistiques calculables :
* Le minimum : $\min_{i} x_i$
* Le maximum : $\max_{i} x_i$
* L'amplitude : $\max_{i}x_i - \min_{i}x_i$
* La moyenne : $\bar{x} = \frac{1}{n}\sum_i x_i$
* L'écart-type (RMS) : $\sigma = \sqrt{ \frac{1}{n} \sum_{i}(x_i - \bar{x})^2 } = \sqrt{ \frac{1}{n}\sum_{i} x_i^2 - \bar{x}^2 }$
Petite précision, RMS signifie *Root Mean Square* ou moyenne quadratique en français. Celle-ci est identique à l'écart-type si la moyenne est nulle puisque la moyenne quadratique se calcule comme suit : $rms = \sqrt{\frac{1}{n}\sum_{i} x_i^2}$
!*/
template <typename T>
class Stat
{
public:
// CONSTRUCTOR
Stat ();
Stat ( const Stat<T> & );
template <typename ITR>
Stat ( const ITR , const ITR );
// DESTRUCTOR
~Stat ();
// OPERATOR
Stat<T> & operator = ( const Stat<T> & );
Stat<T> & operator += ( const T );
// GETTER
inline std::size_t n () const;
inline T min () const;
inline T max () const;
inline T amp () const;
inline T avg () const;
inline T rms () const;
// SETTER
inline void add ( const T );
private:
// ATTRIBUTS
std::size_t fn; // number of elements
T fmin; // minimum
T fmax; // maximum
T fsum; // sum of all
T fsum2; // sum of square
};
#include "stat.cpp"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment