-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_basic.cpp
More file actions
47 lines (40 loc) · 1.59 KB
/
example_basic.cpp
File metadata and controls
47 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* sample-moments library
*
* Copyright (c) 2021 Volodymyr Vovchenko
*
* Licensed under the MIT License <http://opensource.org/licenses/MIT>
*/
#include <SampleMoments.h> // The library
#include <random> // Random number generation
#include <iostream> // Output
// Sample usage with the normal distribution
int main() {
// Parameters of the normal distribution
double mean = 10.;
double sigma = 0.5;
// Random number generator from the normal distribution
std::mt19937 rng;
std::normal_distribution<double> distribution(mean, sigma);
// The number of observations
int number_of_observations = 100000;
// Populate the observations
std::vector<double> observations;
for(int i = 0; i < number_of_observations; ++i) {
double N = distribution(rng);
observations.push_back(N);
}
// Analyze the observations
SampleMoments::NumberStatistics stats(observations);
std::cout << " Sample mean: " << stats.GetMean()
<< " +- " << stats.GetMeanError() << std::endl;
std::cout << " Sample variance: " << stats.GetVariance()
<< " +- " << stats.GetVarianceError() << std::endl;
std::cout << " Sample skewness: " << stats.GetCentralMoment(3)
<< " +- " << stats.GetCentralMomentError(3) << std::endl;
std::cout << " Sample excess kurtosis: " << stats.GetCumulant(4)
<< " +- " << stats.GetCumulantError(4) << std::endl;
std::cout << "Sample normalized excess kurtosis: " << stats.GetCumulantRatio(4, 2)
<< " +- " << stats.GetCumulantRatioError(4, 2) << std::endl;
return 0;
}