mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
add namespace - statistics
This commit is contained in:
parent
579620271f
commit
1125c85b3f
@ -11,13 +11,19 @@
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* \namespace statistics
|
||||
* \brief Statistical algorithms
|
||||
*/
|
||||
namespace statistics {
|
||||
|
||||
/**
|
||||
* continuous mean and variance computance using
|
||||
* first value as an approximation for the mean.
|
||||
* If the first number is much far form the mean, the algorithm becomes very
|
||||
* inaccurate to compute variance and standard deviation.
|
||||
*/
|
||||
template <typename T>
|
||||
class stats_computer1 {
|
||||
template <typename T>
|
||||
class stats_computer1 {
|
||||
public:
|
||||
/** Constructor
|
||||
* \param[in] x new data sample
|
||||
@ -55,14 +61,14 @@ class stats_computer1 {
|
||||
unsigned int n = 0;
|
||||
double Ex, Ex2;
|
||||
T K;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* continuous mean and variance computance using
|
||||
* Welford's algorithm (very accurate)
|
||||
*/
|
||||
template <typename T>
|
||||
class stats_computer2 {
|
||||
template <typename T>
|
||||
class stats_computer2 {
|
||||
public:
|
||||
/** Constructor
|
||||
* \param[in] x new data sample
|
||||
@ -98,7 +104,12 @@ class stats_computer2 {
|
||||
private:
|
||||
unsigned int n = 0;
|
||||
double mu = 0, var = 0, M = 0;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace statistics
|
||||
|
||||
using statistics::stats_computer1;
|
||||
using statistics::stats_computer2;
|
||||
|
||||
/** Test the algorithm implementation
|
||||
* \param[in] test_data array of data to test the algorithms
|
||||
|
Loading…
x
Reference in New Issue
Block a user