CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mathfunc.h
Go to the documentation of this file.
1 #ifndef __MATHFUNC_H__
2 #define __MATHFUNC_H__
3 
4 #include<math.h>
5 #include<stdarg.h>
6 #include<stdio.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #define __EPS__ 1e-8
13 
14 #ifndef MAX
15 #define MAX(a,b) ( (a) > (b) ? (a) : (b) )
16 #endif
17 
18 #ifndef MIN
19 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
20 #endif
21 
22 #define MAX_DOUBLE 1.7976931348623157e+308
23 #define MIN_DOUBLE 4.9e-300
24 
25 
26 typedef double (*math_func)(double* x, void* args);
27 
28 typedef struct
29 {
30  int maxiters;
31  int bymax;
32  double rho, chi, psi, sigma;
33  double tolx, tolf;
34  double delta, zero_delta;
35 
36  int N, N1;
37  int iters;
38  double** v;
39  double* fv;
40  double** vsort;
41  double* x_mean;
42  double* x_r;
43  double* x_tmp;
44  int* idx;
45 
46  void* args;
48 }FMinSearch;
49 
51 
52 extern int __maxidx(double* data, int size );
53 extern double __max(double* data, int size );
54 extern double __min(double* data, int size );
55 extern double ipow(double val, int expo);
56 
57 extern double unifrnd();
58 
59 extern double gamma(double c);
60 extern double gammaln(double c);
61 extern double gammaincln(double x, double a);
62 extern double gammainc(double x, double a);
63 
64 extern double beta(double alpha, double beta);
65 extern double betaln(double alpha, double beta);
66 extern double betainc(double x, double alpha, double beta);
67 
68 extern double choose(double n, double r);
69 extern double chooseln(double n, double r);
70 extern double gampdf(double x, double alpha, double beta);
71 extern double gamcdf(double x, double alpha, double beta);
72 extern double betapdf(double x, double alpha, double beta);
73 extern double chi2pdf(double x, int df);
74 extern double chi2cdf(double x, int df);
75 extern double fpdf(double x, int df1, int df2 );
76 extern double fcdf(double x, int df1, int df2 );
77 extern double tpdf(double x, int df);
78 extern double tcdf(double x, int df);
79 extern double binopdf(int x, int n, double p);
80 extern double binocdf(int x, int n, double p);
81 extern double poisspdf(int x, double lambda);
82 extern double poisscdf(int x, double lambda );
83 extern double exppdf(double x, double mu );
84 extern double exprnd(double mu);
85 extern double reylpdf(double x, double b);
86 extern double normpdf(double x, double mu, double sigma);
87 extern double normrnd(double mu, double sigma);
88 extern double normcdf(double x, double mu, double sigma);
89 extern double norminv(double x, double mu, double sigma);
90 extern double mean(double* data, int size);
91 extern double variance(double* data, int size);
92 extern double summation(double* data, int size);
93 extern double* vector_fraction(double* data, int size, double denominator);
94 extern int comp_double (const void * elem1, const void * elem2);
95 
96 extern double pvalue(double v, const double* conddist, int size );
97 
98 extern double fminsearch(pFMinSearch pfm, double* X0);
99 
100 extern pFMinSearch fminsearch_new();
101 extern pFMinSearch fminsearch_new_with_eq(math_func eq, int Xsize, void* args);
102 extern void fminsearch_set_equation(pFMinSearch pfm,math_func eq, int Xsize, void* args);
103 extern void fminsearch_free(pFMinSearch pfm);
104 extern int fminsearch_min(pFMinSearch pfm, double* X0);
105 extern double* fminsearch_get_minX(pFMinSearch pfm);
106 extern double fminsearch_get_minF(pFMinSearch pfm);
107 
108 typedef struct tagHistogram
109 {
110  int nbins;
111  int nsamples;
112  double width;
113  double max,min;
114 
115  double* point;
116  unsigned int* count;
117 }Histogram;
118 
120 
121 extern pHistogram histogram_new(double* data, int nsamples, int nbins);
122 extern void histogram_free(pHistogram phist);
123 extern void histogram_set_by_bin(pHistogram phist, double* data, int nsample, int nbins );
124 extern void histogram_set_by_unit(pHistogram phist, double* data, int nsample, double unit );
125 extern void histogram_set_sparse_data(pHistogram phist, double* data, int nsamples );
126 extern int histogram_get_count(pHistogram phist, double p);
127 extern double histogram_compare(pHistogram phist1, pHistogram phist2);
128 extern void histogram_print(pHistogram phist,FILE* fp);
129 extern int histogram_merge(pHistogram phist, pHistogram parg);
130 extern double histogram_check_fitness(pHistogram phist, double* args, double (*cdf)(double p, double* args) );
131 extern double histogram_get_prob(pHistogram phist, double p);
132 extern pHistogram histogram_load(char* file);
133 extern void histogram_set_with_preset_point(pHistogram phist, double* data, int nsamples, double* point, int nbins);
134 
135 typedef struct tagANOVAResultElement
136 {
137  int df;
138  double* mean;
139  int* num;
140  double vSS;
141  double MS;
142  double F;
143  double pvalue;
145 
147 
148 typedef struct tagANOVA
149 {
150  int nways;
151  int* ngrps;
152  void* data;
153  double gmean;
154  pANOVAResultElement value;
157 }ANOVA;
158 
159 typedef ANOVA* pANOVA;
160 
161 extern pANOVA anova_new(int nways, int* ngrps);
162 extern void anova(pANOVA panova, ... );
163 extern void anova1_run(pANOVA panova);
164 extern void anova2_run(pANOVA panova);
165 extern void anovan_run(pANOVA panova, va_list ap);
166 extern void anova_free(pANOVA panova);
167 extern void anova_print(pANOVA panova, char** name);
168 extern void anova_print_data(pANOVA panova);
169 
170 extern double cmp_paired_t_test(double* grp1, double* grp2, int size);
171 extern double cmp_two_indep_chi2test(double* grp1, double* grp2, int size );
172 extern double cmp_two_indep_t_test(double* grp1, int size1, double* grp2, int size2 );
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif
double * fminsearch_get_minX(pFMinSearch pfm)
Definition: fminsearch.cpp:304
double beta(double alpha, double beta)
Definition: mathfunc.c:156
void fminsearch_free(pFMinSearch pfm)
Definition: fminsearch.cpp:46
int * ngrps
Definition: mathfunc.h:151
double fminsearch(pFMinSearch pfm, double *X0)
double vSS
Definition: mathfunc.h:140
void * args
Definition: mathfunc.h:46
void anova_free(pANOVA panova)
Definition: grpcmp.c:122
double ** vsort
Definition: mathfunc.h:40
pANOVA anova_new(int nways, int *ngrps)
Definition: grpcmp.c:86
double normpdf(double x, double mu, double sigma)
Definition: mathfunc.c:420
int maxiters
Definition: mathfunc.h:30
double cmp_two_indep_chi2test(double *grp1, double *grp2, int size)
Definition: grpcmp.c:62
Definition: mathfunc.h:148
int iters
Definition: mathfunc.h:37
struct tagHistogram Histogram
int df
Definition: mathfunc.h:137
void fminsearch_set_equation(pFMinSearch pfm, math_func eq, int Xsize, void *args)
Definition: fminsearch.cpp:53
double(* math_func)(double *x, void *args)
Definition: mathfunc.h:26
void histogram_set_by_unit(pHistogram phist, double *data, int nsample, double unit)
Definition: histogram.c:171
double normcdf(double x, double mu, double sigma)
Definition: mathfunc.c:632
double gammaincln(double x, double a)
Definition: mathfunc.c:143
double width
Definition: mathfunc.h:112
double pvalue(double v, const double *conddist, int size)
Definition: mathfunc.c:663
void anova(pANOVA panova,...)
Definition: grpcmp.c:231
double betaln(double alpha, double beta)
Definition: mathfunc.c:161
double reylpdf(double x, double b)
double binocdf(int x, int n, double p)
Definition: mathfunc.c:332
math_func eq
Definition: mathfunc.h:47
Definition: mathfunc.h:135
double fminsearch_get_minF(pFMinSearch pfm)
Definition: fminsearch.cpp:309
double pvalue
Definition: mathfunc.h:143
double __min(double *data, int size)
Definition: mathfunc.c:42
Definition: mathfunc.h:28
double chi2cdf(double x, int df)
Definition: mathfunc.c:284
double ipow(double val, int expo)
Definition: mathfunc.c:60
double * mean
Definition: mathfunc.h:138
struct tagANOVA ANOVA
double MS
Definition: mathfunc.h:141
int histogram_get_count(pHistogram phist, double p)
Definition: histogram.c:284
double zero_delta
Definition: mathfunc.h:34
ANOVAResultElement total
Definition: mathfunc.h:155
double summation(double *data, int size)
Definition: mathfunc.c:691
pANOVAResultElement value
Definition: mathfunc.h:154
double __max(double *data, int size)
Definition: mathfunc.c:27
int * idx
Definition: mathfunc.h:44
pHistogram histogram_new(double *data, int nsamples, int nbins)
Definition: histogram.c:9
double poisscdf(int x, double lambda)
Definition: mathfunc.c:357
double cmp_paired_t_test(double *grp1, double *grp2, int size)
Definition: grpcmp.c:9
double max
Definition: mathfunc.h:113
ANOVAResultElement error
Definition: mathfunc.h:156
void anovan_run(pANOVA panova, va_list ap)
double exppdf(double x, double mu)
Definition: mathfunc.c:395
double chooseln(double n, double r)
Definition: mathfunc.c:224
double * fv
Definition: mathfunc.h:39
double * x_r
Definition: mathfunc.h:42
double gamcdf(double x, double alpha, double beta)
Definition: mathfunc.c:260
double F
Definition: mathfunc.h:142
void histogram_set_by_bin(pHistogram phist, double *data, int nsample, int nbins)
Definition: histogram.c:144
void anova_print(pANOVA panova, char **name)
Definition: grpcmp.c:343
void * data
Definition: mathfunc.h:152
double unifrnd()
Definition: mathfunc.c:91
int * num
Definition: mathfunc.h:139
double mean(double *data, int size)
Definition: mathfunc.c:646
int __maxidx(double *data, int size)
Definition: mathfunc.c:9
double gamma(double c)
Definition: mathfunc.c:100
int nbins
Definition: mathfunc.h:110
int fminsearch_min(pFMinSearch pfm, double *X0)
Definition: fminsearch.cpp:264
pFMinSearch fminsearch_new()
Definition: fminsearch.cpp:7
void histogram_set_with_preset_point(pHistogram phist, double *data, int nsamples, double *point, int nbins)
Definition: histogram.c:214
ANOVA * pANOVA
Definition: mathfunc.h:159
pFMinSearch fminsearch_new_with_eq(math_func eq, int Xsize, void *args)
Definition: fminsearch.cpp:23
double sigma
Definition: mathfunc.h:32
double tolx
Definition: mathfunc.h:33
void anova_print_data(pANOVA panova)
Definition: grpcmp.c:360
double histogram_compare(pHistogram phist1, pHistogram phist2)
Definition: histogram.c:389
ANOVAResultElement * pANOVAResultElement
Definition: mathfunc.h:146
struct tagANOVAResultElement ANOVAResultElement
void histogram_free(pHistogram phist)
Definition: histogram.c:77
double * point
Definition: mathfunc.h:115
FMinSearch * pFMinSearch
Definition: mathfunc.h:50
void anova2_run(pANOVA panova)
Definition: grpcmp.c:279
double variance(double *data, int size)
Definition: mathfunc.c:654
double gammaln(double c)
Definition: mathfunc.c:112
double betainc(double x, double alpha, double beta)
Definition: mathfunc.c:207
double norminv(double x, double mu, double sigma)
Definition: mathfunc.c:637
int nsamples
Definition: mathfunc.h:111
double * vector_fraction(double *data, int size, double denominator)
Definition: mathfunc.c:702
double ** v
Definition: mathfunc.h:38
unsigned int * count
Definition: mathfunc.h:116
double * x_tmp
Definition: mathfunc.h:43
int histogram_merge(pHistogram phist, pHistogram parg)
Definition: histogram.c:296
double gampdf(double x, double alpha, double beta)
Definition: mathfunc.c:245
double binopdf(int x, int n, double p)
Definition: mathfunc.c:327
void histogram_print(pHistogram phist, FILE *fp)
Definition: histogram.c:365
tuple args
Definition: mcl2rawcafe.py:48
int nways
Definition: mathfunc.h:150
double fcdf(double x, int df1, int df2)
Definition: mathfunc.c:302
double poisspdf(int x, double lambda)
Definition: mathfunc.c:352
void histogram_set_sparse_data(pHistogram phist, double *data, int nsamples)
Definition: histogram.c:233
double choose(double n, double r)
Definition: mathfunc.c:219
Histogram * pHistogram
Definition: mathfunc.h:119
double chi2pdf(double x, int df)
Definition: mathfunc.c:279
int N1
Definition: mathfunc.h:36
void anova1_run(pANOVA panova)
Definition: grpcmp.c:246
double histogram_get_prob(pHistogram phist, double p)
Definition: histogram.c:291
double tcdf(double x, int df)
Definition: mathfunc.c:317
double min
Definition: mathfunc.h:113
int bymax
Definition: mathfunc.h:31
double histogram_check_fitness(pHistogram phist, double *args, double(*cdf)(double p, double *args))
Definition: histogram.c:394
Definition: mathfunc.h:108
double tpdf(double x, int df)
Definition: mathfunc.c:311
double gmean
Definition: mathfunc.h:153
double gammainc(double x, double a)
Definition: mathfunc.c:148
pHistogram histogram_load(char *file)
Definition: histogram.c:28
double normrnd(double mu, double sigma)
Definition: mathfunc.c:426
double fpdf(double x, int df1, int df2)
Definition: mathfunc.c:293
double betapdf(double x, double alpha, double beta)
Definition: mathfunc.c:269
int comp_double(const void *elem1, const void *elem2)
Definition: mathfunc.c:712
double exprnd(double mu)
Definition: mathfunc.c:400
double * x_mean
Definition: mathfunc.h:41
double cmp_two_indep_t_test(double *grp1, int size1, double *grp2, int size2)
Definition: grpcmp.c:28