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

Dataframes implementation is a class. All functions that will transform 'voidly' (internaly) the relative data are built in the class. All functions that copy and transform the relative data are extern to classes.

Matrices are 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

itos

#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"


RegEx

regex_match

#Usage

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

#Description

Performs a match with the regex flavor.

This library provides an entirely new RegEx flavor.

Read documentation in README_RegEx.md file for details about synthax.

#Arguments

NameDefinition
searched is the regular expression
x is the text to search into

#Example(s)

std::string inpt_str = "Le radiateur fonctionne bien.";
std::string searched = "[A-Z a-z][A-Z{+1}a-z{+1} {+1}]{?bien}[A-Z{0}]{+1}";

std::map<std::vector<int>, std::map<bool, std::string>> out_mp = regex_match(searched, inpt_str);
std::map<std::vector<int>, std::map<bool, std::string>>::iterator out_it = out_mp.begin();
std::vector<int> idx_v = out_it->first;
std::map<bool, std::string>::iterator rslt_mp = out_it->second.begin();
std::string rtn_str = rslt_mp->second;
bool is_found = rslt_mp->first;
if (is_found) {
std::cout << idx_v[0] << "\n";
std::cout << idx_v[1] << "\n";
std::cout << is_found << "\n";
std::cout << rtn_str << "\n";
} else {
std::cout << "not found\n";
};

0
28
1
Le radiateur fonctionne bien.


regex_grep

#Usage

std::map<std::vector<int>, std::vector<std::string>> regex_grep(std::string &searched, std::string &x)

#Description

Performs a grep with the regex flavor.

This library provides an entirely new RegEx flavor.

Read documentation in README_RegEx.md file for details about synthax.

#Arguments

NameDefinition
searched is the input regular expression
x is the text to search into

#Example(s)

std::string inpt_str = "MMMLe radiateur fonctionne bien.";
std::string searched = "[A-Z a-z][A-Z{+1}a-z{+1} {+1}]{?bien}[A-Z{0}]{+1}";

std::map<std::vector<int>, std::vector<std::string>> out_mp2 = regex_search_all(searched, inpt_str);
std::map<std::vector<int>, std::vector<std::string>>::iterator out_it2 = out_mp2.begin();
std::vector<int> idx_v2 = out_it2->first;
std::vector<std::string> str_v2 = out_it2->second;
for (int i = 0; i < str_v2.size(); ++i) {
std::cout << "idx: " << idx_v2[i] << " str: " << str_v2[i] << "\n";
};
idx: 31 str: Le radiateur fonctionne bien.
idx: 31 str: radiateur fonctionne bien.
idx: 31 str: fonctionne bien.
idx: 31 str: e radiateur fonctionne bien.
idx: 31 str: r fonctionne bien.
idx: 31 str: e bien.


regex_subout

#Usage

std::string regex_subout(std::string &searched, std::string &replacer, std::string x)

#Description

Substituates the first pattern matched by the regular expression, to a replacement pattern.

#Arguments

NameDefinition
searched is the regular expression
replacer is the replacement pattern
x is the input string to replace searched by replacer into

#Example(s)

std::string inpt_str = "MMMLe radiateur fonctionne bien.... C'est un bon radiateur.";
std::string rplcd = " moteur ";
std::string searched = " a-z{9}[ .]";
std::string out_txt = regex_subout(searched, rplcd, inpt_str);
std::cout << out_txt << "\n";
MMMLe moteur fonctionne bien.... C'est un bon radiateur.


regex_subout_all

#Usage

std::string regex_subout_all(std::string &searched, std::string &replacer, std::string x)

#Description

Substituates all patterns matched by the regular expression, to a replacement pattern.

#Arguments

NameDefinition
searched is the regular expression
replacer is the replacement pattern
x is the input string to replace searched by replacer into

#Example(s)

std::string inpt_str = "MMMLe radiateur fonctionne bien.... C'est un bon radiateur.";
std::string rplcd = " moteur ";
std::string searched = " a-z{9}[ .]";
std::string out_txt = regex_subout_all(searched, rplcd, inpt_str);
std::cout << out_txt << "\n";
MMMLe moteur fonctionne bien.... C'est un bon moteur.


regex_subin

#Usage

void regex_subin(std::string &searched, std::string &replacer, std::string &x)

#Description

Substituates the first pattern matched by the regular expression, to a replacement pattern.

#Arguments

NameDefinition
searched is the regular expression
replacer is the replacement pattern
x is the input string to replace searched by replacer into

#Example(s)

std::string inpt_str = "MMMLe radiateur fonctionne bien.... C'est un bon radiateur.";
std::string rplcd = " moteur ";
std::string searched = " a-z{9}[ .]";
regex_subin(searched, rplcd, inpt_str);
std::cout << inpt_str << "\n";
MMMLe moteur fonctionne bien.... C'est un bon radiateur.


regex_subin_all

#Usage

void regex_subin_all(std::string &searched, std::string &replacer, std::string &x)

#Description

Substituates all patterns matched by the regular expression, to a replacement pattern.

#Arguments

NameDefinition
searched is the regular expression
replacer is the replacement pattern
x is the input string to replace searched by replacer into

#Example(s)

std::string inpt_str = "MMMLe radiateur fonctionne bien.... C'est un bon radiateur.";
std::string rplcd = " moteur ";
std::string searched = " a-z{9}[ .]";
regex_subin_all(searched, rplcd, inpt_str);
std::cout << inpt_str << "\n";
MMMLe moteur fonctionne bien.... C'est un bon moteur.


Can be num ?

can_be_nb

#Usage

bool can_be_nb(std::string &x)

#Description

Returns a boolean, 1 if the input std::string can be converted to a number (int, float...), 0 if not.

#Arguments

NameDefinition
x is the input stdstring

#Example(s)

std::string inpt_str = "15.69596";
bool rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569T596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "15.69.596";
rslt = can_be_nb(inpt_str);
std::cout << rslt << "\n";

0


can_be_flt_dbl

#Usage

bool can_be_flt_dbl(std::string &x)

#Description

Returns a boolean, 1 if the input std::string can be converted to a float or double, 0 if not.

#Arguments

NameDefinition
x is the input stdstring

#Example(s)

std::string inpt_str = "15.69596";
bool rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

1

inpt_str = "1569596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "1569T596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0

inpt_str = "15.69.596";
rslt = can_be_flt_dbl(inpt_str);
std::cout << rslt << "\n";

0


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


Hypergeometric distribution

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<int> x = {150, 190, 400};
int n_trials = 555;
std::vector<double> out = dhyper(x, n_ones, n_others, n_trials);
print_nvec(out);
:0: 0.00807227 1.69452e-11 4.42674e-236


phyper

#Usage

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

#Description

Returns the cumulative hypergeometric distribution (interval between the first value of the input quantiles and last value)

#Arguments

NameDefinition
x is the vector of qualtiles
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<int> x = {0, 150};

int n_trials = 555;

