-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwchissum.cpp
132 lines (89 loc) · 3.98 KB
/
wchissum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
PascalX - A python3 library for high precision gene and pathway scoring for
GWAS summary statistics with C++ backend.
https://github.com/BergmannLab/PascalX
Copyright (C) 2021 Bergmann lab and contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <boost/multiprecision/float128.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <ruben.hpp>
#include <davies.hpp>
using namespace boost::multiprecision;
using namespace boost::math;
double onemin_smart_algo(double* lambda, int n, double X, int* ifault) {
std::cout << std::scientific;
// Dummy centrality parameters and multiplicities
double* nc = new double[n];
int* ml = new int[n];
// find min and max lambda
double lmax = lambda[0];
double lmin = lambda[0];
double mean = 0;
for(int i = 0; i < n; i++) {
nc[i] = 0.0;
ml[i] = 1;
mean += lambda[i];
if(lambda[i] < lmin) lmin = lambda[i];
if(lambda[i] > lmax) lmax = lambda[i];
}
mean /= n;
double R = lmax/lmin;
double RESULT;
std::cout<<"\n"<<std::endl;
if(R < 100 || (n < 20 && R < 1000)) {
Ruben:
// Use Ruben
std::cout << "Using Ruben (N="<< n << " ,M=" << mean << " ,R=" << R << ", X=" << X << ")" <<std::endl;
double dnsty;
// Small precision run
RESULT = 1 - ruben<double>(lambda, ml, nc, n, X, 1, 100000, 1e-16, &dnsty, ifault);
if(RESULT < 1e-14 || ifault[0] != 0) {
float128 dn;
float128 tmp;
tmp = 1 - ruben<float128>(lambda, ml, nc, n, X, 1, 1000000, 1e-32, &dn, ifault);
if(tmp < 1e-30 || ifault[0] != 0) {
cpp_bin_float_100 dn;
cpp_bin_float_100 tmp;
tmp = 1 - ruben<cpp_bin_float_100>(lambda, ml, nc, n, X, 1, 10000000, 1e-100, &dn, ifault);
RESULT = tmp.convert_to<double>();
} else {
RESULT = tmp.convert_to<double>();
}
}
} else {
// Use Davies
std::cout << "Using Davies (N="<< n << " ,M=" << mean << " ,R=" << R << ", X=" << X << ")" <<std::endl;
double* trace = new double[7];
RESULT = 1 - davies<double>(lambda, ml, nc, n, X, 20000, 1e-12, ifault, trace);
std::cout << "RES1: " << RESULT << " [" << ifault[0] << "]"<< std::endl;
if(RESULT < 1e-14 || ifault[0] != 0) {
float128 tmp = 1 - davies<float128>(lambda, ml, nc, n, X, 100000, 1e-32, ifault, trace);
if(tmp < 1e-30 || ifault[0] != 0) {
cpp_bin_float_100 tmp = 1 - davies<cpp_bin_float_100>(lambda, ml, nc, n, X, 1000000, 1e-100, ifault, trace);
RESULT = tmp.convert_to<double>();
} else {
RESULT = tmp.convert_to<double>();
}
}
if(ifault[0]==1) goto Ruben;
delete(trace);
}
// Cleanup
delete(nc);
delete(ml);
return RESULT;
}
extern "C"
double onemin_wchissum_m1nc0(double* lambda, int n, double X, int* ifault) {
return onemin_smart_algo(lambda, n, X, ifault);
}