Skip to content

Lienar algebra, data manipulation and statistical library written in C++, for C++.

License

Notifications You must be signed in to change notification settings

julienlargetpiet/fulgurance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Table Of Contents




INTRODUCTION:

Stylished documentation is available here

In current development.

This framework provides functions for statistical analysis, machine learning, parsing and data manipulation with its own implementation of matrices and dataframes. Other tools can be found at fulgurance_tools part.

The framework is developped with C++ 14 but should work properly with 11 and 17 and furthers.

The main branch provides algorithms developped on the top of stl vector, but a deque version is coming.

Philosophy

Matrices and dataframes implementation are classes. All functions that will transform 'voidly' (internaly) the relative data are built in the classes. All functions that copy and transform the relative data are extern to classes.

Also, all the functions relative to matrices classes exist for more standard type of matrices that is stl 2D vectors.



Commun functions

On elements

Standard operations

mod

#Usage

template <typename T> double mod(T &dividend, T &divider)

#Description

Returns the mod of 2 number (int, float or double)

#Arguments

NameDefinition
a is an the dividend (int, float, double)
b is the divider (int, float, double)

#Example(s)

float a = 45.216;
float b = 3.2164;
mod(a, b)
0.186401


int_lngth

#Usage

int int_lngth(const int &x)

#Description

Returns the length of an int.

#Arguments

NameDefinition
x is an int

#Example(s)

int a = 896;
int_lngth(a);
3


roundout

#Usage

template <typename T> T roundout(T x, int n)

#Description

Returns a rounded value with decimal precision.

#Arguments

NameDefinition
x is an int, float, double
n is an int indicating the decimal precision

#Example(s)

float x = 34.476;
int n = 2;
float out = roundout(x, n);
34.48
n = 0;
out = roundout(x, n);
34
n = -1;
out = roundout(x, n)
30


roundin

#Usage

template <typename T> void roundin(T &x, int n)

#Description

Transforms the input value to a rounded value with decimal precision.

#Arguments

NameDefinition
x is an int, float, double
n is an int indicating the decimal precision

#Example(s)

float x = 34.476
int n = 2;
roundin(x, n);
34.48
n = 0;
x = 67.754;
roundin(x, n);
68
n = -1;
roundin(x, n);
70


randint

#Usage

auto randint(const int &min, const int max, int seed = -1)

#Description

Returns a pseudo-random number between min and max.

#Arguments

NameDefinition
min is an int
max is a max
seed is an int that determines the pseudo-random output, defaults to -1, so the seed will be randomly picked up by default, if you want to determine the output, choose a seed between 0 and 9.

#Example(s)

int min = -300;
int max = 100;
randint(min, max);
-14
randint(min, max);
-231
// If you want to generate a float just do:
double x = randint(min, max);
min = 0;
max = 900;
x += randint(min, max) / 1000;
-13.257


logn

#Usage

template <typename T, typename T2> double logn(T &val, T2 &base)

#Description

Returns the logarithm of any positive number to any base. This generalizes the log(value) / log(base) method.

#Arguments

NameDefinition
val is the value of the logarith base n (must be positive)
base is the base of the logarithm

#Example(s)

double val = 2.63;
int base = 10;
logn(val, base);
0.419956
base = 2;
1.39506


Facto

#Usage

unsigned int Facto(unsigned int x)

#Description

Returns the factorial of a positive integer.

#Arguments

NameDefinition
x is a unsigned integer

#Example(s)

Facto(7);
5040
Facto(0);
1


Comb

#Usage

double Comb(double r, double n)

#Description

Returns the result of the combination formula for given parameters.

#Arguments

NameDefinition
r is the number of objects choosen among the set
n is the number of objects in the set

#Example(s)

Comb(2, 5);
10
Comb(5, 12);
792


String to int, float, double

si

#Usage

int si(const std::string &x)

#Description

Returns a std::string that can be converted to an int, to an int.

#Arguments

NameDefinition
x is a stl string that can be converted to an int

#Example(s)

std::string a = "341";
int out = si(a);
341


sf

#Usage

float sf(const std::string &x)

#Description

Returns a converted std::string that can be converted to a float, to a float. Produces the same results than stof.

#Arguments

NameDefinition
x is a stl string that can be converted to a float

#Example(s)

std::string a = "44.23";
float out = sf(a);
44.23


sf2

#Usage

float sf2(const std::string &x)

#Description

Returns a converted std::string that can be converted to a float, to a float. Uses another algorithm than edm1_sf.

#Arguments

NameDefinition
x is a stl string that can be converted to a float

#Example(s)

std::string a = "44.23";
float out = sf2(a);
44.23


stod

#Usage

double stod(const std::string &x)

#Description

Returns a converted std::string, that can be converted to a double, to a double.

#Arguments

NameDefinition
x is a stl string

#Example(s)

std::string a = "4566.132214";
double out = stod(a);
4566.132214


Int, double, to string

#Usage

std::string itos(unsigned int x)

#Description

Returns the input integer as a std string.

#Arguments

NameDefinition
is an unsigned int

#Example(s)

itos(45897);
"45897"


On std::vector<Type>

Statistical functions

sum

#Usage

template <typename T> T sum(const std::vector<T> &x)

#Description

Returns the sum of all elements in a vector (int, float, double, bool).

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<double> vec = {1.434, 22.3322, 32423.097};
double out = sum(vec);
32446.8632


Mean

#Usage

template <typename T> T Mean(const std::vector<T> &x)

#Description

Returns the mean of all elements in a vector (int, float, double, bool).

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 4, 2};
double out = Mean(vec);
2.333333


quantile

#Usage

template <typename T, typename T2> double quantile(std::vector<T> &x, T2 &prob, double precision = 0.001)

#Description

Returns the quantile value for a given probability between 0 and 1 for an input stl vector (int, float, double, bool). If you just want to calculate median, the med() function is more straight forward.

#Arguments

NameDefinition
x stl vector (int, float, double, bool), must be ascendly sorted
prob is the probability(float, double)
precision is a double value representing the accuracy of the result. The lower the value is, higher the accuracy will be.

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<int> vec2 = {1, 2, 3, 4};
double prob = 0.89;
quantile(vec2, prob);
3.67188
prob = 0.65;
quantile(vec, prob);
6.84375


med

#Usage

template <typename T> double med(std::vector<T> &x)

#Description

Returns the median of a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool), must be ascendly sorted

#Example(s)

std::vector<int> vec = {1, 2, 3, 4};
double out = med(vec);
2.5


cor

#Usage

template <typename T, typename T2> double cor(const std::vector<T> &x, const std::vector<T2> &x2)

#Description

Returns the correlation between two variables / two stl vectors (int, float, double, bool)

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)
x2 is an stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec1 = {1, 2, 3, 4, 5, 6};
std::vector<int> vec2 = {-6, -5, -4, -3, -2, -1};
double out = cor(vec1, vec2);
1


Sd

#Usage

template <typename T> double Sd(std::vector<T> &x)

#Description

Returns the standard deviation of a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 2, 2, 3, 3, 3, 4, 4, 5};
double out = Sd(vec);
1.224745


Uniform distribution

dunif

#Usage

template <typename T> std::vector<double> dunif(std::vector<T> &x, double &min, double &max)

#Description

Returns the probability distribution of the uniform distribution.

#Arguments

NameDefinition
x is a vector containing all the values you want the probability from
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> out = dunif(vec, min, max);
print_nvec(out);
:0: 0 0.0833333 0.0833333 0.0833333 0 0


punif

#Usage

template <typename T> std::vector<double> punif(std::vector<T> &x, double &min, double &max, double step = 0.01)

#Description

Returns the cumulative probablity distribution of the uniform distribution.

#Arguments

NameDefinition
x is a vector containing the values you want the cumulative probability from, must be ascendly sorted
min is the minimum of the probability distribution
max is the maximum of the probability distribution
step the lower it is, the more accurate the result gets

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> out = punif(vec, min, max);
print_nvec(out);
:0: 0 0.000833333 0.459167 0.834167 1 1


qunif

#Usage

std::vector<double> qunif(std::vector<double> &x, double &min, double &max)

#Description

Returns the quantile of the uniform distribution.

#Arguments

NameDefinition
x is the probability vector
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution

#Example(s)

double min = -2;
double max = 10;
std::vector<double> vec = {-7, -2, 3.5, 8, 12, 56};
std::vector<double> vec2 = {0.2, 0.4, 0.5, 0.6, 0.75};
std::vector<double> out = qunif(vec2, min, max);
print_nvec(out);
:0: 3.6 5.2 6 6.8 8


runif

#Usage

std::vector<double> unif(unsigned int &n, double &min, double &max, double noise = 0.1, int seed = -1)

#Description

Returns a stl double vector containing pseudo-random uniform distribution between a min and max.

#Arguments

NameDefinition
n is the number of elements of the output stl vector
min is the minimum of the uniform distribution
max is the maximum of the uniform distribution
noise is the noise in the returnde uniform distribution
seed is an int, controlling the output values, defaults to -1, so by default the function returns pseudo-random uniform distribution. If you want to manually control the output, enter a positive int for this parameter.

#Example(s)

unsigned int n = 1500;
double min = 1;
double max = 55;
std::vector<double> out = unif(n, min, max);
print_nvec(out);
:0: 1 1.03701 1.07557 1.10951 1.14757 1.18151 1.21957 1.25351 1.29157 1.32551 1.36357 1.39751 1.43557 1.46951 1.50757 1.54151 1.57957 1.61351 1.65157 1.68551 1.72357 1.75751 1.79557 1.82951
...
:1475: 54.1015 54.1396 54.1735 54.2116 54.2455 54.2836 54.3175 54.3556 54.3895 54.4276 54.4615 54.4996 54.5335 54.5716 54.6055 54.6436 54.6775 54.7156 54.7495 54.7876 54.8215 54.8596 54.8935 54.9316
:1500: 55


Normal distribution

rnorm

#Usage

std::vector<double> rnorm(unsigned int &n, double &mean, double &sd, double noise = 0.05, int seed = -1)

#Description

Returns a pseudo-random normal distribution as a double stl vector. Note, if you can it is preferable to choose the smallest standard deviation possible to increase speed. Example: N(14, 10) -> N(1.4, 1).

#Arguments

NameDefinition
n is the number of elements in the output stl vector
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
noise is the noise, defaults to 0.05
seed is an int that dictates the result, defaults to -1, so by default the output is pseudo-random

#Example(s)

unsigned int n = 10000;
double sd = 250;
double mean = 155;
std::vector<double> out;
double result;
out = rnorm(n, mean, sd);
Sd(out);
250.6228
Mean(out);
154.9945