std::vector<double> out_v = phyper(x, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 2.59543e-84 0.973988


qhyper

#Usage

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

#Description

Returns the quantiles of the input probabilities according to the hypergeometric probability distribution.

#Arguments

NameDefinition
x is the vector of the input probabilities, must be ascendly sorted
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<double> x = {0.05, 0.12, 0.35, 0.36, 0.36, 0.56, 0.78};

int n_trials = 555;

std::vector<unsigned int> out_v = qhyper(x, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 121 124 131 131 131 135 139


rhyper

#Usage

std::vector<unsigned int> rhyper(unsigned int &n_obs, unsigned int &n_ones, unsigned int n_others, int &n_trials)

#Description

Returns pseudo-randomly generated values that follow a hypergeometric distribution

#Arguments

NameDefinition
n_obs is the number of observations
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;

int n_trials = 555;
unsigned int n_obs = 12;

std::vector<unsigned int> out_v = rhyper(n_obs, n_ones, n_others, n_trials);

print_nvec(out_v);

:0: 129 133 136 139 143 149 124 129 133 136 139 143


Operations between vectors

add_vout

#Usage

template <typename T, typename T2> std::vector<T> add_vout(std::vector<T> x, T2 &to_add)

#Description

Adds a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_add is the value to add

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = add_vout(inv, val);
print_nvec(outv);
:0: 6.3 9.3 5.3 8.3


subs_vout

#Usage

template <typename T, typename T2> std::vector<T> subs_vout(std::vector<T> x, T2 &to_subs)

#Description

Substracts a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_substract is the value to substract

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = subs_vout(inv, val);
print_nvec(outv);
:0: -2.3 0.7 -3.3 -0.3


mult_vout

#Usage

template <typename T, typename T2> std::vector<T> mult_vout(std::vector<T> x, T2 &to_mult)

#Description

Multiplicates a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_multiplicate is the value to multiplicate

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = mult_vout(inv, val);
print_nvec(outv);
:0: 8.6 21.5 4.3 17.2


divide_vout

#Usage

template <typename T, typename T2> std::vector<T> divide_vout(std::vector<T> x, T2 &to_divide)

#Description

Divides a value to all elements of the input vector, returns the vector.

#Arguments

NameDefinition
x is the input vector
to_divide is the value to divide

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
std::vector<double> outv = divide_vout(inv, val);
print_nvec(outv);
:0: 0.465116 1.16279 0.232558 0.930233


add_vin

#Usage

template <typename T, typename T2> void add_vin(std::vector<T> &x, T2 &to_add)

#Description

Adds a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_add is the value to add

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
add_vin(inv, val);
print_nvec(inv);
:0: 6.3 9.3 5.3 8.3


subs_vin

#Usage

template <typename T, typename T2> void subs_vin(std::vector<T> &x, T2 &to_subs)

#Description

Substracts a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_subs is the value to substract

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
subs_vin(inv, val);
print_nvec(inv);
:0: -2.3 0.7 -3.3 -0.3


mult_vin

#Usage

template <typename T, typename T2> void mult_vin(std::vector<T> &x, T2 &to_mult)

#Description

Multiplicates a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_mult is the value to multiplicate

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
mult_vin(inv, val);
print_nvec(inv);
:0: 8.6 21.5 4.3 17.2


divide_vin

#Usage

template <typename T, typename T2> void divide_vin(std::vector<T> &x, T2 &to_divide)

#Description

Divides a value to all elements of the input vector.

#Arguments

NameDefinition
x is the input vector
to_divide is the value to divide

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
double val = 4.3;
divide_vin(inv, val);
print_nvec(inv);
:0: 0.465116 1.16279 0.232558 0.930233


add_v2out

#Usage

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

#Description

Add corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = add_v2out(inv, inv2);

print_nvec(outv);
:0: 4 10 3 9


subs_v2out

#Usage

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

#Description

Substracts corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = subs_v2out(inv, inv2);

print_nvec(outv);
:0: 0 0 -1 -1


mult_v2out

#Usage

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

#Description

Multiplies corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = mult_v2out(inv, inv2);

print_nvec(outv);
:0: 4 25 2 20


divide_v2out

#Usage

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

#Description

Divides corresponding elements of 2 vectors, returns vector.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)

std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

std::vector<double> outv = divide_v2out(inv, inv2);

print_nvec(outv);
:0: 1 1 0.5 0.8


add_v2in

#Usage

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

#Description

Adds corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

add_v2in(inv, inv2);

print_nvec(inv);
:0: 4 10 3 9


subs_v2in

#Usage

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

#Description

Substract corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

subs_v2in(inv, inv2);

print_nvec(inv);
:0: 0 0 -1 -1


mult_v2in

#Usage

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

#Description

Multiplies corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

mult_v2in(inv, inv2);

print_nvec(inv);
:0: 4 25 2 20


divide_v2in

#Usage

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

#Description

Adds corresponding elements of 2 vectors.

#Arguments

NameDefinition
x is the first vector
x2 is the second vector

#Example(s)


std::vector<double> inv = {2, 5, 1, 4};
std::vector<double> inv2 = {2, 5};

double val = 4.3;

divide_v2in(inv, inv2);

print_nvec(inv);

:0: 1 1 0.5 0.8


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

#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 < 50; ++i) { vec.push_back(i); }
print_nvec(vec);
:0: 12 2 4534 7 -78 12122 0 1 2 3
:10: 4 5 6 7 8 9 10 11 12 13
:20: 14 15 16 17 18 19 20 21 22 23
:30: 24 25 26 27 28 29 30 31 32 33
:40: 34 35 36 37 38 39 40 41 42 43
:50: 44 45 46 47 48 49



#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> vec2 = {"peugeot", "wolkswagen", "honda", "renault", "stellantis"};
for (int i = 0; i < 20; ++i) { vec2.push_back("yesss"); }
print_svec(vec2);
:0: peugeot wolkswagen honda renault stellantis yesss yesss yesss
:8: yesss yesss yesss yesss yesss yesss yesss yesss
:16: yesss yesss yesss yesss yesss yesss yesss yesss
:24: 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}


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


Bool and indices conversions

bool_to_idx

#Usage

std::vector<unsigned int> bool_to_idx(std::vector<bool> &x)

#Description

Converts a boolean vector to an indices vector.

#Arguments

NameDefinition
x is the input boolean vector

#Example(s)

std::vector<bool> xbool = {0, 0, 1, 1, 0, 1, 0};
std::vector xidx = bool_to_idx(xbool);
print_nvec(xidx);
2 3 5


idx_to_bool

#Usage

std::vector<bool> idx_to_bool(std::vector<unsigned int> &x, int target_size = -1)

#Description

Converts a indice vector to a boolean vector

#Arguments

NameDefinition
x is the input indices vector
target_size is the size of the wanted output boolean vector

#Example(s)

std::vector<unsigned int> xidx = {2, 3, 5};
std::vector<bool> xbool = idx_to_bool(xidx, 7);
print_nvec(xbool);
:0: 0 0 1 1 0 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}


str_sort_descend

#Usage

