31 T
min(std::vector<T> &
set){
33 for(
long i=
set.size()-1;i>0;i--){
34 if (
set[i]<min){ min=
set[i];}
40 T
max(std::vector<T> &
set){
42 for(
long i=
set.size()-1;i>0;i--){
43 if (
set[i]>max){ max=
set[i];}
52 T delta=(maxi-mini+1)/N_bins;
53 std::vector<T> bin (N_bins,0);
54 for(
int i=
set.size()-1;i>=0;i--){
55 T value=floor((
set[i]-mini)/delta);
56 bin(value)=bin(value)+1/(
set.size()*delta);
62 T
smooth_histogram (std::vector<T> histo,
int intervals,
int window_size,
int iterations){
63 std::vector<T> s_histo=histo;
64 for (
int i=1;i<=iterations;i++){
65 for (
int b=0;b<=intervals-window_size;b++){
66 int c=b+floor((window_size-1)/2);
68 for (
int j=b;j<=b+window_size-1;i++){
69 s_histo[c]=s_histo[c]+histo[j]/window_size;
72 for (
int b=0;b<=((window_size-1)/2)-1;b++){
73 s_histo=s_histo[floor((window_size-1)/2)];
75 for (
int b=intervals-window_size+1+floor((window_size-1)/2); b<=intervals-1;i++){
76 s_histo[b]=s_histo[intervals-window_size+floor((window_size-1) / 2)];
81 for (
int b=0;b<=intervals-1;b++){
84 for (
int b=0;b<=intervals-1;b++){
92 for(
size_t i=0;i<
set.size();i++){
93 entropy+=
set[i]*(log(
set[i])/log(2));
98 float rel_entropy (std::vector<float> &
set, std::vector<float> &set2){
100 if (
set.size()!=set2.size()){
101 std::cerr <<
"Distributions aren't the same size";
104 for(
size_t i=0;i<
set.size();i++){
105 rel_entropy+=0.5*(
set[i]* (log (
set[i]/set2[i]) /log(2) )+set2[i]*(log(set2[i]/
set[i])/log(2)));
116 double _integrate (
double (*funct)(
double, std::vector<double>),
double upper,
double lower,std::vector<double> param){
117 double mid=(lower+upper)/2.0;
118 double h3=fabs(upper-lower)/6.0;
119 return h3*(funct(lower,param)+4*funct(mid,param)+funct(upper,param));
122 double integrate (
double (*funct)(
double,std::vector<double>),
double lower,
double upper ,std::vector<double> param,
double max_error=0.001,
double sum=0){
123 double mid=(upper+lower)/2.0;
124 double left=
_integrate(funct,lower, mid, param);
125 double right=
_integrate(funct,mid,upper, param);
126 if (fabs(left+right-sum)<=15*max_error){
127 return left+right +(left+right-sum)/15;
129 return integrate(funct,lower,mid,param,max_error/2,left) +
integrate(funct,mid,upper,param,max_error/2,right);
135 double simpson (
double (*funct)(
double,
double,
double),
double alpha,
double beta,
double lower,
double upper){
136 double mid=(lower+upper)/2.0;
137 double h3=fabs(upper-lower)/6.0;
138 return h3*(funct(lower,alpha,beta)+4*funct(mid,alpha,beta)+funct(upper,alpha,beta));
141 double adapt_simpson (
double (*funct)(
double,
double,
double),
double alpha,
double beta,
double lower,
double upper,
double max_error,
double sum){
142 double mid=(upper+lower)/2.0;
143 double left=
simpson(funct,alpha,beta,lower, mid);
145 double right=
simpson(funct,alpha,beta,mid,upper);
146 if (fabs(left+right-sum)<=15*max_error){
147 return left+right +(left+right-sum)/15;
149 return adapt_simpson(funct,alpha,beta,lower,mid,max_error/2,left) +
adapt_simpson(funct,alpha,beta,mid,upper,max_error/2,right);
167 else if (position>=b){
171 return (
float)(position-a+1)/(b-a+1);
183 for(
int i=k+1;i<=n;i++) {c+=log(i);}
184 for(
int j=1;j<=(n-k);j++) {c-=log(j);}
193 return bin_coef(n,k)*pow(p,k)*pow(1-p,n-k);
211 std::vector<float> param (2,0.0);
230 for(
int i=1; i<=n;i++){
244 return sqrt((2*
PI)/x)*pow(((x/exp(1))*sqrt(x*sinh(1/x)+1/810*pow(x,6))),x);
250 return (pow(beta,alpha)/
gamma_func(alpha))*pow(x,alpha-1)*exp(-beta*x);
262 std::vector<double> parameters (2,0.0);
276 double beta_pdf(
double x,
double alpha,
double beta){
280 double beta_pdf(
double x, std::vector<double> param){
281 return beta_pdf(x,param[0],param[1]);
284 double beta_cdf(
double x,
double alpha,
double beta){
285 std::vector<double> parameters (2,0.0);
299 double normal_pdf(
double x,
double mean,
double variance){
300 return (1/(sqrt(2*
PI*variance)))*exp(-1*pow(x-mean,2)/(2*variance));
309 float summation (
float (*funct)(
int,std::vector<float>),
int lower,
int upper, std::vector<float> param){
311 for(
int i=lower;i<=upper;i++){
325 if (r.size()==p.size()){
return 0.0;}
328 for(
int i=0;i<r.size();i++){
339 double value=param[0];
340 return (pow(x,value-1)*exp(-x));
344 std::vector<double> parameters (2,0.0);
359 double erf_value=
erf(x);
360 return 0.5*(1.0+erf_value);