rnorm2

#Usage

std::vector<double> rnorm2(unsigned int &n, double &mean, double &sd, double noise = 0.05, int seed = -1)

#Description

Same as norm(), but faster and less accurate.

#Arguments

NameDefinition
n is the number of elements in the output stl vector
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
noise is the noise, defaults to 0.05
seed is an int that dictates the result, defaults to -1, so by default the output is pseudo-random

#Example(s)

unsigned int n = 10000;
double sd = 50;
double mean = 155;
std::vector<double> out;
double result;
out = rnorm2(n, mean, sd);
Sd(out);
42.06729
Mean(out);
155.0009



qnorm1

#Usage

template <typename T, typename T2> double qnorm1(T &mean, T2 &sd, double &val, double offset_prob = 0.05)

#Description

Returns the quantile value for a given theoretical normal distribution. There is an offset probability input that tells the most offset probability the function has to takein count in order to return the quantile value.

#Arguments

NameDefinition
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
val is the quantile percentage (between 0 and 1)
offset_prob is the probability from which is no longer not taken in count by the function in order to return a coherent value

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {0.33, 0.40, 0.45, 0.5, 0.55};
std::vector<double> out = qnorm1(vec, mean, sd);
print_nvec(out);
:0: 10.8688 11.3346 11.6673 12 12.3327


qnorm2

#Usage

template <typename T, typename T2> double qnorm1(T &mean, T2 &sd, double &val, double offset_prob = 0.05)

#Description

Returns the quantile value for a given theoretical normal distribution. This algorithm may be more precise than qnorm1 but takes slightly longer times to compute.

#Arguments

NameDefinition
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
x are the quantile percentage (between 0 and 1), must be ascendly sorted
step is the accuracy, the lower it is, the more precise it gets

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {0.33, 0.40, 0.45, 0.5, 0.55};
std::vector<double> out = qnorm2(vec, mean, sd);
print_nvec(out);
:0: 9.92 10.85 11.48 12.11 12.74


dnorm

#Usage

template <typename T> std::vector<double> dnorm(std::vector<T> &x, double &mean, double &sd, double step = 1)

#Description

Returns the density function of a given normal distribution as an stl double vector.

#Arguments

NameDefinition
x is an stl vector of values you want the probability from
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
step the step of each element you want the probability from, see examples. Defaults to 1, so it ouputs the same result as the dnorm() function in R by default.

#Example(s)

double mean = 12;
double sd = 2;
std::vector<double> vec = {1, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14};
std::vector<double> vec2 = {9, 10, 11, 12, 13, 14};
std::vector<double> out = dnorm(vec, mean, sd, 0.5);
print_nvec(out);
:0: 0.0323794 0.0456623 0.0604927 0.0752844 0.0880163 0.096667 0.0997356 0.096667 0.0880163 0.0752844 0.0604927
out = dnorm(vec2, mean, sd, 1);
:0: 0.0647588 0.120985 0.176033 0.199471 0.176033 0.120985


pnorm

#Usage

template <typename T> std::vector<double> pnorm(std::vector<T> &x, double &mean, double &sd, double step = 0.01)

#Description

Returns the cumulative distribution function of a given normal distribution.

#Arguments

NameDefinition
x is an stl vector containing all the elements you want the function distribution to be calculated with, must be ascendly sorted
mean is the mean of the normal distribution
sd is the standard deviation of the normal distribution
step the lower it is the higher the accuracy is

#Example(s)

double mean = 15;
double sd = 2;
std::vector<double> vec = {13, 13.5, 14, 14.5, 15, 15.5, 16, 18};
std::vector<double> out = pnorm(vec, mean, sd);
print_nvec(out);
:0: 0.00120985 0.0693298 0.151367 0.24421 0.342947 0.441622 0.534291 0.774818


Binomial

dbinom

#Usage

std::vector<double> dbinom(std::vector<unsigned int> &k, unsigned int &n, double &p)

#Description

Returns the probability function of a binomial distribution as an stl double vector.

#Arguments

NameDefinition
x is an stl unsigned int vector containing all the x's
n is the size of the set
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {39, 40, 41, 42, 43, 44, 45, 46, 47, 48};
unsigned int n = 100;
double p = 0.45;
std::vector<double> out = dbinom(vec, n, p);
print_nvec(out);
:0: 0.03875 0.0483929 0.0580423 0.066859 0.0739653 0.0785867 0.0801904 0.0785867 0.0739653 0.066859 0.0580423 0.0483929


pbinom

#Usage

std::vector<double> pbinom(std::vector<unsigned int> &k, unsigned int &n, double &p)

#Description

Returns the cumulative distribution function of range P(X = {x1,x2...}) as an stl double vector.

#Arguments

NameDefinition
k is an stl unsigned int vector containing all the k's, must be ascendly sorted
n is the size of the set
p is the probability of success

#Example(s)

unsigned int n = 10;
double p = 0.5;
std::vector<unsigned int> vec = {3, 5, 7};
std::vector<double> out = pbinom(vec, n, p);
print_nvec(out);
:0: 0.117188 0.568359 0.890625


qbinom

#Usage

std::vector<unsigned int> qbinom(std::vector<double> &pvec, unsigned int &n, double &p)

#Description

Returns the quantiles of a binomial distribution.

#Arguments

NameDefinition
pvec is an stl vector of probabilities, must be ascendly sorted
n is size of the set, as an unsigned int
p is the probability of success, as a double

#Example(s)

std::vector<double> vec3 = {0.3, 0.4, 0.5, 0.6, 0.7};
unsigned int n = 100;
double prob = 0.55;
std::vector<unsigned int> out = qbinom(vec3, n, prob);
print_nvec(out);
:0: 47 48 50 51 52 54


rbinom

#Usage

std::vector<unsigned int> rbinom(unsigned int &n, unsigned int size, double p)

#Description

Returns pseudo-random values of binomial distribution.

#Arguments

NameDefinition
n is the number of observations
size is the size of the individuals
p is the probability of success

#Example(s)

unsigned int size = 100;
double p = 0.5;
unsigned int n = 60;
std::vector<unsigned int> out = rbinom(n, size, p);
print_nvec(out);
:25: 50 50 50 50 50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
:50: 50 50 50 50 50 50 50 50 50 50
Mean(out);
49
Sd(out);
5.90141
std::sqrt(size * p * (1 - p));
5


Poisson

dpois

#Usage

std::vector<double> dpois(std::vector<int> &k, int &lambda)

#Description

Returns the poisson probability distribution.

#Arguments

NameDefinition
k is the vector containing the k values
lambda is the mean

#Example(s)

int lambda = 500;
std::vector<int> vec2 = {492, 500, 520};
std::vector<double> out = dpois(vec2, lambda);
print_nvec(out);
:0: 0.0167352 0.0178412 0.0119593


ppois

#Usage

std::vector<double> ppois(std::vector<int> &k, int &lambda)

#Description

Returns the poisson cumulative probability distribution.

#Arguments

NameDefinition
k is the vector containing the k values
lambda is the mean

#Example(s)

int lambda = 500;
std::vector<int> vec2 = {492, 500, 520};
std::vector<double> out = ppois(vec2, lambda);
print_nvec(out);
:0: 0.0167352 0.157008 0.468481


qpois

#Usage

std::vector<unsigned int> qpois(std::vector<double> &p, int &lambda)

#Description

Returns the quantile of the poisson distribution

#Arguments

NameDefinition
p is the vector of probabilities
lambda is the mean

#Example(s)

std::vector<double> vec = {0.22, 0.5, 0.7};
int lambda = 500;
std::vector<unsigned int> out = qpois(vec, lambda);
:0: 483 500 512


rpois

#Usage

std::vector<unsigned int> rpois(unsigned int &n, unsigned int lambda)

#Description

#Arguments

NameDefinition
n is the number of observations
lambda is the mean

#Example(s)

unsigned int lambda = 100;
unsigned int n = 60;
std::vector<unsigned int> out = rpois(n, lambda);
print_nvec(out);
:0: 114 86 86 86 115 115 85
85 85 116 116 84 84 119 119
83 83 120 120 79 79 133 133 67
:25: 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
:50: 101 101 101 101 101 101 101 101
101 101
Mean(out);
99
Sd(out);
13.0799
std::sqrt(lambda);
10


Exponential distribution

dexp

#Usage

std::vector<double> dexp(std::vector<double> &x, double &rate)

#Description

Returns the probability distribution of the exponential distribution

#Arguments

NameDefinition
x is the vector containing the values you want the probability from
rate is the rate value for the exponential distribution, given by 1 / mean

#Example(s)

double rate = 0.2;
std::vector<double> vec = {1, 2, 3, 4, 5, 6};
std::vector<double> out = dexp(vec, rate);
print_nvec(out);
:0: 0.163746 0.134064 0.109762 0.0898658 0.0735759 0.0602388


pexp

#Usage

std::vector<double> pexp(std::vector<double> &x, double &rate, double step = 0.01)

#Description

Returns the cumulative probability distribution for the exponential distribution.

#Arguments

NameDefinition
x is the vector of the values you want the cumulative probability distribution from, must be ascendly sorted
rate is the rate for the exponential distribution
step the lower it is the more accurate the result will be

#Example(s)

:0: 0.00163746 0.148559 0.271287 0.37067 0.452038 0.518657


qexp

#Usage

std::vector<double> qexp(std::vector<double> &p, double &rate)

#Description

Returns the quantile of the exponential probability distribution

#Arguments

NameDefinition
p is the vector of probabilities
rate is the rate of the exponential distribution

#Example(s)

double rate = 0.2;
std::vector<double> vec2 = {0.1, 0.2, 0.3, 0.4, 0.5, 0.75};
std::vector<double> out = qexp(vec2, rate);
print_nvec(out);
:0: 0.526803 1.11572 1.78337 2.55413 3.46574 6.93147


rexp

#Usage

std::vector<double> rexp(unsigned int &n, double rate)

#Description

Returns a pseudo-random distribution of the exponential distribution

#Arguments

NameDefinition
n is the number of observations
rate is the rate of the exponential distribution

#Example(s)

