Last change
on this file was
10371,
checked in by aboeckma, 11 years ago
|
updated mafft version. Added extensions (no svn ignore, yet)
|
File size:
1.7 KB
|
Line | |
---|
1 | #ifndef UTIL_H |
---|
2 | #define UTIL_H |
---|
3 | |
---|
4 | #include <algorithm> |
---|
5 | #include <cassert> |
---|
6 | #include <cstdio> |
---|
7 | #include <cstdlib> |
---|
8 | #include <cstdarg> |
---|
9 | #include <cstring> |
---|
10 | #include <cmath> |
---|
11 | #include <cctype> |
---|
12 | #include <climits> |
---|
13 | #include <cfloat> |
---|
14 | #include <ctime> |
---|
15 | #include <fstream> |
---|
16 | #include <functional> |
---|
17 | #include <iomanip> |
---|
18 | #include <iostream> |
---|
19 | #include <iterator> |
---|
20 | #include <list> |
---|
21 | #include <map> |
---|
22 | #include <numeric> |
---|
23 | #include <string> |
---|
24 | #include <sstream> |
---|
25 | #include <stack> |
---|
26 | #include <vector> |
---|
27 | #include <fcntl.h> |
---|
28 | #include <unistd.h> |
---|
29 | //#include <pthread.h> // mingw de error, by katoh |
---|
30 | #include <signal.h> |
---|
31 | |
---|
32 | namespace ProbCons { |
---|
33 | |
---|
34 | const double IMPOSSIBLE = -FLT_MAX + 1000; |
---|
35 | const double IMPOSSIBLEDBL = -DBL_MAX + 10000; |
---|
36 | |
---|
37 | namespace MXSCARNA { |
---|
38 | template <typename T> |
---|
39 | inline bool |
---|
40 | IsPossible(const T& v) { |
---|
41 | return (v > (IMPOSSIBLE + 1.0e-5)); |
---|
42 | } |
---|
43 | |
---|
44 | template <typename T> |
---|
45 | inline T |
---|
46 | logSum(const T& a, const T& b) |
---|
47 | { |
---|
48 | if (a >= b) { |
---|
49 | return a + log(1.0 + exp(b - a)); |
---|
50 | } else { |
---|
51 | return b + log(1.0 + exp(a - b)); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | template <typename T> |
---|
56 | inline T |
---|
57 | logSub(const T&a, const T& b) |
---|
58 | { |
---|
59 | if(a > b) { |
---|
60 | return log(exp(a) - exp(b)); |
---|
61 | } |
---|
62 | else { |
---|
63 | return log(exp(a) - exp(b)); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | template <typename T> |
---|
68 | inline T |
---|
69 | logSum(const T& a, const T& b, const T& c) |
---|
70 | { |
---|
71 | if (a >= b) { |
---|
72 | if( a >= c ) { |
---|
73 | return a + log(1.0 + (exp(b - a) + exp(c - a))); |
---|
74 | } |
---|
75 | else { |
---|
76 | if( b >= c) { |
---|
77 | return b + log(exp(a - b) + 1.0 + exp(c - b)); |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | return c + log(exp(a - c) + exp(b - c) + 1.0); |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | template <typename T> |
---|
87 | inline T |
---|
88 | logSumExp(const T& x, const T& y) |
---|
89 | { |
---|
90 | if(x == y) return x + 0.69314718055; |
---|
91 | double vmin = std::min(x, y); |
---|
92 | double vmax = std::max(x, y); |
---|
93 | |
---|
94 | if (vmax > vmin + 50) { |
---|
95 | return vmax; |
---|
96 | } |
---|
97 | else { |
---|
98 | return vmax + std::log (std::exp (vmin - vmax) + 1.0); |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | #endif /* UTIL_H */ |
---|
Note: See
TracBrowser
for help on using the repository browser.