std::vector<std::string> str_sort_descend(std::vector<std::string> &x,
std::vector order_v = {
' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '[', '\\',
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '{', '|', '}',
'~'
})

#Description

Returns a descendly sorted vector of std::string (according to ascii table order by default)

#Arguments

NameDefinition
x is the input vector
order_v is the order of each character (ascii table by default)

#Example(s)

std::vector<std::string> inv = {"b", "c", "a", "b", "a", "aa", "ab"};
std::vector<std::string> outv = str_sort_descend(inv);
print_svec(outv);
:0: c b b ab aa a a


str_sort_ascend

#Usage

std::vector<std::string> str_sort_ascend(std::vector<std::string> &x, std::vector order_v = {
' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '[', '\\',
']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '{', '|', '}',
'~'

})

#Description

Returns a ascendly sorted vector of std::string. (according to ascii table order by default)

#Arguments

NameDefinition
x is the input vector
order_v is the order of each character (ascii table by default)

#Example(s)

std::vector<std::string> inv = {"b", "c", "a", "b", "a", "aa", "ab"};
std::vector<std::string> outv = str_sort_ascend(inv);
print_svec(outv);
:0: a a aa ab b b c


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
:25: 2 3 11 9
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"}


Merge strings of 2 vectors

merge_strv

#Usage

std::vector<std::string> merge_strv(std::vector<std::string> &x1, std::vector<std::string> &x2, std::string sep = "-")

#Description

Returns a vector of merged strings of the input vectors

#Arguments

NameDefinition
x1 is the first vector
x2 is the second vector

#Example(s)


std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};

std::vector<std::string> vec2 = {"lm", "lm", "O"};

std::vector<std::string> outv = merge_strv(vec, vec2);
print_svec(outv);

:0: lm-lm lm-lm mm-O lm-lm po-lm rr-O rr-lm po-lm


Occurence of elements in vectors

occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> occu(std::vector<T> &x)

#Description

Returns a map containing: the input vector of elements with unique elements, and their associated occurence in another vector (second in map)

#Arguments

NameDefinition
x is the input vector

#Example(s)

std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;
for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
lm 3
mm 1
po 2
rr 2


desc_occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> desc_occu(std::vector<T> vec, std::vector<unsigned int> freqv)

#Description

Returns a descendly sorted occu() output.

#Arguments

NameDefinition
vec is the vector of unique elements
freqv is the associated occurence of the elements

#Example(s)

std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;

std::cout << "######\n";

rtn_mp = desc_occu(uvec, freqv);
rtn_it = rtn_mp.begin();
uvec = rtn_it->first;
freqv = rtn_it->second;

for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
lm 3
po 2
rr 2
mm 1


asc_occu

#Usage

template <typename T> std::map<std::vector<T>, std::vector<unsigned int>> asc_occu(std::vector<T> vec, std::vector<unsigned int> freqv)

#Description

Returns a ascendly sorted out put of the occu() output.

#Arguments

NameDefinition
vec is the vector of unique elements
freqv is the associated occurence of the elements

#Example(s)


std::vector<std::string> vec = {"lm", "lm", "mm", "lm", "po", "rr", "rr", "po"};
std::map<std::vector<std::string>, std::vector<unsigned int>> rtn_mp = occu(vec);
std::map<std::vector<std::string>, std::vector<unsigned int>>::iterator rtn_it = rtn_mp.begin();
int i;
std::vector<std::string> uvec = rtn_it->first;
std::vector<unsigned int> freqv = rtn_it->second;
for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};

rtn_mp = asc_occu(uvec, freqv);
rtn_it = rtn_mp.begin();
uvec = rtn_it->first;
freqv = rtn_it->second;

for (i = 0; i < freqv.size(); ++i) {
std::cout << uvec[i] << " " << freqv[i] << "\n";
};
mm 1
po 2
rr 2
lm 3


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


The Dataframe Object

Dataframe

#Usage

Dataframe my_dataframe

#Description

Dataframe objects supporting reading csv, with custom separator, storing columns in differents type vectors, creating a new Dataframe object on top of an already existing one specifying the rows and columns to copy, the same goes for a matrix (as std::vector<std::vector<T>>) and std::vector<T>. See examples.

#Arguments

NameDefinition
See_below See below

#Example(s)

See below


Dataframe.readf

#Usage

void readf(std::string &file_name, char delim = ',', bool header_name = 1, char str_context_begin = '\'', char str_context_end = '\'')

#Description

Import a csv as a Dataframe object.

#Arguments

NameDefinition
file_name is the file_name of the csv to read
delim is the column delimiter
header_name is if the first row is in fact the column names
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context

#Example(s)

Dataframe obj1;
std::string file_name = "teste_dataframe.csv";
obj1.readf(file_name);


Dataframe.writef

#Usage

void writef(std::string &file_name, char delim = ',', bool header_name = 1, char str_context_bgn = '\'', char str_context_end = '\'')

#Description

Write a dataframe object into a csv file.

#Arguments

NameDefinition
file_name is the file name to write data into
delim is the column delimiter
header_name 1 to write the column names, 0 else
str_context_begin is the first symbol of a quote, (to not take in count a comma as a new column if it is in a quote for example)
str_context_end is the end symbol for a quote context

#Example(s)

// after reading teste_dataframe.csv as obj1
std::string out_file = "out.csv";
obj1.writef(out_file);


Dataframe.display

#Usage

void display();

#Description

Print the current dataframe.

#Arguments

NameDefinition
no no

#Example(s)

// after reading teste_dataframe.csv as obj1
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 aa 5 z
:1: 6 7 8 bb 10 e
:2: 1 2 3 cc 5 h
:3: 6 7 8 uu 10 a
:4: 1 2 3 s4 -5 q
:5: 6 7 8 s9 10 p
:6: 1 2 3 a4 5 j
:7: 6 7 8 m9 10 i
:8: 6 7 8 s9 10 p
:9: 1 2 3 a4 5 j
:10: 6 7 8 m9 10 i
:11: 6 7 8 m9 10 i
:12: 6 7 8 s9 10 p
:13: 1 2 3 a4 5 j
:14: 6 7 8 m9 10 i



Dataframe.idx_dataframe

#Usage

void idx_dataframe(std::vector<int> &rows, std::vector<int> &cols, Dataframe &cur_obj)

#Description

Allow to copy a dataframe choosing rows and columns (by index) of the copied dataframe.

#Arguments

NameDefinition
rows is the vector containing all the rows to copy ({-1}) for all
cols is the vector of the index of the columns to copy
cur_obj is the dataframe that will contain all the rows and columns of the copied dataframe

#Example(s)

// after reading teste_dataframe.csv as obj1
Dataframe obj2;
std::vector<int> idx_rows = {-1};
std::vector<int> idx_cols2 = {1, 2, 3};
obj2.idx_dataframe(idx_rows, idx_cols2, obj1);

obj2.display();
col1 col2 col3
:0: 2 3 aa
:1: 7 8 bb
:2: 2 3 cc
:3: 7 8 uu
:4: 2 3 s4
:5: 7 8 s9
:6: 2 3 a4
:7: 7 8 m9
:8: 7 8 s9
:9: 2 3 a4
:10: 7 8 m9
:11: 7 8 m9
:12: 7 8 s9
:13: 2 3 a4
:14: 7 8 m9


Dataframe.name_dataframe

#Usage

void name_dataframe(std::vector<int> &rows, std::vector<int> &name_cols, Dataframe &cur_obj)

#Description

Allow to copy a dataframe choosing rows and columns (by name) of the copied dataframe.

#Arguments