double rate = 0.2;
unsigned int n = 100;
std::vector<double> out = rexp(n, rate);
print_nvec(out);
:0: 13.2 13.2 2.79385 2.79385 2.79385
13.6804 13.6804 4.10504 4.10504 15.9378
15.9378 5.60406 5.60406 21.5331 21.5331
10.4864 10.4864 5.20657 5.20657 5.20657
5.20657 5.20657 5.20657 5.20657
:25: 5.20657 5.20657 5.20657 5.20657 5.20657
4.80913 4.80913 4.80913 4.80913 4.80913 4.80913
4.80913 4.80913 4.80913 4.80913 4.80913 4.80913
4.80913 4.80913 5.3978 5.3978 5.3978 5.3978 5.3978
:50: 5.3978 5.3978 5.3978 5.3978 5.3978 4.57492
4.57492 4.57492 4.57492 4.57492 4.57492 4.57492
4.57492 4.57492 4.57492 4.57492 4.57492 5.58841
5.63733 5.63733 5.63733 5.63733 5.63733 5.63733
:75: 5.63733 5.63733 4.35393 4.35393 4.35393 4.35393
4.35393 4.35393 4.35393 4.35393 4.35393 4.35393
4.35393 5.82063 5.82063 5.82063 5.82063 5.82063
5.82063 5.82063 5.82063 4.19025 4.19025 4.19025
:100: 4.19025
Mean(out);
5.94307
Sd(out);
4.29426


Cauchy

dcauchy

#Usage

std::vector<double> dcauchy(std::vector<double> &x, double location = 0, double scale = 1)

#Description

Returns the probability distribution of the cauchy distribution.

#Arguments

NameDefinition
x is the vector of values you want the probability from
location is the x coordinate
scale is the t coordinate

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {-2, -1, 0, 1, 2, 4};
std::vector<double> out = dcauchy(vec, location, scale);
print_nvec(out);
:0: 0.063662 0.159155 0.31831 0.159155 0.063662 0.0187241


pcauchy

#Usage

std::vector<double> pcauchy(std::vector<double> &x, double location = 0, double scale = 1)

#Description

Returns the cumulative probability distribution of the cauchy distribution (starts from first value).

#Arguments

NameDefinition
x is the vector of values you want the cumulative probability from
location is the x coordinate
scale is the t coordinate
step the lowest it is the more accurate the result gets

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {-2, -1, 0, 1, 2, 4};
std::vector<double> out = pcauchy(vec, location, scale);
print_nvec(out);
:0: 0.000634083 0.10305 0.35305 0.60305 0.705467 0.775071


qcauchy

#Usage

std::vector<double> qcauchy(std::vector<double> &p, double location = 0, double scale = 1)

#Description

Returns the quantile of the cauchy probability distribution

#Arguments

NameDefinition
p is the vector containing the probabilities
location is the x coordiante
scale is the y coordinate

#Example(s)

double location = 0;
double scale = 1;
std::vector<double> vec = {0.1, 0.25, 0.4, 0.5, 0.63, 0.78};
std::vector<double> out = qcauchy(vec, location, scale);
print_nvec(out);
:0: -3.07768 -1 -0.32492 0 0.432739 1.20879


rcauchy

#Usage

std::vector<double> rcauchy(unsigned int n, double x = 0, double y = 1)

#Description

Returns a pseudo-random generation of numbers following a cauchy distribution.

#Arguments

NameDefinition
n is the number of numbers to generate
x is the x coordinate
y is the y coordinate

#Example(s)

int ref_min = -2;
double location = -4;
double scale = 8;
unsigned int n = 100;
std::vector<double> out = rcauchy(n, location, scale);
std::vector<bool> out2 = supcmp(out, ref_min);
sum(out2);
42


Gamma distribution

dgamma

#Usage

std::vector<double> dgamma(std::vector<double> &x, double &shape, double &rate)

#Description

Returns the gamma density probability distribution. Uses a normal law of mean = 1/rate * shape and sd = 1/rate * sqrt(shape) to approximate for shape value greater than 171

#Arguments

NameDefinition
x is the input vector composed of the x values
shape is the alpha value
rate is the rate value (lambda or 1/theta)

#Example(s)

std::vector<double> vec = {6444, 6666, 6888};
double shape = 3333;
double rate = 0.5;
std::vector<double> out = dgamma(vec, shape, rate);
print_nvec(out);
:0: 0.000544178 0.00345511 0.000544178


pgamma

#Usage

std::vector<double> pgamma(std::vector<double> &x, double &shape, double &rate, double step)

#Description

Returns the gamma cmulative probability distribution between an interval (first x value to last x value)

#Arguments

NameDefinition
x is the input x values, must be ascendly sorted
shape is the alpha value
rate is the lambda value, 1/theta
step the lower it is, the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec = {6444, 6555, 6666, 6888};
double shape = 3333;
double rate = 0.5;
double step = 0.1;
std::vector<double> out = pgamma(vec, shape, rate, step);
print_nvec(out);
:0: 5.44178e-05 0.141121 0.473211 0.946151


qgamma

#Usage

std::vector<double> qgamma(std::vector<double> &x, double &shape, double &rate, double step)

#Description

Returns the quantile value of the gamma probability distribution

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
shape is the alpha value
rate is the lambda value (1 / theta)
step the lower it is, the more accurate the result will be at a cmputational cost

#Example(s)

std::vector<double> vec = {0.26, 0.45, 0.5, 0.6, 0.88};
double shape = 3333;
double rate = 0.5;
double step = 0.1;
std::vector<double> out = qgamma(vec, shape, rate, step);
print_nvec(out);
:0: 6591.86 6651.56 6666.06 6695.36 6801.76


rgamma

#Usage

std::vector<double> rgamma(unsigned int &n, double &shape, double &rate, double step)

#Description

Generates pseudo-random variables that follow a gamma probability distribution

#Arguments

NameDefinition
n is the number of observations, more than 1
shape is the alpha value
rate is the lambda (1 / theta)
step the lower it is, the more the result will be accurate, at a computational cost

#Example(s)

unsigned int n = 100;
double shape = 3333;
double rate = 0.25;
double step = 0.01;
std::vector out = rgamma(n, shape, rate, step);
print_nvec(out);
:0: 12794.8 12857.7 12897.7 12927.7 12952.2 12973 12991.2
13007.5 13022.4 13036.1 13048.8 13060.7 13071.9 13082.5 13092.7
13102.4 13111.7 13120.6 13129.3 13137.7 13145.8 13153.7 13161.4
13168.9
:25: 13183.4 13190.5 13197.4 13204.2 13210.9 13217.5 13224 13230.4
13236.8 13243 13249.2 13255.4 13261.5 13267.5 13273.5 13279.5
13285.4 13291.3 13297.1 13303 13308.8 13314.6 13320.4 13326.2
:50: 13337.8 13343.6 13349.4 13355.2 13361 13366.9 13372.7 13378.6
13384.6 13390.5 13396.5 13402.6 13408.6 13414.8 13421 13427.3
13433.6 13440 13446.5 13453.1 13459.8 13466.6 13473.5 13480.6
:75: 13495.1 13502.6 13510.3 13518.2 13526.4 13534.7 13543.4
13552.4 13561.7 13571.3 13581.5 13592.1 13603.3 13615.3 13628
13641.6 13656.5 13672.8 13691 13711.9 13736.3 13766.3 13806.3
13869.2
:100: 13276.2


Beta distribution

dbeta

#Usage

std::vector<double> dbeta(std::vector<double> &x, double &a, double &b, double normalisation_step = 1)

#Description

Returns the beta density probability distribution

#Arguments

NameDefinition
x is the vector of the probabilities
a is alpha, number of successes
b is beta, the number of failures
normalisation_step is the probability unit of the x vector

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1};
double step = 0.005;
std::vector<double> out = dbeta(vec, a, b, step);
print_nvec(out);
:0: 0 1.24746e-15 1.1697e-06 0.00428754 0.0410157
0.00547615 1.23346e-05 1.87358e-10 1.06384e-18 0


pbeta

#Usage

std::vector<double> pbeta(std::vector<double> &x, double &a, double &b, double step = 0.01)

#Description

Returns the beta cumulative probability distribution, of an interval of the first input value to the last input value (from the input vector of probabilities)

#Arguments

NameDefinition
x is the vector of the probabilities, must be ascendly sorted
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be at a computational cost

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1};
double step = 0.005;
std::vector<double> out = pbeta(vec, a, b, step);
print_nvec(out);
:0: 0 2.65054e-16 1.23119e-06 0.0129867 0.468685 0.974149
0.999966 1 1 1


qbeta

#Usage

std::vector<double> qbeta(std::vector<double> &x, double &a, double &b, double step = 0.01)

#Description

Returns the quantile of given probabilities according to the beta probability distribution

#Arguments

NameDefinition
x is the vector of probabilities you want the probabilities from
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be at a computational cost

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0.3, 0.55, 0.9, 0.99};
double step = 0.005;
std::vector<double> out = qbeta(vec2, a, b, step);
print_nvec(out);


rbeta

#Usage

std::vector<double> rbeta(unsigned int &n, double &a, double &b, double step = 0.01)

#Description

Returns pseudo-ranomly value that follow a beta probability distribution

#Arguments

NameDefinition
n is the number of observations, values to generate
a is alpha, the number of successes
b is beta, the number of failures
step the lower this value is, the more accurate the result will be. Have to be lowered if the output starts having clone values, it can happen when n is very high

#Example(s)

double a = 40;
double b = 60;
std::vector<double> vec = {0.3, 0.55, 0.9, 0.99};
double step = 0.005;
unsigned int n = 100;
std::vector<double> out = rbeta(n, a, b, step);
print_nvec(out);
:0: 0.29716 0.31027 0.31901 0.32338 0.32775 0.33212
0.33649 0.34086 0.34086 0.34523 0.34523 0.3496 0.35397
0.35397 0.35397 0.35834 0.35834 0.36271 0.36271 0.36708
0.36708 0.36708 0.37145 0.37145
:25: 0.37582 0.37582 0.37582 0.38019 0.38019 0.38019
0.38456 0.38456 0.38456 0.38893 0.38893 0.38893 0.38893
0.3933 0.3933 0.3933 0.39767 0.39767 0.39767 0.39767
0.40204 0.40204 0.40204 0.40641
:50: 0.40641 0.40641 0.41078 0.41078 0.41078 0.41515
0.41515 0.41515 0.41515 0.41952 0.41952 0.41952 0.42389
0.42389 0.42389 0.42389 0.42826 0.42826 0.42826 0.43263
0.43263 0.43263 0.437 0.437
:75: 0.44137 0.44137 0.44574 0.44574 0.44574 0.45011 0.45011
0.45448 0.45448 0.45448 0.45885 0.46322 0.46322 0.46759
0.46759 0.47196 0.47633 0.47633 0.4807 0.48507 0.49381 0.49818
0.50692 0.52003
:100: 0.3933


Chi Square distribution

dchisq

#Usage

std::vector<double> dchisq(std::vector<double> &x, double °f)

#Description

