X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=binaries%2Fsrc%2Fmuscle%2Fintmath.cpp;fp=binaries%2Fsrc%2Fmuscle%2Fintmath.cpp;h=40c25bb38d58ec46dd27dd25c908e0c3cd0d0aba;hb=b67f9b9dd77fa8f57d515842b8382b88d85cc029;hp=5a09dd48fb0e34703bcae0c2ed0282f31143f7b3;hpb=faaf27fc0103b2fbd8a9a19a2aa8e544d2144fbb;p=jabaws.git diff --git a/binaries/src/muscle/intmath.cpp b/binaries/src/muscle/intmath.cpp index 5a09dd4..40c25bb 100644 --- a/binaries/src/muscle/intmath.cpp +++ b/binaries/src/muscle/intmath.cpp @@ -8,31 +8,33 @@ PROB ScoreToProb(SCORE Score) return (PROB) pow(2.0, (double) Score/INTSCALE); } -static const double log2e = log2(exp(1.0)); - -double lnTolog2(double ln) - { - return ln*log2e; - } - -double log2(double x) - { - if (0 == x) - return MINUS_INFINITY; - - static const double dInvLn2 = 1.0/log(2.0); -// Multiply by inverse of log(2) just in case multiplication -// is faster than division. - return log(x)*dInvLn2; - } - -SCORE ProbToScore(PROB Prob) - { - if (0.0 == Prob) - return MINUS_INFINITY; -// return (SCORE) floor(INTSCALE*log2(Prob)); - return (SCORE) log2(Prob); - } +//#if 0 +//static const double log2e = log2(exp(1.0)); +// +//double lnTolog2(double ln) +// { +// return ln*log2e; +// } +// +//double log2(double x) +// { +// if (0 == x) +// return MINUS_INFINITY; +// +// static const double dInvLn2 = 1.0/log(2.0); +//// Multiply by inverse of log(2) just in case multiplication +//// is faster than division. +// return log(x)*dInvLn2; +// } +//#endif + +//SCORE ProbToScore(PROB Prob) +// { +// if (0.0 == Prob) +// return MINUS_INFINITY; +//// return (SCORE) floor(INTSCALE*log2(Prob)); +// return (SCORE) log2(Prob); +// } WEIGHT DoubleToWeight(double d) { @@ -69,97 +71,97 @@ bool BTEq(double b1, double b2) return BTEq2((BASETYPE) b1, (BASETYPE) b2); } -const double dLn2 = log(2.0); - -// pow2(x)=2^x -double pow2(double x) - { - if (MINUS_INFINITY == x) - return 0; - return exp(x*dLn2); - } - -// lp2(x) = log2(1 + 2^-x), x >= 0 -double lp2(double x) - { - return log2(1 + pow2(-x)); - } - -// SumLog(x, y) = log2(2^x + 2^y) -SCORE SumLog(SCORE x, SCORE y) - { - return (SCORE) log2(pow2(x) + pow2(y)); - } - -// SumLog(x, y, z) = log2(2^x + 2^y + 2^z) -SCORE SumLog(SCORE x, SCORE y, SCORE z) - { - return (SCORE) log2(pow2(x) + pow2(y) + pow2(z)); - } +//const double dLn2 = log(2.0); -// SumLog(w, x, y, z) = log2(2^w + 2^x + 2^y + 2^z) -SCORE SumLog(SCORE w, SCORE x, SCORE y, SCORE z) - { - return (SCORE) log2(pow2(w) + pow2(x) + pow2(y) + pow2(z)); - } +//// pow2(x)=2^x +//double pow2(double x) +// { +// if (MINUS_INFINITY == x) +// return 0; +// return exp(x*dLn2); +// } -SCORE lp2Fast(SCORE x) - { - assert(x >= 0); - const int iTableSize = 1000; - const double dRange = 20.0; - const double dScale = dRange/iTableSize; - static SCORE dValue[iTableSize]; - static bool bInit = false; - if (!bInit) - { - for (int i = 0; i < iTableSize; ++i) - dValue[i] = (SCORE) lp2(i*dScale); - bInit = true; - } - if (x >= dRange) - return 0.0; - int i = (int) (x/dScale); - assert(i >= 0 && i < iTableSize); - SCORE dResult = dValue[i]; - assert(BTEq(dResult, lp2(x))); - return dResult; - } +//// lp2(x) = log2(1 + 2^-x), x >= 0 +//double lp2(double x) +// { +// return log2(1 + pow2(-x)); +// } // SumLog(x, y) = log2(2^x + 2^y) -SCORE SumLogFast(SCORE x, SCORE y) - { - if (MINUS_INFINITY == x) - { - if (MINUS_INFINITY == y) - return MINUS_INFINITY; - return y; - } - else if (MINUS_INFINITY == y) - return x; - - SCORE dResult; - if (x > y) - dResult = x + lp2Fast(x-y); - else - dResult = y + lp2Fast(y-x); - assert(SumLog(x, y) == dResult); - return dResult; - } - -SCORE SumLogFast(SCORE x, SCORE y, SCORE z) - { - SCORE dResult = SumLogFast(x, SumLogFast(y, z)); - assert(SumLog(x, y, z) == dResult); - return dResult; - } - -SCORE SumLogFast(SCORE w, SCORE x, SCORE y, SCORE z) - { - SCORE dResult = SumLogFast(SumLogFast(w, x), SumLogFast(y, z)); - assert(SumLog(w, x, y, z) == dResult); - return dResult; - } +//SCORE SumLog(SCORE x, SCORE y) +// { +// return (SCORE) log2(pow2(x) + pow2(y)); +// } +// +//// SumLog(x, y, z) = log2(2^x + 2^y + 2^z) +//SCORE SumLog(SCORE x, SCORE y, SCORE z) +// { +// return (SCORE) log2(pow2(x) + pow2(y) + pow2(z)); +// } +// +//// SumLog(w, x, y, z) = log2(2^w + 2^x + 2^y + 2^z) +//SCORE SumLog(SCORE w, SCORE x, SCORE y, SCORE z) +// { +// return (SCORE) log2(pow2(w) + pow2(x) + pow2(y) + pow2(z)); +// } + +//SCORE lp2Fast(SCORE x) +// { +// assert(x >= 0); +// const int iTableSize = 1000; +// const double dRange = 20.0; +// const double dScale = dRange/iTableSize; +// static SCORE dValue[iTableSize]; +// static bool bInit = false; +// if (!bInit) +// { +// for (int i = 0; i < iTableSize; ++i) +// dValue[i] = (SCORE) lp2(i*dScale); +// bInit = true; +// } +// if (x >= dRange) +// return 0.0; +// int i = (int) (x/dScale); +// assert(i >= 0 && i < iTableSize); +// SCORE dResult = dValue[i]; +// assert(BTEq(dResult, lp2(x))); +// return dResult; +// } +// +//// SumLog(x, y) = log2(2^x + 2^y) +//SCORE SumLogFast(SCORE x, SCORE y) +// { +// if (MINUS_INFINITY == x) +// { +// if (MINUS_INFINITY == y) +// return MINUS_INFINITY; +// return y; +// } +// else if (MINUS_INFINITY == y) +// return x; +// +// SCORE dResult; +// if (x > y) +// dResult = x + lp2Fast(x-y); +// else +// dResult = y + lp2Fast(y-x); +// assert(SumLog(x, y) == dResult); +// return dResult; +// } +// +//SCORE SumLogFast(SCORE x, SCORE y, SCORE z) +// { +// SCORE dResult = SumLogFast(x, SumLogFast(y, z)); +// assert(SumLog(x, y, z) == dResult); +// return dResult; +// } + +//SCORE SumLogFast(SCORE w, SCORE x, SCORE y, SCORE z) +// { +// SCORE dResult = SumLogFast(SumLogFast(w, x), SumLogFast(y, z)); +// assert(SumLog(w, x, y, z) == dResult); +// return dResult; +// } double VecSum(const double v[], unsigned n) {