NameDefinition
rows is the vector containing all the rows to copy ({-1}) for all
cols is the vector of the name of the columns to copy
cur_obj is the dataframe that will contain all the rows and columns of the copied dataframe

#Example(s)

// after reading teste_dataframe.csv as obj1
Dataframe obj2;
std::vector<int> idx_rows = {-1};
std::vector<std::string> idx_cols2 = {"col2", "col3", "col3"};
obj2.name_dataframe(idx_rows, idx_cols2, obj1);

obj2.display();
col1 col2 col3
:0: 2 3 aa
:1: 7 8 bb
:2: 2 3 cc
:3: 7 8 uu
:4: 2 3 s4
:5: 7 8 s9
:6: 2 3 a4
:7: 7 8 m9
:8: 7 8 s9
:9: 2 3 a4
:10: 7 8 m9
:11: 7 8 m9
:12: 7 8 s9
:13: 2 3 a4
:14: 7 8 m9


Dataframe.idx_colint

#Usage

template <typename T> void idx_colint(std::vector<int> rows, unsigned int x, std::vector<T> &rtn_v)

#Description

Allow to copy a int, unsigned int , bool or double column as a vector<T>, by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the index of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<int> currows = {1, 0, 1};
std::vector<unsigned int> outv = {};
obj1.idx_colint(currows, 2, outv);
print_nvec(outv);
:0: 8 3 8


Dataframe.name_colint

#Usage

template <typename T> void name_colint(std::vector<int> rows, std::string colname, std::vector<T> &rtn_v)

#Description

Allow to copy a int, unsigned int , bool or double column as a vector<T>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the name of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<int> currows = {1, 0, 1};
std::vector<unsigned int> outv = {};
obj1.idx_colint(currows, "col2", outv);
print_nvec(outv);
:0: 8 3 8


Dataframe.idx_colstr

#Usage

void idx_colstr(std::vector<int> rows, unsigned int x, std::vector<std::string> &rtn_v)

#Description

Allow to copy a std::string column as a vector<std::string>, by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the index of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> outv2 = {};
obj1.idx_colstr(currows, 3, outv2);
print_svec(outv2);
:0: bb aa bb


Dataframe.name_colstr

#Usage

template <typename T> void name_colint(std::vector<int> rows, std::string colname, std::vector<T> &rtn_v)

#Description

Allow to copy a int, unsigned int , bool or double column as a vector<std::string>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the name of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> outv2 = {};
obj1.name_colstr(currows, "col4", outv2);
print_svec(outv2);
:0: bb aa bb


Dataframe.idx_colchr

#Usage

void idx_colchr(std::vector<int> rows, unsigned int x, std::vector<char> &rtn_v)

#Description

Allow to copy a char column as a vector<char>, by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the index of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<char> outv3 = {};
obj1.idx_colchr(currows, 5, outv3);
for (char i : outv3) {
std::cout << i << " ";
};
std::cout << "\n";
e z e


Dataframe.name_colchr

#Usage

void name_colchr(std::vector<int> rows, std::string colname, std::vector<char> &rtn_v)

#Description

Allow to copy a char column as a vector<char>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x is the name of the column to copy
rtn_v is the vector that will contain the column to copy

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<char> outv3 = {};
obj1.name_colchr(currows, "col6", outv3);
for (char i : outv3) {
std::cout << i << " ";
};
std::cout << "\n";
e z e


Dataframe.idx_matrint

#Usage

template <typename T> void idx_matrint(std::vector<int> rows, std::vector<unsigned int> x_v, std::vector<std::vector<T>> &rtn_matr)

#Description

Allow to copy a set of columns that are same type (int, unsigned int, bool or double) as a std::vector<std::vector<T>> , by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ( {-1} ) for all
x_v is the vector containing the indices of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::vector<unsigned int>> out_matr = {};
std::vector<unsigned int> idx_cols = {1, 0, 2, 2};
obj1.idx_matrint(currows, idx_cols, out_matr);
print_nmatr(out_matr);
[0] [1] [2] [3]
:0: 7 6 8 8
:1: 2 1 3 3
:2: 7 6 8 8


Dataframe.name_matrint

#Usage

template <typename T> void name_matrint(std::vector<int> rows, std::vector<std::string> x_v, std::vector<std::vector<T>> &rtn_matr)

#Description

Allow to copy a set of columns that are same type (int, unsigned int, bool or double) as a std::vector<std::vector<T>>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x_v is the vector containing the names of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::vector<unsigned int>> out_matr = {};
std::vector<std::string> idx_vec2 = {"col1", "col2", "col3"};
obj1.name_matrint(currows, idx_vec2, out_matr);
print_nmatr(out_matr);
[0] [1] [2]
:0: 6 7 8
:1: 1 2 3
:2: 6 7 8


Dataframe.idx_matrstr

#Usage

void idx_matrstr(std::vector<int> rows, std::vector<unsigned int> x_v, std::vector<std::vector<std::string>> &rtn_matr)

#Description

Allow to copy a set of columns that are std::string type as a std::vector<std::vector<std::string>>, by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x_v is the vector containing the indices of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::vector<std::string>> out_matr2 = {};
std::vector<unsigned int> idx_cols = {3};
obj1.idx_matrstr(currows, idx_cols, out_matr2);
print_smatr(out_matr2);
[0]
:0: bb
:1: aa
:2: bb


Dataframe.name_matrstr

#Usage

void name_matrstr(std::vector<int> rows, std::vector<std::string> x_v, std::vector<std::vector<std::string>> &rtn_matr)

#Description

Allow to copy a set of columns that are std::string type as a std::vector<std::vector<std::string>>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x_v is the vector containing the names of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::vector<std::string>> out_matr2 = {};
std::vector<std::string> idx_vec2 = {"col4"};
obj1.name_matrstr(currows, idx_vec2, out_matr2);
print_smatr(out_matr2);
[0]
:0: bb
:1: aa
:2: bb


Dataframe.idx_matrchr

#Usage

void idx_matrchr(std::vector<int> rows, std::vector<unsigned int> x_v, std::vector<std::vector<char>> &rtn_matr)

#Description

Allow to copy a set of columns that are char type as a std::vector<std::vector<char>>, by column index.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x_v is the vector containing the indices of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::vector<char>> out_matr3 = {};
std::vector<unsigned int> idx_cols = {5};
obj1.idx_matrchr(currows, idx_cols, out_matr3);
print_smatr(out_matr3);
[0]
:0: e
:1: z
:2: e


Dataframe.name_matrchr

#Usage

void name_matrchr(std::vector<int> rows, std::vector<std::string> x_v, std::vector<std::vector<char>> &rtn_matr)

#Description

Allow to copy a set of columns that are char type as a std::vector<std::vector<char>>, by column name.

#Arguments

NameDefinition
rows is a vector containing the row indices to copy ({-1}) for all
x_v is the vector containing the names of the column to copy
rtn_matr is the matrix that will contain all the columns copyed

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<char> out_matr3 = {};
std::vector<std::string> idx_vec2 = {"col6"};
obj1.name_matrchr(currows, idx_vec2, out_matr3);
print_smatr(out_matr3);
[0]
:0: e
:1: z
:2: e


Dataframe.get_nrow

#Usage

unsigned int get_nrow();

#Description

Returns the number of rows for the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int nrow = obj1.get_nrow();
15