Returns the chi square density probability function

#Arguments

NameDefinition
x is the input vector of quantiles
degf is the degree of freedom

#Example(s)

std::vector<double> vec = {180, 200, 210, 250, 290, 310};
double degf = 240;
std::vector<double> out = dchisq(vec, degf);
print_nvec(out);
:0: 0.000263702 0.00333664 0.00747074 0.0157848
0.00152353 0.000193457


pchisq

#Usage

std::vector<double> pchisq(std::vector<double> &x, double °f, double step = 0.05)

#Description

Returns the chi square cumulative probability function

#Arguments

NameDefinition
x is the input vector of quantiles, must be ascendly sorted
degf is the degree of freedom
step the lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec = {180, 200, 210, 250, 290, 310};
double degf = 240;
std::vector<double> out = pchisq(vec, degf);
print_nvec(out);
:0: 1.31851e-05 0.0266942 0.0790938 0.682744
0.983524 0.996995


qchisq

#Usage

std::vector<double> qchisq(std::vector<double> &x, double °f, double step = 0.05)

#Description

Returns the probability of the input quantile values

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
degf is the degree of freedom
step th lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<double> vec2 = {0.2, 0.45, 0.56, 0.69, 0.88};
double degf = 240;
std::vector<double> out = qchisq(vec2, degf);
print_nvec(out);
:0: 221.45 236.65 242.7 250.4 266


rchisq

#Usage

std::vector<double> rchisq(unsigned int &n, double °f, double step = 0.05)

#Description

Returns pseudo-random values that follow a chi square probability distribution

#Arguments

NameDefinition
n is the number of observations
degf is the degree of freedom
step the lower it is the more accurate the result is. Have to be lowered if the output begins to have clone values. It can happen if n is very high

#Example(s)

unsigned int n = 100;
double degf = 240;
std::vector out = rchisq(n, degf);
print_nvec(out);
:0: 192.049 197.248 200.571 203.09 205.181 206.95
208.558 209.951 211.238 212.417 213.542 214.614 215.579
216.544 217.402 218.313 219.117 219.921 220.671 221.422
222.172 222.869 223.566 224.262
:25: 225.602 226.246 226.889 227.478 228.122 228.711
229.301 229.89 230.48 231.07 231.606 232.195 232.785
233.321 233.91 234.446 234.982 235.572 236.108 236.644
237.18 237.77 238.306 238.842
:50: 239.914 240.503 241.039 241.575 242.165 242.701
243.29 243.826 244.416 244.952 245.542 246.131 246.721
247.31 247.9 248.543 249.133 249.776 250.419 251.062 251.706
252.349 253.046 253.742
:75: 255.19 255.94 256.69 257.441 258.245 259.102 259.96 260.871
261.782 262.801 263.819 264.891 266.017 267.25 268.536 269.93
271.43 273.146 275.022 277.166 279.738 282.901 287.189 293.942
:100: 223.914


test_chisq_fit

#Usage

bool test_chisq_fit(std::vector<double> theoretical, std::vector<double> observed, double a_value = 0.05, double step = 0.05)

#Description

Performs a chi square goodness of fit test. Returns 1 if the observed values fit the observed values at a given p_value, 0 else

#Arguments

NameDefinition
theoretical is the vector containing all the theoretical data
observed is the vector containing all the observed data
a_value is the significance level
step the lower this value is the more accurate the result wil be at a computational cost

#Example(s)

std::vector theoretical = {20, 20, 30, 40, 60, 30};
std::vector observed = {30, 14, 34, 45, 57, 20};
double a_value = 0.05;
bool out = test_chisq_fit(theoretical, observed, a_value);
0 // the observed data does not fit the theoretical data


test_chisq_independance

#Usage

bool test_chisq_independance(std::vector<std::vector<double>> &matr, double a_value = 0.05, double step = 0.05)

#Description

Performs a chi square independance test. Returns 0 if the variables are independant, 1 else

#Arguments

NameDefinition
matr is the input matrice (observed values)
a_value is the significance level (the greater it is the more likely the 2 variables will be percieved as independant)
step the lower this value is the more accurate the result will be at a computational cost

#Example(s)

std::vector<std::vector<double>> matr = {{8, 16, 11, 10},
{9, 27, 22, 16},
{7, 13, 8, 12},
{9, 13, 12, 7}};
print_matr(matr);
double step = 0.05;
double a_value = 0.05;
bool out = test_chisq_independance(matr, a_value, step);
0 // the variables are independant


Geometric distributions

dgeom

#Usage

std::vector<double> dgeom(std::vector<unsigned int> &x, double &p)

#Description

Returns the geometric density probability distribution

#Arguments

NameDefinition
x is the input vector of quantiles, representing the number of failures before success
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {2, 3, 4, 5};
double p = (double)1 / 6;
std::vector<double> out = dgeom(vec, p);
print_nvec(out);
:0: 0.115741 0.0964506 0.0803755 0.0669796


pgeom

#Usage

std::vector<double> pgeom(std::vector<unsigned int> &x, double &p)

#Description

Returns the geometric cumulative probability distribution (interval between firts value in vector and last, see example)

#Arguments

NameDefinition
x is the input vector of quantiles, representing the number of failures before success, must be ascendly sorted
p is the probability of success

#Example(s)

std::vector<unsigned int> vec = {2, 3, 4, 5};
double p = (double)1 / 6;
std::vector<double> out = pgeom(vec, p);
print_nvec(out);
:0: 0.115741 0.212191 0.292567 0.359546


qgeom

#Usage

std::vector<unsigned int> qgeom(std::vector<double> &x, double &p)

#Description

Returns the quantiles of the input probabilities according to a geometric probability distribution

#Arguments

NameDefinition
x is the input vector of probabilities, must be ascendly sorted
p is the probability of success

#Example(s)

std::vector<double> vec2 = {0.2, 0.3, 0.5, 0.52, 0.6, 0.85};
double p = (double)1 / 6;
std::vector<unsigned int> out = qgeom(vec2, p);
print_nvec(out);
:0: 1 1 3 4 5 10


rgeom

#Usage

std::vector<unsigned int> rgeom(unsigned int &n, double &p)

#Description

Returns pseudo-randomly generated values that follow a geometric distribution

#Arguments

NameDefinition
n is the number of observations
p is the probability of success

#Example(s)

double p = (double)2 / 9;
unsigned int n = 100;
std::vector<unsigned int> out = rgeom(n, p);
print_nvec(out);
:0: 8 13 3 0 4 2 0 4 2 11 4 1 12 3 9
5 2 10 15 7 0 5 7 2
:25: 8 4 3 9 17 2 10 5 2 1 4 8 12 6 1
5 6 9 4 2 0 5 2 1
:50: 8 2 6 1 13 6 0 4 7 1 4 7 1 5 1
4 3 9 4 2 10 5 2 10
:75: 1 12 3 8 17 2 9 4 2 11 6 8 3 6 0
5 7 10 5 2 2 3 1 13
:100: 6


dhyper

#Usage

std::vector<double> dhyper(std::vector<int> &x, unsigned int &n_ones, unsigned int &n_others, int &n_trials)

#Description

Returns the hypergeometric probability distribution

#Arguments

NameDefinition
x is the vector of quantiles
n_ones is the number of desired elements in the set
n_others is the number of undesired elements in the set
n_trials is the number of drawns

#Example(s)

unsigned int n_others = 1300;
unsigned int n_ones = 415;
std::vector x = {150, 190, 400};
int n_trials = 555;
std::vector out = dhyper(x, n_ones, n_others, n_trials);
print_nvec(out);
:0: 0.00807227 1.69452e-11 4.42674e-236


Min - Max

min

#Usage

template <typename T> T min(const std::vector<T> &x)

#Description

Returns the min element from a vector (int, float, double, bool)

For finding the index of the min element refer here

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {4, 1, -7};
int out = min(vec);
-7


max

#Usage

template <typename T> T max(const std::vector<T> &x)

#Description

Returns the max element from a vector (int, float, double, bool)

For finding the index of the min element refer here

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {4, 1, -7};
int out = max(vec);
4


Mixing

Heuristic (slightly slower)

mixout

#Usage

template <typename T> void mixout(std::vector<T> &x)

#Description

Returns a stl vector with its elements at different indexes pseudo-randomly chosen.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
std::vector<int> out = mixout(vec);
print_nvec(out);
:0: 66 10 51 47 46 57 13 6 85 40 28 55 42 91 61 34 63 12 23 19 79 62 35 84
:25: 43 5 54 17 93 90 0 73 9 18 49 71 20 89 70 41 4 56 22 45 2 29 88 31
:50: 65 3 75 25 94 77 52 78 39 87 83 27 1 15 24 44 76 99 58 95 92 68 97 26
:75: 64 74 11 80 81 69 59 38 8 7 50 14 98 36 82 60 72 32 96 33 37 30 53 67
:100: 48


mixin

#Usage

template <typename T> void mixin(std::vector<T> &x)

#Description

Transforms a stl vector with its elements at different indexes pseudo-randomly chosen.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
mixin(vec);
print_nvec(vec);
:0: 66 10 51 47 46 57 13 6 85 40 28 55 42 91 61 34 63 12 23 19 79 62 35 84
:25: 43 5 54 17 93 90 0 73 9 18 49 71 20 89 70 41 4 56 22 45 2 29 88 31
:50: 65 3 75 25 94 77 52 78 39 87 83 27 1 15 24 44 76 99 58 95 92 68 97 26
:75: 64 74 11 80 81 69 59 38 8 7 50 14 98 36 82 60 72 32 96 33 37 30 53 67
:100: 48


Deterministic (slightly faster)

mixoutd

#Usage

template <typename T> std::vector<T> mixoutd(std::vector<T> x)

#Description

Returns a stl vector with its elements at different indexes. The function is determinitic based on the size of the input stl vector.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
std::vector<int> out = mixoutd(vec);
print_nvec(out);
:0: 93 65 90 45 1 41 51 79 28 13 18 84 68 37 77 22 15 29 44 9 6 47 36 57
:25: 14 24 26 46 56 96 33 61 54 59 5 73 34 76 75 71 11 78 92 31 48 50 55 49
:50: 52 17 89 21 0 81 64 82 39 67 53 40 63 66 83 97 99 42 2 86 85 80 60 72
:75: 20 87 27 4 35 19 10 88 43 98 38 8 30 69 58 23 16 95 32 94 91 70 74 62
:100: 25


mixind

#Usage

template <typename T> std::vector<T> mixind(std::vector<T> &x)

#Description

Transforms a stl vector with its elements at different indexes. The function is determinitic based on the size of the input stl vector.

