statistics is a header only cplusplus library which you can use to make statistical computations easily.
Just #include
the statistics.h
file in your C++ programs and you're good to go.
- Checks if a given number is even or not
- T: Type of the number. Accepted values: int, float, double
- number: The number to be checked if its even or not.
- true if the given number is even, false otherwise.
bool isEvenNumber = statistics::isEven<int>(3);
bool isEvenFloat = statistics::isEven<float>(4.0);
- Calculates the mean of the elements in
data
.
- T: Type of the elements
- data: The vector containing the elements whose mean is to be calculated
- the mean of the given elements in the array as a
float
std::vector<float> myNumbers{3.4, 8.9, 6. -4.5, 0.8};
std::cout << "Mean of my numbers is " << statistics::mean<float>(myNumbers);
- Calculates the median of the elements in
data
.
- T: Type of the elements
- data: The vector containing the elements whose median is to be calculated
- the mean of the given elements in the array as a
float
std::vector<float> myNumbers{3.4, 8.9, 6. -4.5, 0.8};
std::cout << "Median of my numbers is " << statistics::median<float>(myNumbers);
- Calculates the variance of the elements in
data
.
- T: Type of the elements
- data: The vector containing the elements whose variance is to be calculated
- the variance of the given elements in the array as a
float
std::vector<float> myNumbers{3.4, 8.9, 6. -4.5, 0.8};
std::cout << "Variance of my numbers is " << statistics::variance<float>(myNumbers);
- Calculates the standard deviation of the elements in
data
.
- T: Type of the elements
- data: The vector containing the elements whose standard deviation is to be calculated
- the standard deviation of the given elements in the array as a
float
std::vector<float> myNumbers{3.4, 8.9, 6. -4.5, 0.8};
std::cout << "sigma of my numbers is " << statistics::standard_deviation<float>(myNumbers);
- Generates a vector of random numbers of given type
T
with the given options.
- T: Type of the random numbers to be generated.
- opts: An instance of class
genRandomOpts
with set values of parameters required to generate the random numbers.- opts.min_val: Lowest boundary for the random numbers
- opts.max_val: Maximum boundary for the random numbers
- opts.mean: Mean of the random numbers
- opts.dist: Type of probability distribution of the numbers. Accepted values:
- statistics::NORMAL,
- statistics::UNIFORM,
- statistics::BINOMIAL,
- statistics::BERNOULLI,
- statistics::POISSON,
- statistics::EXPONENTIAL
- opts.standard_deviation: Std Deviation of the random numbers.
- An array of random numbers with the given type.
statistics::genRandomOptions opts{};
opts.dist = statistics::NORMAL;
opts.size = 10000;
opts.min_val = 1;
opts.max_val = 1000;
opts.mean = 500;
opts.standard_deviation = 200;
std::vector<float> randomFloats = statistics::genRandom<float>(opts);
Feel free to raise a pull with description and I'll take a look at it.