Dataframe.get_ncol

#Usage

unsigned int get_ncol();

Returns the number of columns for the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
unsigned int ncol = obj1.get_ncol();
6


Dataframe.get_rowname

#Usage

std::vector<std::string> get_rowname();

Returns the rowname of the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> row_names = obj1.get_rowname();
nothing becuase obj1 has no rownames


Dataframe.get_colname

#Usage

std::vector<std::string> get_colname();

Returns the colname of the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> col_names = obj1.get_colname();
col1 col2 col3 col4 col5 col6


Dataframe.set_rowname

#Usage

void set_rowname(std::vector<std::string> &x);

Set rowname to the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> row_names = {"n1", "n2", "n3"..."n15"};
obj1.set_rowname(row_names);


Dataframe.set_colname

#Usage

void set_colname(std::vector<std::string> &x);

Set colname to the associated dataframe.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<std::string> col_names = {"col1", "col2", "col3", "col4",
"col5", "col6"};
obj1.set_colname();


Dataframe.replace_colint

#Usage

template <typename T> void replace_colint(std::vector<T> &x, unsigned int &colnb)

Replace a int, unsigned int, bool or double column of the associated dataframe.

#Arguments

NameDefinition
x is the column (as vector) that will replace the dataframe column
colnb is the index of the column to replace

#Example(s)

// after reading teste_dataframe.csv as obj1