#Arguments

NameDefinition
x is an stl vector of any type

#Example(s)

std::vector<int> vec;
for (int i = 0; i < 100; ++i) {
vec.push_back(i);
};
mixind(vec);
print_nvec(vec);
:0: 93 65 90 45 1 41 51 79 28 13 18 84 68 37 77 22 15 29 44 9 6 47 36 57
:25: 14 24 26 46 56 96 33 61 54 59 5 73 34 76 75 71 11 78 92 31 48 50 55 49
:50: 52 17 89 21 0 81 64 82 39 67 53 40 63 66 83 97 99 42 2 86 85 80 60 72
:75: 20 87 27 4 35 19 10 88 43 98 38 8 30 69 58 23 16 95 32 94 91 70 74 62
:100: 25


Print

print_nvec

#Usage

template <typename T> void print_nvec(const std::vector<T> &x, int untl = -1)

#Description

Print a stl vector (int, float, double, bool)

#Arguments

NameDefinition
x stl vector (int, float, double, bool)
untl is an int idicating how many elements must be printed, defaults to -1, so by default all elements will be printed

#Example(s)

std::vector<int> vec = {12, 2, 4534, 7, -78, 12122};
for (int i = 0; i < 20; ++i) { vec.push_back(7); }
print_nvec(vec);
:0: 12 2 4534 7 -78 12122 23323 12 6 2 8 45 7 7 7 7 7 7 7 7 7 7 7 7
:25: 7 7 7 7 7 7 7


print_svec

#Usage

template <typename T> void print_nvec(const std::vector<T> &x, int untl = -1)

#Description

Print a stl vector (int, float, double, bool)

#Arguments

NameDefinition
x stl vector (int, float, double, bool)
untl is an int idicating how many elements must be printed, defaults to -1, so by default all elements will be printed

#Example(s)

std::vector<std::string> vec = {"peugeot", "wolkswagen", "honda", "renault", "stellantis"};
for (int i = 0; i < 20; ++i) { vec.push_back("yesss"); }
print_svec(vec);
:0: peugeot wolkswagen honda renault stellantis yesss yesss yesss yesss yesss yesss yesss yesss yesss yesss yesss yesss
:18: yesss yesss yesss yesss yesss yesss yesss


Parts

getpart

#Usage

template <typename T> std::vector<T> getpart(std::vector<T> &x, std::string prt)

#Description

Retursn part of stl vector with R like synthax.

#Arguments

NameDefinition
x is an stl vector
prt is a stdstring that describe the parts of the stl vector to get (R like synthax)

#Example(s)

std::vector<int> vec;
std::vector<int> vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vec = getpart(vec2, "1,3,5:9,0:9");
print_nvec(vec);
:0: 2 4 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10


Add parts to existing stl vector

partout

#Usage

template <typename T> std::vector<T> partout(std::vector<T> &inpt, std::vector<T> &x, std::string prt)

#Description

Returns the input stl vector with elements added from another stl vector of the same type. The elements added are described with a std::string following the R synthax.

#Arguments

NameDefinition
inpt is the stl vector to which elements from the second stl vector will be added
x is the stle vecotr from which elements will be added
prt is a stdstring that describes the elements from the second stl vector to be aded to the first stl vector

#Example(s)

std::vector<int> out;
std::vector<int> vec = {52, 88};
std::vector<int> vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
out = partout(vec, vec2, "1,3,5:9,0:9");
print_nvec(out);
0: 52 88 2 4 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10


partin

#Usage

template <typename T> std::vector<T> partin(std::vector<T> &inpt, std::vector<T> &x, std::string prt)

#Description

Transforms the input stl vector adding elements from another stl vector of the same type. The elements added are described with a std::string following the R synthax.

#Arguments

NameDefinition
inpt is the stl vector to which elements from the second stl vector will be added
x is the stle vecotr from which elements will be added
prt is a stdstring that describes the elements from the second stl vector to be aded to the first stl vector

#Example(s)

std::vector<int> vec = {52, 88};
std::vector<int> vec2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
partin(vec, vec2, "1,3,5:9,0:9");
print_nvec(vec);
0: 52 88 2 4 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10


Absolute values

abs_vin

#Usage

template <typename T> void abs_vin(std::vector<T> &x)

#Description

Converts the elements of a vector to absolute values.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, -5, -7, 3};
abs_vin(vec);
{1, 5, 7, 3}


abs_vout

#Usage

template <typename T> void abs_vout(std::vector<T> &x)

#Description

Returns the input vector with all of its elements converted to absolute values.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, -5, -7, 3};
std::vector<unsigned int> out = abs_vout(vec);
{1, 5, 7, 3}


abs_voutb

#Usage

template <typename T> std::vector<T> abs_voutb(const std::vector<T> &x)

#Description

Returns the input vector with all of its elements converted to absolute values.

uses another algorithm than abs_vout, with indices instead of iterators.

#Arguments

NameDefinition
x is a stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {-45, 23, 21, -6, 45};
std::vector<unsigned int> out = abs_voutb(vec);
{45, 23, 21, 6, 45}


Match

matchl

#Usage

