source: tags/arb-6.0/GDE/MAFFT/mafft-7.055-with-extensions/extensions/mxscarna_src/Util.hpp

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
32namespace ProbCons {
33   
34const double IMPOSSIBLE = -FLT_MAX + 1000;
35const double IMPOSSIBLEDBL = -DBL_MAX + 10000;
36
37namespace MXSCARNA {
38template <typename T>
39inline bool
40IsPossible(const T& v) { 
41    return (v > (IMPOSSIBLE + 1.0e-5));
42}
43
44template <typename T>
45inline T
46logSum(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
55template <typename T>
56inline T
57logSub(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
67template <typename T>
68inline T
69logSum(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
86template <typename T>
87inline T
88logSumExp(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.