std::vector<unsigned int> rpl_col = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14};
unsigned int col = 0;
obj1.replace_colint(rpl_col, col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 0 2 3 aa 5 z
:1: 1 7 8 bb 10 e
:2: 2 2 3 cc 5 h
:3: 3 7 8 uu 10 a
:4: 4 2 3 s4 -5 q
:5: 5 7 8 s9 10 p
:6: 6 2 3 a4 5 j
:7: 7 7 8 m9 10 i
:8: 8 7 8 s9 10 p
:9: 9 2 3 a4 5 j
:10: 10 7 8 m9 10 i
:11: 11 7 8 m9 10 i
:12: 12 7 8 s9 10 p
:13: 13 2 3 NA 5 j
:14: 14 7 8 m9 10 i


Dataframe.replace_colstr

#Usage

void replace_colstr(std::vector<std::string> &x, unsigned int &colnb)

#Description

Replace a string column of the associated dataframe.

#Arguments

NameDefinition
x is the column (as vector) that will replace the dataframe column
colnb is the index of the column to replace

#Example(s)

// after reading teste_dataframe.csv as obj1

std::vector<std::string> rpl_col = {"0", "1", "2", "3", "4", "5", "6",
"7", "8", "9",
"10", "11", "12", "13", "14"};
unsigned int col = 3;
obj1.replace_colstr(rpl_col, col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 0 5 z
:1: 6 7 8 1 10 e
:2: 1 2 3 2 5 h
:3: 6 7 8 3 10 a
:4: 1 2 3 4 -5 q
:5: 6 7 8 5 10 p
:6: 1 2 3 6 5 j
:7: 6 7 8 7 10 i
:8: 6 7 8 8 10 p
:9: 1 2 3 9 5 j
:10: 6 7 8 10 10 i
:11: 6 7 8 11 10 i
:12: 6 7 8 12 10 p
:13: 1 2 3 13 5 j
:14: 6 7 8 14 10 i


Dataframe.replace_colchr

#Usage

void replace_colchr(std::vector<char> &x, unsigned int &colnb)

#Description

Replace a string column of the associated dataframe.

#Arguments

NameDefinition
x is the column (as vector) that will replace the dataframe column
colnb is the index of the column to replace

#Example(s)

// after reading teste_dataframe.csv as obj1

std::vector<char> rpl_col = {'c', 'c', 'c', 'c', 'c', 'c', 'c',
'c', 'c', 'c',
'b', 'b', 'v', 'v', 'v'};
unsigned int col = 5;
obj1.replace_colchr(rpl_col, col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 aa 5 c
:1: 6 7 8 bb 10 c
:2: 1 2 3 cc 5 c
:3: 6 7 8 uu 10 c
:4: 1 2 3 s4 -5 c
:5: 6 7 8 s9 10 c
:6: 1 2 3 a4 5 c
:7: 6 7 8 m9 10 c
:8: 6 7 8 s9 10 c
:9: 1 2 3 a4 5 c
:10: 6 7 8 m9 10 b
:11: 6 7 8 m9 10 b
:12: 6 7 8 s9 10 v
:13: 1 2 3 NA 5 v
:14: 6 7 8 m9 10 v


Dataframe.add_colint

#Usage

template <typename T> void add_colint(std::vector<T> &x, std::string name = "NA")

#Description

Add a column int, unsigned int, bool or double type to the associated dataframe

#Arguments

NameDefinition
x is the column to add
name is the column to add name

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> rpl_col = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14};
obj1.add_colint(rpl_col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char> <uint>
col1 col2 col3 col4 col5 col6 NA
:0: 1 2 3 aa 5 z 0
:1: 6 7 8 bb 10 e 1
:2: 1 2 3 cc 5 h 2
:3: 6 7 8 uu 10 a 3
:4: 1 2 3 s4 -5 q 4
:5: 6 7 8 s9 10 p 5
:6: 1 2 3 a4 5 j 6
:7: 6 7 8 m9 10 i 7
:8: 6 7 8 s9 10 p 8
:9: 1 2 3 a4 5 j 9
:10: 6 7 8 m9 10 i 10
:11: 6 7 8 m9 10 i 11
:12: 6 7 8 s9 10 p 12
:13: 1 2 3 NA 5 j 13
:14: 6 7 8 m9 10 i 14


Dataframe.add_colstr

#Usage

void add_colstr(std::vector<std::string> &x, std::string name = "NA")

#Description

Add a column string type to the associated dataframe.

#Arguments

NameDefinition
x is the column to add
name is the column to add name

#Example(s)

// after reading teste_dataframe.csv as obj1

std::vector<std::string> rpl_col = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14"};
obj1.add_colstr(rpl_col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char> <str>
col1 col2 col3 col4 col5 col6 NA
:0: 1 2 3 aa 5 z 0
:1: 6 7 8 bb 10 e 1
:2: 1 2 3 cc 5 h 2
:3: 6 7 8 uu 10 a 3
:4: 1 2 3 s4 -5 q 4
:5: 6 7 8 s9 10 p 5
:6: 1 2 3 a4 5 j 6
:7: 6 7 8 m9 10 i 7
:8: 6 7 8 s9 10 p 8
:9: 1 2 3 a4 5 j 9
:10: 6 7 8 m9 10 i 10
:11: 6 7 8 m9 10 i 11
:12: 6 7 8 s9 10 p 12
:13: 1 2 3 NA 5 j 13
:14: 6 7 8 m9 10 i 14


Dataframe.add_colchr

#Usage

add_colchr(std::vector<char> &x, std::string name = "NA")

#Description

Add a column char type to the associated dataframe.

#Arguments

NameDefinition
x is the column to add
name is the column to add name

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<char> rpl_col = {'c', 'c', 'c', 'c', 'c', 'c', 'c',
'c', 'c', 'c',
'b', 'b', 'v', 'v', 'v'};
obj1.add_colchr(rpl_col);
obj1.display();
<uint> <uint> <uint> <str> <int> <char> <char>
col1 col2 col3 col4 col5 col6 NA
:0: 1 2 3 aa 5 z c
:1: 6 7 8 bb 10 e c
:2: 1 2 3 cc 5 h c
:3: 6 7 8 uu 10 a c
:4: 1 2 3 s4 -5 q c
:5: 6 7 8 s9 10 p c
:6: 1 2 3 a4 5 j c
:7: 6 7 8 m9 10 i c
:8: 6 7 8 s9 10 p c
:9: 1 2 3 a4 5 j c
:10: 6 7 8 m9 10 i b
:11: 6 7 8 m9 10 i b
:12: 6 7 8 s9 10 p v
:13: 1 2 3 NA 5 j v
:14: 6 7 8 m9 10 i v


Dataframe.rm_col

#Usage

void rm_col(std::vector<unsigned int> &nbcolv)

#Description

Removes columns from associated dataframe.

#Arguments

NameDefinition
nbcolv is a vector containing all the indices of the columns to erase from the associated dataframe. The indices must be sorted descendly.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> colv = {4, 1};
obj1.rm_col(colv);
obj1.display();
<uint> <uint> <str> <char>
col1 col3 col4 col6
:0: 1 3 aa z
:1: 6 8 bb e
:2: 1 3 cc h
:3: 6 8 uu a
:4: 1 3 s4 q
:5: 6 8 s9 p
:6: 1 3 a4 j
:7: 6 8 m9 i
:8: 6 8 s9 p
:9: 1 3 a4 j
:10: 6 8 m9 i
:11: 6 8 m9 i
:12: 6 8 s9 p
:13: 1 3 NA j
:14: 6 8 m9 i


Dataframe.rm_row

#Usage

void rm_col(std::vector<unsigned int> &nbcolv)

#Description

Removes rows from associated dataframe.

#Arguments

NameDefinition
nbcolv is a vector containing all the indices of the rows to erase from the associated dataframe. The indices must be sorted descendly.

#Example(s)

// after reading teste_dataframe.csv as obj1
std::vector<unsigned int> rowv = {4, 1};
obj1.rm_row(rowv);
obj1.display();
<uint> <uint> <uint> <str> <int> <char>
col1 col2 col3 col4 col5 col6
:0: 1 2 3 aa 5 z
:1: 1 2 3 cc 5 h
:2: 6 7 8 uu 10 a
:3: 6 7 8 s9 10 p
:4: 1 2 3 a4 5 j
:5: 6 7 8 m9 10 i
:6: 6 7 8 s9 10 p
:7: 1 2 3 a4 5 j
:8: 6 7 8 m9 10 i
:9: 6 7 8 m9 10 i
:10: 6 7 8 s9 10 p
:11: 1 2 3 NA 5 j
:12: 6 7 8 m9 10 i


Dataframe.transform_inner

#Usage

void transform_inner(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies a inner join on the associated dataframe.

#Arguments

NameDefinition
cur_obj is the other dataframe used for inner join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the inner join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_inner(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
:0: id1 1
:1: id2 6
:2: id4 6
:3: id5 1
:4: id6 6
:5: id7 1
:6: id8 6
:7: id9 6
:8: id11 6
:9: id12 6
:10: id14 1
:11: id15 6


Dataframe.transform_excluding

#Usage

void transform_excluding(Dataframe &cur_obj, unsigned int &in_col, unsigned int &ext_col)

#Description

Applies a excluding join on the associated dataframe.

#Arguments

NameDefinition
cur_obj is the other dataframe used for the excluding join
in_col is the index of the column representing the key (primary) of the associated dataframe
ext_col is the index of the column representing the key (foreign) of the other dataframe used for the excluding join

#Example(s)


Dataframe obj1, obj2;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj1.transform_excluding(obj2, col1, col2);
obj1.display();
<str> <uint>
col1 col2
:0: id3 1
:1: id10 1
:2: id13 6


Dataframe.merge_inner

#Usage

void merge_inner(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a inner join on a newly created dataframe.

#Arguments

NameDefinition
obj1 is the first dataframe
obj2 is the second dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the first dataframe column as primary key
key1 is the index of the first dataframe column as foreign key

#Example(s)


Dataframe obj1, obj2, obj3;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_inner(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <str> <uint> <uint>

:0: id1 1 id1 2 3
:1: id2 6 id2 7 8
:2: id4 6 id4 7 8
:3: id5 1 id5 2 3
:4: id6 6 id6 7 8
:5: id7 1 id7 2 3
:6: id8 6 id8 2 3
:7: id9 6 id9 7 8
:8: id11 6 id11 7 8
:9: id12 6 id12 7 8
:10: id14 1 id14 7 8
:11: id15 6 id15 2 3


Dataframe.merge_excluding

#Usage

void merge_excluding(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a left excluding join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_excluding(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <str> <uint> <uint>

:0: id3 1 NA NA NA
:1: id10 1 NA NA NA
:2: id13 6 NA NA NA


Dataframe.merge_excluding_both

#Usage

void merge_excluding_both(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a full excluding join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_excluding_both(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <str> <uint> <uint>

:0: id3 1 NA NA NA
:1: id10 1 NA NA NA
:2: id13 6 NA NA NA
:3: NA NA id119 7 8


Dataframe.merge_all

#Usage

void merge_all(Dataframe &obj1, Dataframe &obj2, bool colname, unsigned int &key1, unsigned int &key2)

#Description

Performs a full join to the associated dataframe (newly created). The first dataframe as argument is considered as the left one.

#Arguments

NameDefinition
obj1 is the left dataframe
obj2 is the right dataframe
colname 1 to give the column names to the newly created dataframe
key1 is the index of the column of the left dataframe
key2 is the index of the column of the right dataframe

#Example(s)

Dataframe obj1, obj2, obj3;
std::string filename = "outb.csv";
obj1.readf(filename);

std::vector<unsigned int> colv = {4, 3, 2};
obj1.rm_col(colv);

std::string f2 = "outb2.csv";
obj2.readf(f2);

unsigned int col1 = 0;
unsigned int col2 = 0;

obj3.merge_all(obj1, obj2, 1, col1, col2);
obj3.display();
<str> <uint> <str> <uint> <uint>

:0: id3 1 NA NA NA
:1: id10 1 NA NA NA
:2: id13 6 NA NA NA
:3: NA NA id119 7 8
:4: id1 1 id1 2 3
:5: id2 6 id2 7 8
:6: id4 6 id4 7 8
:7: id5 1 id5 2 3
:8: id6 6 id6 7 8
:9: id7 1 id7 2 3
:10: id8 6 id8 2 3
:11: id9 6 id9 7 8
:12: id11 6 id11 7 8
:13: id12 6 id12 7 8
:14: id14 1 id14 7 8
:15: id15 6 id15 2 3


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

Read matrix from file

read_matr

#Usage

template <typename T> void read_matr(std::string &file_name, std::vector<std::vector<T>> &out_matr, char delim = ',')

#Description

Returns a matrix stored in a file.

#Arguments

NameDefinition
file_name is the name of the file
out_matr is a declared matrix
delim is the column delimiter

#Example(s)

std::string teste_file = "teste.csv";
std::vector<std::vector<double>> out_matr;
read_matr(teste_file, out_matr);
print_matr(out_matr);

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


write_matr

#Usage

template <typename T> void write_matr(std::string &file_name, std::vector<std::vector<T>> &in_matr, char delim = ',')

#Description

Writes a matrix into a file.

#Arguments

NameDefinition
file_name is the name of the file
in_matr is the input matrix
delim is the chosen column delimiter

#Example(s)


std::string teste_file = "teste2.csv";
std::vector<std::vector<int>> in_matr = {
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
};

write_matr(teste_file, in_matr);


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

#Usage

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

#Description

Print a matrix (float, int, double...) as 2D stl vector.

#Arguments

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

#Example(s)


std::vector<std::vector<int>> out_matr = {
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 333, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
};
print_nmatr(out_matr);

[0] [1] [2] [3] [4]
:0: 1 1 1 1 1
:1: 2 2 2 2 2
:2: 3 3 333 3 3
:3: 4 4 4 4 4




std::vector<std::vector<double>> out_matr2 = {
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 333.23, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
};
print_nmatr(out_matr2);

[0] [1] [2] [3] [4]
:0: 1 1 1 1 1
:1: 2 2 2 2 2
:2: 3 3 333.23 3 3
:3: 4 4 4 4 4




#Usage

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

#Description

Print a matrix (std::string, char) as 2D stl vector.

#Arguments

NameDefinition
x is a 2D stl vector (stdstring, char)

#Example(s)

std::vector<std::vector<std::string>> out_matr3 = {
{"1", "2", "3", "4"},
{"1", "2", "3", "4"},
{"1", "2", "333", "44224441111111"},
{"1", "2", "3", "4"},
{"1", "2", "3", "4"}
};
print_smatr(out_matr3);

[0] [1] [2] [3] [4]
:0: 1 1 1 1 1
:1: 2 2 2 2 2
:2: 3 3 333 3 3
:3: 4 4 44224441111111 4 4




std::vector<std::vector<char>> out_matr4 = {
{'1', '2', '3', '4'},
{'1', '2', '3', '4'},
{'1', '2', '3', '4'},
{'1', '2', '3', '4'},
{'1', '2', '3', '4'}
};

print_smatr(out_matr4);

[0] [1] [2] [3] [4]
:0: 1 1 1 1 1
:1: 2 2 2 2 2
:2: 3 3 3 3 3
:3: 4 4 4 4 4




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


Determinant

det_small

#Usage

template <typename T> double det_small(std::vector<std::vector<T>> &inpt_matr)

#Description

Calculates matrix determinant up to 5x5.

#Arguments

NameDefinition
impt_matr is the input matrix

#Example(s)


std::vector<std::vector<int>> inpt_matr = {
{81, 55, 1, 81, 40},
{42, 48, 41, 37, 5},
{84, 1, 61, 612, 6},
{52, 59, 23, 50, 22},
{39, 6, 95, 69, 23},
};
int out_val = det_small(inpt_matr);
std::cout << out_val << "\n";
1473982232


Apply any function on indefinite numbers of same type vectors

Fapply object

#Usage

Fapply

#Description

Allows to perform any function on a set of same type vectors, simplified

#Arguments

NameDefinition
... all the vectors

#Example(s)

// declare a custom function

int add(std::vector<int> x) {
int rtn_v = x[0];
for (int i = 1; i < x.size(); ++i) {
rtn_v += x[i];
};
return rtn_v;
};

std::vector<int> inpt_v1 = {1, 2, 3, 4, 5, 6, 7};
std::vector<int> inpt_v2 = {7, 6, 5, 4, 3, 2, 1};

Fapply obj1(inpt_v1); //initialise object with a vector argument
obj1.set_args(inpt_v1, inpt_v2, inpt_v2); //ingest args

//performs the chosen function
std::vector<int> outv = obj1.fapply(merge_str);

print_nvec(outv);

:0: 15 14 13 12 11 10 9


Fapply2d object

#Usage

Fapply(std::vector<TB> &x)

#Description

Apllies any function onto a variadic numbers of vectors of any type

#Arguments

NameDefinition
x is an empty vector of the type choosen for the operations between vectors

#Example(s)

std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

std::vector<int> iinv = {};

Fapply2d obj1(iinv);


Fapply2d.set_args

#Usage

template <typename T, typename ...T2> void set_args(std::vector<T> &x, std::vector<T2>&... x2)

#Description

Is a variadic function allowing to put in the class an indefinite number of vectors of the same type that will be used by your custom function later, see Fapply2d.fapply2d()

#Arguments

NameDefinition
... is some same types vectors

#Example(s)


std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

obj1.set_args(xint, xint, xint2);


Fapply2d.fapply2d

#Usage

template <typename T> std::vector<T> fapply2d(std::vector<T> (&f)(std::vector<std::vector<T>>))

#Description

Performs your custom function on the std::vector> created by Fapply2d.set_args().

#Arguments

NameDefinition
f is the reference to the custom function

#Example(s)


std::vector<int> addv(std::vector<std::vector<int>> x) {
std::vector<int> rtn_v = {};
int cur_val;
unsigned int i2;
const unsigned int n = x[0].size();
const unsigned int n2 = x.size();
for (int i = 0; i < n; ++i) {
cur_val = 0;
for (i2 = 0; i2 < n2; ++i2) {
cur_val += x[i2][i];
};
rtn_v.push_back(cur_val);
};
return rtn_v;
};

std::vector<int> xint = {0, 1, 2};
std::vector<int> xint2 = {0, 1, 2};

std::vector<int> iinv = {};

Fapply2d obj1(iinv);
obj1.set_args(xint, xint, xint2);
iinv = obj1.fapply2d(addv);
print_nvec(outv);
:0: 0 3 6


Fapply2d.reinitiate

#Usage

void reinitiate();

#Description

Empties the 2d T internal vector. Necessary to reset args (vectors input of the internal 2d vector) of same type before applying the function (or another) to new vectors.

#Arguments

NameDefinition
no no

#Example(s)

Fapply2d.reinitiate();


Geographical coordinates manipulation

geo_min

#Usage

double geo_min(double &lat1, double &longit1, double &lat2, double &longit2, const double sphere_ray = 6378)

#Description

Returns the shortest distance between 2 geographical points.

#Arguments

NameDefinition
lat1 is the lattitude of the first point
longit1 is the longitude of the second point
lat2 is the lattitude of the second point
longit2 is the longitude of the second point
sphere_ray is the rayon of the sphere in km (defaults to Earth)

#Example(s)

double lat1 = 23;
double longit1 = -45;

double lat2 = -23;
double longit2 = 45;

double delta = geo_min(lat1, longit1, lat2, longit2);

std::cout << delta << "\n";

lat1 = 60;
longit1 = 30;

lat2 = 60;
longit2 = -150;

delta = geo_min(lat1, longit1, lat2, longit2);

std::cout << delta << "\n";
6679.1


Date manipulation (Gregorian)

Format convertions

fr_to_eng_datefmt

#Usage

std::string fr_to_eng_datefmt(std::string &x, char sep = '-')

#Description

Converts a french date format to an english one.

#Arguments

NameDefinition
x is the input date
sep is the date separator

#Example(s)

std::string fr_date = "02-07-2022";
std::string eng_date = fr_to_eng_datefmt(fr_date);
std::cout << eng_date<< "\n";
07-02-2022


eng_to_fr_datefmt

#Usage

std::string eng_to_fr_datefmt(std::string &x, char sep = '-')

#Description

Converts a english date format to an french one.

#Arguments

NameDefinition
x is the input date
sep is the date separator

#Example(s)

std::string eng_date = "07-02-2022";
std::string fr_date = eng_to_fr_datefmt(eng_date);
std::cout << fr_date << "\n";
02-07-2022


fmt_converter_date

#Usage

std::string fmt_converter_date(std::string &x, std::string &in_fmt, std::string &out_fmt, char delim = '-')

#Description

Cpnverts a date to another date format.

#Arguments

NameDefinition
x is the input date
in_fmt is the input date format
out_fmt is the output date format

#Example(s)

std::string in_fmt = "dmy";
std::string out_fmt = "mdy";
std::string inpt_date = "02-07-2003";
std::string outfmtdate = fmt_converter_date(inpt_date, in_fmt, out_fmt);
std::cout << outfmtdate << "\n";
07-02-2003


Sort dates

ascend_sort_date

#Usage

std::vector<std::string> ascend_sort_date(std::vector<std::string> &x,
std::string &fmt, char delim = '-')

#Description

Returns a vector of date ascendly sorted. The format meaning is 'y' for year, 'm' for month, 'd' for day, 'h' for hour, 'n' for minute and 's' for second.

#Arguments

NameDefinition
x is the input vector of dates
fmt is the date format
delim is the date delimiter

#Example(s)

std::vector<std::string> vec = {
"02-04-2026",
"02-11-2023",
"07-02-2026",
"22-04-2016",
"02-12-2006",
"17-9-2015",
"03-04-2017",
"02-05-2017",
"15-01-2026"
};

std::string fmt = "dmy";

std::vector<std::string> outv = ascend_sort_date(vec, fmt);
print_svec(outv);
:0: 02-12-2006 17-9-2015 22-04-2016 03-04-2017 02-05-2017 02-11-2023 15-01-2026 07-02-2026
:8: 02-04-2026


descend_sort_date

#Usage

std::vector<std::string> descend_sort_date(std::vector<std::string> &x,
std::string &fmt, char delim = '-')

#Description

Returns a vector of date descendly sorted. The format meaning is 'y' for year, 'm' for month, 'd' for day, 'h' for hour, 'n' for minute and 's' for second.

#Arguments

NameDefinition
x is the input vector of dates
fmt is the date format
delim is the date delimiter

#Example(s)

std::vector<std::string> vec = {
"02-04-2026",
"02-11-2023",
"07-02-2026",
"22-04-2016",
"02-12-2006",
"17-9-2015",
"03-04-2017",
"02-05-2017",
"15-01-2026"
};

std::string fmt = "dmy";

std::vector<std::string> outv = descend_sort_date(vec, fmt);
print_svec(outv);
:0: 02-04-2026 07-02-2026 15-01-2026 02-11-2023 02-05-2017 03-04-2017 22-04-2016 17-9-2015
:8: 02-12-2006


is_leap

#Usage

template <typename T> bool is_leap(unsigned T &x)

#Description

Returns if the input year is leap.

#Arguments

NameDefinition
x is the input year

#Example(s)

int year = 2024;
bool bsx = is_leap(year);
std::cout << bsx << "\n";
1


delta_second

#Usage

double delta_second(std::string &bgn_date, std::string &end_date, int ref_year = 0, char delim = '-')

#Description

Returns the number of second elapsed between 2 dates.

#Arguments

NameDefinition
bgn_date is the first date, must be lower than the second date
end_date is the second date
ref_year is a reference year from which the time elapsed wil be calculated. This value must be lower than the year of the first date
delim is the date delimiter

#Example(s)

std::string bgn_date = "2003-07-02-2-23-46";
std::string end_date = "2025-04-01-12-13-26";
double delta = delta_second(bgn_date, end_date);
std::cout << delta << "\n";
6.86311e+08


is_greater_date

#Usage

bool is_greater_date(std::string &x, std::string &x2, char delim = '-')

#Description

Returns if the first date is greater than the second one. The dates must have the same format, which is the highest time unit at the beginning and so on.

#Arguments

NameDefinition
x is the first date
x2 is the second date
delim is the date delimiter

#Example(s)

std::string bgn_date = "2003-07-02-2-23-46";
std::string end_date = "2025-04-01-12-13-26";
bool outbool = is_greater_date(end_date, bgn_date);
std::cout << outbool << "\n";
1


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_intricated

#Usage

bool is_intricated (unsigned int &idx, std::vector<unsigned int> &tkn_v)

#Description

Returns a boolean, 1 if the parenthesis refered is intricated in others parenthesis, 0 if not. See examples.

#Arguments

NameDefinition
tkn_v is a std vector containing all the parenthesis pairs. The one outputed by Parser_tokennizer_full function.
idx is an unsigned int that indicates the parenthesis refered in tkn_v vector

#Example(s)

std::string inpt_str = "(ldkhf(f)ek(()))dkjf(gf())()()";
std::vector<std::vector<unsigned int>> out_matr = Parser_tokenizer_full(inpt_str);
std::vector<unsigned int> tkn_v = out_matr[0];
std::vector<unsigned int> idx_v = out_matr[1];
unsigned int i;
for (i = 0; i < tkn_v.size(); ++i) {
std::cout << tkn_v[i] << " ";
};
std::cout << "\n";
for (i = 0; i < tkn_v.size(); ++i) {
std::cout << idx_v[i] << " ";
};
3 0 0 2 1 1 2 3 5 4 4 5 6 6 7 7
0 6 8 11 12 13 14 15 20 23 24 25 26 27 28 29
std::cout << "\n";
unsigned int cur_idx = 15;
bool is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
0
cur_idx = 3;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
1
cur_idx = 7;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
0
cur_idx = 6;
is_it = is_intricated(cur_idx, tkn_v);
std::cout << is_it << "\n";
1


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<bool> 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


Unique string from int

letter_to_nb

#Usage

unsigned int letter_to_nb(std::string &x)

#Description

Returns an int corresponding to the input letter.

This algorithm can be used to get which unique id number it is, if we know that it has been generated with nb_to_letter function

#Arguments

NameDefinition
x is the input string

#Example(s)

std::string inpt_str = "ecfy";
unsigned int rtn_val = letter_to_nb(inpt_str);
std::cout << rtn_val << "\n";
90089

inpt_str = "ajf";
rtn_val = letter_to_nb(inpt_str);
std::cout << rtn_val << "\n";

942


nb_to_letter

#Usage

std::string nb_to_letter(unsigned int &x)

#Description

Returns a unique combination of letters based on an input number, see examples.

#Arguments

NameDefinition
x is the input number

#Example(s)

unsigned int inpt_val = 702;
std::string out_val = nb_to_letter(inpt_val);
std::cout << out_val << "\n";

"zz"

unsigned int inpt_val = 104601;
std::string out_val = nb_to_letter(inpt_val);
std::cout << out_val << "\n";

"exsc"