template <typename T, typename T2> bool matchl(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns 1 if the pattern is found in the stl vector, 0 if not. (returns bool)

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
bool out = matchl(vec, ptrn);
1


match

#Usage

template <typename T, typename T2> unsigned int match(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns the index of the pattern in the vector, -1 if not found.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
unsigned int out = matchl(vec, ptrn);
2


match_max

#Usage

template <typename T> unsigned int match_max(const std::vector<T> &x)

#Description

Returns the index of the maximum value in a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {3, 1, -7, 23, 21};
unsigned int out = match_max(vec);
3


match_min

#Usage

template <typename T> unsigned int match_min(const std::vector<T> &x)

#Description

Returns the index of the minimum value in a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is an stl vector (int, float, double)

#Example(s)

std::vector<int> vec = {3, 1, -7, 23, 21};
unsigned int out = match_min(vec);
2


Grep

grep

#Usage

template <typename T, typename T2> std::vector<unsigned int> grep(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns the indices of a pattern inside a stl vector.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
std::vector<unsigned int> out = grep(vec, ptrn);
{3 4}


grepl

#Usage

template <typename T, typename T2> std::vector<bool> grepl(const std::vector<T> &source, const T2 &ptrn)

#Description

Returns a boolean vector where O corresponds to a non match with the pattern andthe corresponding elements of the stl vector. 1 represents a match.

#Arguments

NameDefinition
source is an stl vector
ptrn is the pattern

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe", "euuh", "maybe"};
std::string ptrn = "maybe";
std::vector<bool> out = grep(vec, ptrn);
{0 0 1 0 1}


RegEx

regex_findr

#Usage

std::map<std::vector<unsigned int>, std::map<bool, std::string>> regex_findr(std::string &searched, std::string &x)

#Description

A minimalist RegEx flavor.

- or context which is the set of elements that are inside [], evaluates the expression from left to right

- range elements matches every elements that are between x-y acording to the ASCII table

- repetition is the number of times a set of elements have to be matched, this is declared inside {n} after the set of elements

- greedyness allows to match a given number of times a set of elements or more, this is declared by {+n} after the set of elements

- \\ is used to escape special characters, apart when it is in a range context, so \\-x or x-\\ are valid

#Arguments

NameDefinition
searched is the RegEx expression
x is the input stdstring

#Example(s)


std::string inpt_str = "uouuupeieeeppppiimi";
std::string searched = "[u{1}p{2}]{2}ii[a-em]";
std::map<std::vector<unsigned int>, std::map<bool, std::string>> outmp = regex_findr(searched, inpt_str);
std::map<std::vector<unsigned int>, std::map<bool, std::string>>::iterator it = outmp.begin();
std::vector<unsigned int> vec1 = it->first;
std::map<bool, std::string>::iterator it2b = it->second.begin();
std::cout << vec1[0] << "\n";
std::cout << vec1[1] << "\n";
std::cout << it2b->first << "\n";
std::cout << it2b->second << "\n";

11
17
1
ppppiim

std::string inpt_str = "uouuupeieeeppppiimi";
std::string searched = "[u{1}p{2}]{+1}ii[a-em]";
std::map<std::vector<unsigned int>, std::map<bool, std::string>> outmp = regex_findr(searched, inpt_str);
std::map<std::vector<unsigned int>, std::map<bool, std::string>>::iterator it = outmp.begin();
std::vector<unsigned int> vec1 = it->first;
std::map<bool, std::string>::iterator it2b = it->second.begin();
std::cout << vec1[0] << "\n";
std::cout << vec1[1] << "\n";
std::cout << it2b->first << "\n";
std::cout << it2b->second << "\n";

11
17
1
ppppiim

std::string inpt_str = "uouuupeieeeppppiimi";
std::string searched = "e{+1}p{2}";
std::map<std::vector<unsigned int>, std::map<bool, std::string>> outmp = regex_findr(searched, inpt_str);
std::map<std::vector<unsigned int>, std::map<bool, std::string>>::iterator it = outmp.begin();
std::vector<unsigned int> vec1 = it->first;
std::map<bool, std::string>::iterator it2b = it->second.begin();
std::cout << vec1[0] << "\n";
std::cout << vec1[1] << "\n";
std::cout << it2b->first << "\n";
std::cout << it2b->second << "\n";

8
12
1
eeepp

std::string inpt_str = "uouuupeieeeppppiimi";
std::string searched = "[a-ia-z]{+1}";
std::map<std::vector<unsigned int>, std::map<bool, std::string>> outmp = regex_findr(searched, inpt_str);
std::map<std::vector<unsigned int>, std::map<bool, std::string>>::iterator it = outmp.begin();
std::vector<unsigned int> vec1 = it->first;
std::map<bool, std::string>::iterator it2b = it->second.begin();
std::cout << vec1[0] << "\n";
std::cout << vec1[1] << "\n";
std::cout << it2b->first << "\n";
std::cout << it2b->second << "\n";

6
10
1
eieee


Unique

unique

#Usage

template <typename T> std::vector<T> unique(const std::vector<T> &x)

#Description

Returns a stl vector with unique elements from an input stl vector.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<int> vec = {1, 2, 3, 4, 4, 5, 6, 6};
std::vector<int> out = unique(vec);
{1, 2, 3, 4, 5, 6}


Reverse

reverse_out

#Usage

template <typename T> std::vector<T> reverse_out(const std::vector<T> &x)

#Description

Returns a reverse stl vector from an input stl vector.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
std::vector<std::string> out = reverse_out(vec);
{"ll", "o", "he"}


reverse_in

#Usage

template <typename T> std::vector<T> reverse_in(const std::vector<T> &x)

#Description

Reverses a stl vector..

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
reverse_out(vec);
{"ll", "o", "he"}


reverse_out_standard

#Usage

template <typename T> std::vector<T> reverse_out(const std::vector<T> &x)

#Description

Returns a reverse stl vector from an input stl vector. Uses another algorithm than reverse_out.

#Arguments

NameDefinition
x is an stl vector

#Example(s)

std::vector<std::string> vec = {"he", "ll", "o"};
std::vector<std::string> out = reverse_out(vec);
{"ll", "o", "he"}


Repetition of elements

rep

#Usage

template <typename T> std::vector<T> rep(const std::vector<T> &x, const std::vector<int> &hmn)

#Description

Returns a stl vector of elements repeted multiple times relatively to an int stl vector.

#Arguments

NameDefinition
x is a stl vector containing all the elements that will be repeated
hmn is a stl int vector containing all the times each element will be repeated

#Example(s)

std::vector<std::string> vec;
std::vector<int> hmn = {4, 2, 7};
std::vector<std::string> elmnts = {"ok", "ko", "ok2"};
vec = rep(elmnts, hmn);
print_svec(vec);
:0: ok ok ok ok ko ko ok2 ok2 ok2 ok2 ok2 ok2 ok2


Sequence/Range of elements

seq

#Usage

template <typename T, typename T2, typename T3> std::vector<T> seq(T from, T2 const &to, T3 const &by)

#Description

Returns a stl range vector(int, float, double).

#Arguments

NameDefinition
from is the starting value
to is the end value
by is the step value

#Example(s)

float from = 1.25;
float to = 3;
float by = 0.25;
std::vector<float> = seq(from, to, by);
{1.25, 1.5, 1.75, 2, 1.25, 2.5, 2.75, 3}


Comparisons to booleans

comp2

#Usage

template <typename T, typename T2> std::vector<bool> comp2(const std::vector<T> &x, const std::vector<T2> &x2)

#Description

Returns a boolean vector of 2 stl vectors that will be compared elements by elements. The vectors should not necessarily be the same size. The output boolean vector will be the same size as the first stl vector argument. This is the prefered way when there are only 2 vectors to compare, compared to using Compv class.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<unsigned int> vec = {1, 5, 2};
std::vector<unsigned int> vecb = {1, 5, 22};
std::vector<bool> out = comp2(vec, vecb);
1 1 0
vec = {1, 5, 2, 1, 5, 2};
out = comp2(vec, vecb);
1 1 0 1 1 0


Variadic / Indefinite number of arguments - Compv Class

Compv.to_comp()

#Usage

Compv comp1(std::vector<Type> vec1);
comp1.to_comp(std::vector<Type> vec2, std::vector<Type> vec3);
comp1.result();
comp1.reinitiate(std::vector<OtherType> vec4);
...

#Description

Returns a boolean vector of multiple stl vectors that will be compared elements by elements. The vectors do not have necessarily to be the same size. The output boolean vector will be the size of the initiation vector.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<unsigned int> vec = {1, 5, 2};
std::vector<unsigned int> vecb = {1, 5, 2};
std::vector<unsigned int> vecc = {1, 5, 22};
std::vector<unsigned int> vec2 = {1, 5};
std::vector<unsigned int> vec2b = {1, 5};
std::vector<unsigned int> vec2c = {1, 5};
Compv obj1(vec);
obj1.to_comp(vecb, vecc);
std::vector<bool> out = obj1.result();
1 1 0
obj1.reinitiate(vec2);
out = obj1.result();
1 1
vec = {1, 5, 22, 1, 5, 2};
obj1.reinitiate(vec);
obj1.to_comp(vec, vecb, vecc);
out = obj1.result();
1 1 0 1 1 0


Lower

lowercomp2

#Usage

template <typename T, typename T2> std::vector<bool> lowercomp2(std::vector<T> &x, std::vector<T2> &x2)

#Description

Returns a boolean vector, 1 if the corresponding values from the first vector is lower than the corresponding values from the second vecotr. The output vector is the size of the first vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> vec = {1, 2.5, -6, 7.8, 2};
std::vector<double> vec = {2, 2};
lowercomp2(vec, vec2);
1 0 1 0 0


Greater

greatercomp2

#Usage

template <typename T, typename T2> std::vector<bool> greatercomp2(std::vector<T> x, T2 x2)

#Description

Returns a boolean vector, 1 if the corresponding values from the first vector is greater than the corresponding values from the second vecotr. The output vector is the size of the first vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> vec = {1, 2.5, -6, 7.8, 2};
std::vector<double> vec = {2, 2, 2, 2, 2};
greatercomp2(vec, vec2);
0 1 0 1 0


Any - All

any

#Usage

bool any(const std::vector<bool> &x)

#Description

Returns 1 if a boolean vector has at least 1 as value of one of its elements, 0 if not.

#Arguments

NameDefinition
x is a stl boolean vector

#Example(s)

std::vector<bool> vec = {0, 0, 1, 0};
bool out = any(vec);
1
std::vector<bool> vec = {0, 0, 0, 0};
out = any(vec);
0


all

#Usage

all any(const std::vector<bool> &x)

#Description

Returns 1 if all the elements of a stl boolean vector equals to 1, 0 if not.

#Arguments

NameDefinition
x is a stl boolean vector

#Example(s)

std::vector<bool> vec = {0, 0, 1, 0};
bool out = all(vec);
0
std::vector<bool> vec = {1, 1, 1, 1};
out = all(vec);
1


Sorting algorithms

sort_descin

#Usage

template <typename T> void sort_descin(std::vector<T> &x)

#Description

Transforms a stl vector (int, float, double, bool) to a sorted decreasing stl vector.

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
sort_descin(vec);
{22, 5, 5, 2, 1, 1}


sort_ascin

#Usage

template <typename T> void sort_ascin(std::vector<T> &x)

#Description

Transforms a stl vector (int, float, double, bool) to a sorted increasing stl vector.

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
sort_ascin(vec);
{1, 1, 2, 5, 5, 22}


sort_descout

#Usage

template <typename T> void sort_descout(std::vector<T> &x)

#Description

Returns a stl sorted decreasingly vector from a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
std::<int> out = sort_descout(vec);
{22, 5, 5, 2, 1, 1}


sort_ascout

#Usage

template <typename T> void sort_ascout(std::vector<T> &x)

#Description

Returns a stl sorted increasingly vector from a stl vector (int, float, double, bool).

#Arguments

NameDefinition
x stl vector (int, float, double, bool)

#Example(s)

std::vector<int> vec = {1, 5, 2, 1, 5, 22};
std::<int> out = sort_ascout(vec);
{1, 1, 2, 5, 5, 22}


Remove range of elements

rm_ordered

#Usage

template <typename T> void rm_ordered(std::vector<T> &x, std::vector<int> ids)

#Description

Remove elements from a stl vector. Keeps the vector sorted at a certain computational cost compared to rm_unordered. The stl int vector provided for the indices of the element to be removed must be decreasingly sorted. The capacity of the vector is kept unchanged, so if you want to shrink it, consider doing shrink_to_fit() method.

#Arguments

NameDefinition
x is an stl vector
ids is an stl int vector decreasingly sorted

#Example(s)

std::vector<int> vec = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> ids = {8, 5, 3, 2};
rm_ordered(vec, ids);
print_nvec(vec);
:0: 0 1 4 6 7 9


rm_unordered

#Usage

template <typename T> void rm_unordered(std::vector<T> &x, std::vector<int> ids)

#Description

Remove elements from a stl vector. Does not keep the vector sorted for computational speed compared to rm_ordered. The stl int vector provided for the indices of the element to be removed must be decreasingly sorted. The capacity of the vector is kept unchanged, so if you want to shrink it, consider doing shrink_to_fit() method.

#Arguments

NameDefinition
x is an stl vector
ids is an stl int vector decreasingly sorted

#Example(s)

std::vector<int> vec = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> ids = {8, 5, 3, 2};
rm_unordered(vec, ids);
print_nvec(vec);
:0: 0 1 6 7 4 9


Sets (Union - Diff - Removing shared elements)

union2

#Usage

template <typename T> std::vector<T> union2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the union of two stl vectors. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = union2(vec1, vec2);
print_nvec(out);
:0: 3 4 4 5 7 8 2 4 0 1 2 3 9 11


Variadic / Indefinite number of arguments - Unionv Class

Unionv.to_union()

#Usage

Unionv union1(std::vector<Type> vec1);
union1.to_union(std::vector<Type> vec2, std::vector<Type> vec3);
union1.result();
union1.reinitiate(std::vector<Type2> vec4);
...

#Arguments

NameDefinition
... undefinite number of stl vector of the same type

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Unionv union1(vec1);
union1.to_union(vec2, vec3, vec3);
std::vector<int> out = union1.result();
print_nvec(out);
:0: 3 4 4 5 7 8 2 4 11 0 1 2 3 9 11 4 0 1 2 3 11 9 0 1
union1.reinitiate(vec2);
union1.to_union(vec1);
out = union1.result();
print_nvec(out);
:0: 0 1 2 3 9 11 4 3 4 4 5 7 8 2 4 11


intersect2

#Usage

template <typename T> std::vector<T> union2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the commun elements of two stl vectors of the same type. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = intersect2(vec1, vec2);
print_nvec(out);
:0: 2 3


Variadic / Indefinite number of arguments - Intersectv Class

Intersectv.to_intersect()

#Usage

Intersectv intersect1(std::vector<Type> vec1);
intersect1.to_intersect(std::vector<Type> vec2, std::vector<Type> vec3);
intersect1.reinitiate(std::vector<Type2>);
...

#Description

Returns the commun elements of undefinite number of stl vectors of the same type. The returned vector can have extra capacity non initiated, to get rid of that consider applying it the shrink_to_fit() method. The returned vector does not return unique elements, so if you want unique elements, consider enter unique stl vectors as input.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Intersectv intersect1(vec1);
intersect1.to_intersect(vec2, vec3);
std::vector<int> out = intersect1.result();
print_nvec(out);
:0: 3 2 11
intersect1.reinitiate(vec1);
intersect1.to_intersect(vec2);
out = intersect1.result();
print_nvec(out);
:0: 3 4 4 2 4 11


diff2

#Usage

template <typename T> std::vector<T> diff2(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the elements that are in one of the stl vector but not in the intersection of all stl vectors. Does not returns a stl vector with unique elements, so if you want it to return unique elements, make sure to enter unique stl vectors as input.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> out = diff2(vec1, vec2);
print_nvec(out);
:0: 9 4 4 5 7 8 11 4 0 1


Variadic / Indefinite number of arguments - Diffv Class

Diffv.to_diff()

#Usage

Diffv diff1(std::vector<Type> vec1)
diff1.to_diff(std::vector<Type> vec2, std::vector<Type> vec2);
diff1.result();
diff1.reinitiate(std::vector<Type2> vec4);
...

#Description

Returs a stl vector of all the elements that are in one of the undefinite number of input stl vectors (of the same type) or more, but not in the intersection of all these stl vectors. Does not return a stl vector with unique elements, if you want it to return a stl vector with unique elements make sure that your input vectors contain unique elements. The returned vector can have more capacity than its size, to get rid of this unusable memory, you can apply the shrink_to_fit() method on it.

#Arguments

NameDefinition
... undefinite number of stl vectors of the same type

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> vec3 = {0, 1, 2, 3, 11, 9};
Diffv diff1(vec1);
diff1.to_diff(vec2, vec3);
std::vector<int> out = diff1.result();
print_nvec(out);
:0: 9 4 4 5 7 8 9 4 4 0 1 0 1
diff1.reinitiate(vec3);
diff1.to_diff(vec2, vec1);
out = diff1.result();
print_nvec(out);
:0: 0 1 4 4 4 9 0 1 5 7 9 8 4 //same elements, different orders because the initializer vector is not the same


rm_shared_in

#Usage

template <typename T> void rm_shared_in(std::vector<T> &x, std::vector<T> &x2)

#Description

Transforms the first stl vector input removing its commun elements with the second stl vector of the same type. The returned vector has its capacity unchanged, so consider applying the shrink_to_fit() method to it if you want to free some memory.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
rm_shared_in(vec1, vec2);
print_nvec(vec1);
:0: 5 7 8


rm_shared_out

#Usage

template <typename T> std::vector<T> rm_shared_out(std::vector<T> &x, std::vector<T> &x2)

#Description

Returns the first stl vector input minus the its commun elements with the second stl vector of the same type. The returned vector has its capacity unchanged, so consider applying the shrink_to_fit() method to it if you want to free some memory.

#Arguments

NameDefinition
x is an stl vector
x2 is an stl vector

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4, 11};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11, 4};
std::vector<int> out = rm_shared_out(vec1, vec2);
print_nvec(out);
:0: 5 7 8


Variadic / Indefinite number of arguments - Rm_sharedv Class

Rm_sharedv.to_rm()

#Usage

Rm_sharedv rm1(std::vector<Type> vec1);
rm1.to_comp(std::vector<Type> vec2, std::vector<Type> vec3);
rm1.result();
rm1.reinitiate(std::vector<OtherType> vec4);
...

#Description

Returns the initializer vector with the shared elements between this vector and an undefinite number of stl vectors, removed. This method is faster than finding commun elements between undefinite number of stl vectors and the initializer vector, and then removing the commun elements.

#Arguments

NameDefinition
... undefinite number of stl vectors

#Example(s)

std::vector<int> vec1 = {3, 4, 4, 5, 7, 8, 2, 4};
std::vector<int> vec2 = {0, 1, 2, 3, 9, 11};
std::vector<int> vec3 = {0, 1, 2, 3, 9, 11, 8};
Rm_sharedv obj1(vec1);
obj1.to_rm(vec2, vec3);
std::vector<int> out = obj1.result();
print_nvec(out);
:0: 4 4 4 5 7
obj1.reinitiate(vec1);
out = obj1.result();
print_nvec(out);
:0: 3 4 4 5 7 8 2 4


Finding closest elements in stl vector

closest_idx

#Usage

template <typename T> unsigned int closest_idx(std::vector<T> &x, T &val)

#Description

Returns the closest elements from a stl vector (int, float, double, bool) and a given value as the index of the closet element of the stl vector. This is equivalent to finding the index of the minimum difference between the value and the elements in the stl vector, but more efficiently since the function assumes the stl vector is already sorted ascendly or descendly as you see in examples.

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool), must be ascendly or descendly sorted
val is an int, float, double, bool

#Example(s)

std::vector<double> vec = {0.1, 0.89, 1.2, 1.66, 1.78, 2.25, 4.56};
double val = 1.97;
closest_idx(vec, val);
4
val = 0.99;
closest_idx(vec, val);
1
std::vector<double> vec2 = sort_descout(vec);
closest_idx(vec, val);
5
val = 5.33;
closest_val(vec2, val);
0


String and vectors conversions

Collapse (vector to string)

ncollapse

#Usage

template <typename T, typename T2> std::string ncollapse(const std::vector<T> &x, const T2 &sep)

#Description

Collapses all elements from an stl vector (int, float, double, bool) to a string with a given separator.

#Arguments

NameDefinition
x is an stl vector (int, float, double, bool)
sep is a char or string that will be the separator between the elements of x

#Example(s)

std::vector<int> vec = {5, 7, 22, 879};
char sep = "-";
std::string out = ncollapse(vec, sep);
"5-7-22-879"

std::string sep2 = "--";
out = ncollapse(vec, sep2);
"5--7--22--879"


scollapse

#Usage

template <typename T> std::string scollapse(const std::vector<std::string> &x, const T &sep)

#Description

Collapses all elements from an stl string vector to a string with a given separator.

#Arguments

NameDefinition
x is an stl vector (stl string)
sep is a char or string that will be the separator between the elements of x

#Example(s)

std::vector<std::string> vec = {"yess", "no", "maybe"};
char sep = "-";
std::string out = ncollapse(vec, sep);
"yess-no-maybe"

std::string sep2 = "--";
out = ncollapse(vec, sep2);
"yess--no--maybe"


Split (string to vector)

split

#Usage

std::vector<std::string> split(const std::string &x, const char &sep)

#Description

Returns a stl vector of stl strings that are part of the input stl string. The input string must have a separator to differenciate elements for the output stl vector.

#Arguments

NameDefinition
x is a stl string
sep is a char

#Example(s)

std::string test = "y-e-ss";
char sep = '-';
std::vector<std::string> out = split(test, sep);
{"y", "e", "ss"}


Others

pct_to_idx

#Usage

unsigned int percentage_to_idx(double &val, unsigned int &sizen)

#Description

Returns an idx of a stl vector from a percentage between 0 and 1.

#Arguments

NameDefinition
val is the percentage value, between 0 and 1
sizen is the size of the vector you want to have the index.

#Example(s)

std::<int> vec = {1, 2, 3, 4};
unsigned int sizen = vec.size();
double pct = 0.6;
unsigned int out = pct_to_idx(pct, sizen);
2


diff_mean

#Usage

template <typename T> double diff_mean(std::vector<T> &x)

#Description

Returns the mean of all the differences in value between the contiguous elementsof a stl vector.

#Arguments

NameDefinition
x is a stl vector (int, float, double, bool)

#Example(s)

std::vector<double> vec = {10, 10.5, 11, 11.5};
diff_mean(vec);
0.5


Operations on matrices like 2d vectors std::vector<std::vector<Type>>

Sum elements for each rows and columns

sum_nxp

#Usage

template <typename T> std::vector<std::vector<T>> sum_nxp(std::vector<std::vector<T>> &matr)

#Description

Returns as the first vector the sum of elements in each row, and in the second vector the sum of each elements in each column

#Arguments

NameDefinition
matr is the input matrice

#Example(s)

std::vector<std::vector<double>> matr = {{1, 2}, {3, 4}, {5, 6}};
print_matr(matr);
std::vector<std::vector<double>> outmatr = sum_xnx(matr);
for (double i : outmatr[0]) {
std::cout << i << " ";
};
std::cout << "\n";
for (double i : outmatr[1]) {
std::cout << i << " ";
};
std::cout << "\n";
9 12
3 7 11


Transposition

t

#Usage

template <typename T> std::vector<std::vector<T>> t(const std::vector<std::vector<T>> &x)

#Description

Retursn the transpose of a matrix as 2D stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is a 2D stl vector (int, float, double, bool)

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3}, {4, 5, 6}};
print_matr(matr); // another function from this library to print matrix as 2D stl vector
[0] [1]
:0: 1 4
:1: 2 5
:2: 3 6
std::vector<std::vector<int>> out = t(matr);
print_matr(out);
[0] [1] [2]
:0: 1 2 3
:1: 4 5 6


t_in_square

#Usage

template <typename T> void t_in_square(std::vector<std::vector<T>> &x)

#Description

Transforms the input square matrix as 2D stl vector (int, float, double, bool) to its transpose.

#Arguments

NameDefinition
x is a 2D stl vector (int, float, double, bool)

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print_matr(matr); // another function from this library to print matrix as 2D stl vector

[0] [1] [2]
:0: 1 4 7
:1: 2 5 8
:2: 3 6 9

t_in_square(matr);

print_matr(matr);

[0] [1] [2]
:0: 1 2 3
:1: 4 5 6
:2: 7 8 9


t_in

#Usage

template <typename T> void t_in(std::vector<std::vector<T>> &x)

#Description

Transforms a matrix as 2D stl vector to its transpose

#Arguments

NameDefinition
x is a matrix as a 2D stl vector

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3, 88, 90}, {4, -5, 6, 78, -7}, {-7, 8, -9, 12, 478}};
print_matr(matr);
[0] [1] [2]
:0: 1 4 -7
:1: 2 -5 8
:2: 3 6 -9
:3: 88 78 12
:4: 90 -7 478
t_in(matr);
print_matr(matr);
[0] [1] [2] [3] [4]
:0: 1 2 3 88 90
:1: 4 -5 6 78 -7
:2: -7 8 -9 12 478
t_in(matr);
print_matr(matr);
[0] [1] [2]
:0: 1 4 -7
:1: 2 -5 8
:2: 3 6 -9
:3: 88 78 12
:4: 90 -7 478


Print

print_matr

#Usage

template <typename T> void print_matr(const std::vector<std::vector<T>> &x)

#Description

Print a matrix as 2D stl vector.

#Arguments

NameDefinition
x is a 2D stl vector

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
print_matr(matr);
[0] [1] [2]
:0: 1 4 7
:1: 2 5 8
:2: 3 6 9


Absolute values

abs_matrin

#Usage

template <typename T> void abs_matrin(std::vector<std::vector<T>> &x)

#Description

Transforms all the values of the cells from a matrix as 2D stl vector (int, float, double, bool) to absolute values.

#Arguments

NameDefinition
x is a matrix as 2D stl vector (int, float, double, bool)

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3}, {4, -5, 6}, {-7, 8, -9}};
print_matr(matr); // another function from this library to print matrix as 2D stl vector
[0] [1] [2]
:0: 1 4 -7
:1: 2 -5 8
:2: 3 6 -9
abs_matrin(matr);
print_matr(matr);
[0] [1] [2]
:0: 1 4 7
:1: 2 5 8
:2: 3 6 9


abs_matrout

#Usage

template <typename T> void abs_matrout(std::vector<std::vector<T>> &x)

#Description

Returns a marix as 2D stl vector (int, float, double, bool) with only absolute values from a matrix as 2D stl vector (int, float, double, bool).

#Arguments

NameDefinition
x is a matrix as 2D stl vector (int, float, double, bool)

#Example(s)

std::vector<std::vector<int>> matr = {{1, 2, 3}, {4, -5, 6}, {-7, 8, -9}};
print_matr(matr); // another function from this library to print matrix as 2D stl vector
[0] [1] [2]
:0: 1 4 -7
:1: 2 -5 8
:2: 3 6 -9
std::vector<std::vector<int>> out = abs_matrout(matr);
print_matr(out);
[0] [1] [2]
:0: 1 4 7
:1: 2 5 8
:2: 3 6 9


Fulgurance Tools

Parser_tokenizer_full

#Usage

std::vector<std::vector<unsigned int>> Parser_tokenizer_full(std::string &x, char frst_chr = '(', char scd_chr = ')')

#Description

Returns a 2d stl vectors. First vector is the pair of each parenthesis. Second stl vector is the index of each parenthesis. Takes a stl string as input.

#Arguments

NameDefinition
x is a stl string

#Example(s)

std::string teste = "(o((ldjf)de)po(m()()m)po)()()";
std::vector<std::vector<unsigned int>> out = Parser_tokenizer_full(teste);
{5 1 0 0 1 4 2 2 3 3 4 5 6 6 7 7}
{0 2 3 8 11 14 16 17 18 19 21 24 25 26 27 28}


is_symetric

#Usage

template <typename T> bool is_symetric(std::vector<T> &x)

#Description

Returns 1 if the vector is symetric, 0 if not. See examples.

#Arguments

NameDefinition
x is the input vector of any type

#Example(s)

std::vector<int> vec = {0, 1, 2, 43, 2, 1, 0};
bool out = is_symetric(vec);
1
vec = {0, 1, 2, 2, 1, 0};
out = is_symetric(vec);
1
vec = {0, 1, 2, 2, 22, 0};
out = is_symetric(vec);
0


all_comb

#Usage

std::vector<std::vector<bool>> all_comb(unsigned int &k, unsigned int &n)

#Description

Returns all the combinations of k elements in a set of n elements.

#Arguments

NameDefinition
k is the k value
n is the total number of the set

#Example(s)

unsigned int k = 5;
unsigned int n = 9;
std::vector<std::vector<bool>> outmatr = all_comb(k, n);
int i2;
for (int i = 0; i < outmatr.size(); ++i) {
for (i2 = 0; i2 < outmatr[0].size(); ++i2) {
std::cout << outmatr[i][i2] <<< " ";
};
std::cout << "\n";
};
1 1 1 1 1 0 0 0 0
1 1 1 1 0 1 0 0 0
1 1 1 1 0 0 1 0 0
1 1 1 1 0 0 0 1 0
1 1 1 1 0 0 0 0 1
1 1 1 0 1 1 0 0 0
1 1 1 0 1 0 1 0 0
1 1 1 0 1 0 0 1 0
1 1 1 0 1 0 0 0 1
1 1 1 0 0 1 1 0 0
1 1 1 0 0 1 0 1 0
1 1 1 0 0 1 0 0 1
1 1 1 0 0 0 1 1 0
1 1 1 0 0 0 1 0 1
1 1 1 0 0 0 0 1 1
1 1 0 1 1 1 0 0 0
1 1 0 1 1 0 1 0 0
1 1 0 1 1 0 0 1 0
1 1 0 1 1 0 0 0 1
1 1 0 1 0 1 1 0 0
1 1 0 1 0 1 0 1 0
1 1 0 1 0 1 0 0 1
1 1 0 1 0 0 1 1 0
1 1 0 1 0 0 1 0 1
1 1 0 1 0 0 0 1 1
1 1 0 0 1 1 1 0 0
1 1 0 0 1 1 0 1 0
1 1 0 0 1 1 0 0 1
1 1 0 0 1 0 1 1 0
1 1 0 0 1 0 1 0 1
1 1 0 0 1 0 0 1 1
1 1 0 0 0 1 1 1 0
1 1 0 0 0 1 1 0 1
1 1 0 0 0 1 0 1 1
1 1 0 0 0 0 1 1 1
1 0 1 1 1 1 0 0 0
1 0 1 1 1 0 1 0 0
1 0 1 1 1 0 0 1 0
1 0 1 1 1 0 0 0 1
1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 0 1 0
1 0 1 1 0 1 0 0 1
1 0 1 1 0 0 1 1 0
1 0 1 1 0 0 1 0 1
1 0 1 1 0 0 0 1 1
1 0 1 0 1 1 1 0 0
1 0 1 0 1 1 0 1 0
1 0 1 0 1 1 0 0 1
1 0 1 0 1 0 1 1 0
1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 0 1 1
1 0 1 0 0 1 1 1 0
1 0 1 0 0 1 1 0 1
1 0 1 0 0 1 0 1 1
1 0 1 0 0 0 1 1 1
1 0 0 1 1 1 1 0 0
1 0 0 1 1 1 0 1 0
1 0 0 1 1 1 0 0 1
1 0 0 1 1 0 1 1 0
1 0 0 1 1 0 1 0 1
1 0 0 1 1 0 0 1 1
1 0 0 1 0 1 1 1 0
1 0 0 1 0 1 1 0 1
1 0 0 1 0 1 0 1 1
1 0 0 1 0 0 1 1 1
1 0 0 0 1 1 1 1 0
1 0 0 0 1 1 1 0 1
1 0 0 0 1 1 0 1 1
1 0 0 0 1 0 1 1 1
1 0 0 0 0 1 1 1 1
0 1 1 1 1 1 0 0 0
0 1 1 1 1 0 1 0 0
0 1 1 1 1 0 0 1 0
0 1 1 1 1 0 0 0 1
0 1 1 1 0 1 1 0 0
0 1 1 1 0 1 0 1 0
0 1 1 1 0 1 0 0 1
0 1 1 1 0 0 1 1 0
0 1 1 1 0 0 1 0 1
0 1 1 1 0 0 0 1 1
0 1 1 0 1 1 1 0 0
0 1 1 0 1 1 0 1 0
0 1 1 0 1 1 0 0 1
0 1 1 0 1 0 1 1 0
0 1 1 0 1 0 1 0 1
0 1 1 0 1 0 0 1 1
0 1 1 0 0 1 1 1 0
0 1 1 0 0 1 1 0 1
0 1 1 0 0 1 0 1 1
0 1 1 0 0 0 1 1 1
0 1 0 1 1 1 1 0 0
0 1 0 1 1 1 0 1 0
0 1 0 1 1 1 0 0 1
0 1 0 1 1 0 1 1 0
0 1 0 1 1 0 1 0 1
0 1 0 1 1 0 0 1 1
0 1 0 1 0 1 1 1 0
0 1 0 1 0 1 1 0 1
0 1 0 1 0 1 0 1 1
0 1 0 1 0 0 1 1 1
0 1 0 0 1 1 1 1 0
0 1 0 0 1 1 1 0 1
0 1 0 0 1 1 0 1 1
0 1 0 0 1 0 1 1 1
0 1 0 0 0 1 1 1 1
0 0 1 1 1 1 1 0 0
0 0 1 1 1 1 0 1 0
0 0 1 1 1 1 0 0 1
0 0 1 1 1 0 1 1 0
0 0 1 1 1 0 1 0 1
0 0 1 1 1 0 0 1 1
0 0 1 1 0 1 1 1 0
0 0 1 1 0 1 1 0 1
0 0 1 1 0 1 0 1 1
0 0 1 1 0 0 1 1 1
0 0 1 0 1 1 1 1 0
0 0 1 0 1 1 1 0 1
0 0 1 0 1 1 0 1 1
0 0 1 0 1 0 1 1 1
0 0 1 0 0 1 1 1 1
0 0 0 1 1 1 1 1 0
0 0 0 1 1 1 1 0 1
0 0 0 1 1 1 0 1 1
0 0 0 1 1 0 1 1 1
0 0 0 1 0 1 1 1 1
0 0 0 0 1 1 1 1 1
std::cout << outmatr.size() << "\n";
126


all_comb_iter

#Usage

unsigned int all_comb_iter(std::deque<bool> &x)

#Description

Returns the number of iterations to find the input boolean vector according to all_comb algorithm

#Arguments

NameDefinition
x is the input boolean vector

#Example(s)

std::vector<bool> teste_dq = {1, 0, 1, 1, 1, 1, 0};
unsigned int out = all_comb_iter(teste_dq);
11


all_comb_iterdq

#Usage

unsigned int all_comb_iterdq(std::deque<bool> &x)

#Description

Returns the number of iterations to find the input boolean deque according to all_comb algorithm

#Arguments

NameDefinition
x is the input boolean deque

#Example(s)

std::deque<bool> teste_dq = {1, 0, 1, 1, 1, 1, 0};
unsigned int out = all_comb_iterdq(teste_dq);
11


bool_gen

#Usage

std::vector<bool> bool_gen(unsigned int &k, unsigned int &n, double seed = 0)

#Description

Returns a boolean vector of size n, with k elements equal to 1

#Arguments

NameDefinition
k is the number of elements that should equal to 1
n is the size of the vector
seed 0, if the vector should be randomly generated, strictly positive values either

#Example(s)

unsigned int k = 5;
unsigned int n = 17;
std::vector<bool> out = bool_gen(k, n, 0);
print_nvec(out);
:0: 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1


Binary conversions

int_to_binarydq

#Usage

std::deque<bool> int_to_binarydq(unsigned int x)

#Description

Converts an unsigned int to a binary format as a boolean deque

#Arguments

NameDefinition
x is the input unsigned int

#Example(s)

std::deque rtn_dq = int_to_binarydq(1286);
1 0 1 0 0 0 0 0 1 1 0


binarydq_to_int

#Usage

unsigned int binarydq_to_int(std::deque<bool> &x)

#Description

Converts a binary format as a boolean deque to an unsigned int

#Arguments

NameDefinition
x is the input boolean std deque

#Example(s)

std::deque<bool> dq_input = {1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0};
unsigned int out = binarydq_to_int(rtn_dq);
1286


About

Lienar algebra, data manipulation and statistical library written in C++, for C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages