NCBI C++ ToolKit
njn_function.hpp
Go to the documentation of this file.
00001 #ifndef ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
00002 #define ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
00003 
00004 /* $Id: njn_function.hpp 45002 2010-03-04 16:32:37Z boratyng $
00005 * ===========================================================================
00006 *
00007 *                            PUBLIC DOMAIN NOTICE
00008 *               National Center for Biotechnology Information
00009 *
00010 *  This software/database is a "United States Government Work" under the
00011 *  terms of the United States Copyright Act.  It was written as part of
00012 *  the author's offical duties as a United States Government employee and
00013 *  thus cannot be copyrighted.  This software/database is freely available
00014 *  to the public for use. The National Library of Medicine and the U.S.
00015 *  Government have not placed any restriction on its use or reproduction.
00016 *
00017 *  Although all reasonable efforts have been taken to ensure the accuracy
00018 *  and reliability of the software and data, the NLM and the U.S.
00019 *  Government do not and cannot warrant the performance or results that
00020 *  may be obtained by using this software or data. The NLM and the U.S.
00021 *  Government disclaim all warranties, express or implied, including
00022 *  warranties of performance, merchantability or fitness for any particular
00023 *  purpose.
00024 *
00025 *  Please cite the author in any work or product based on this material.
00026 *
00027 * ===========================================================================*/
00028 
00029 /*****************************************************************************
00030 
00031 File name: njn_function.hpp
00032 
00033 Author: John Spouge
00034 
00035 Contents: 
00036 
00037 ******************************************************************************/
00038 
00039 #include <corelib/ncbistl.hpp>
00040 
00041 #include "njn_doubletype.hpp"
00042 
00043 #ifdef log2
00044 #undef log2
00045 #endif
00046 
00047 BEGIN_NCBI_SCOPE
00048 BEGIN_SCOPE(blast)
00049 
00050 BEGIN_SCOPE(Njn)
00051 BEGIN_SCOPE(Function)
00052 
00053       template <typename T> inline T bitsToNats (T x_);
00054       template <typename T> inline T natsToBits (T x_);
00055       template <typename T> inline T hartleysToNats (T x_);
00056       template <typename T> inline T natsToHartleys (T x_);
00057       template <typename T> inline T hartleysToBits (T x_);
00058       template <typename T> inline T bitsToHartleys (T x_);
00059 
00060       template <typename T> inline T exp2 (T x_);
00061       template <typename T> inline T log2 (T x_);
00062       template <typename T> inline T exp10 (T x_);
00063       template <typename T> inline T log10 (T x_);
00064 
00065       template <typename T> inline T max (T x_, T y_);
00066       template <typename T> inline T max3 (T a_, T b_, T c_);
00067       template <typename T> inline T min (T x_, T y_);
00068       template <typename T> inline T plus (T x_); // x_^+
00069       template <typename T> inline T minus (T x_); // x_^-
00070       template <typename T> inline T signum (T x_);
00071       template <typename T> inline T heaviside (T x_);
00072 
00073       template <typename T> inline T psqrt (T x_); // square-root of x_^+
00074       template <typename T> inline T square (T x_); // x_ * x_
00075 
00076       template <typename T> inline T bound (T x_, T xlo_, T xhi_); // the closest value to x_ in the interval [xlo_, xhi_]
00077       template <typename T> inline T probability (T x_); // the closest value to x_ in the interval [0.0, 1.0]
00078       template <typename T> inline T prob (T x_); // the closest value to x_ in the interval [0.0, 1.0]
00079 
00080       template <typename T> inline bool isProb (T x_); // the closest value to x_ in the interval [0.0, 1.0]
00081 
00082 //END_SCOPE(Function)
00083 //END_SCOPE(Njn)
00084 
00085 
00086 //
00087 // There are no more declarations beyond this point.
00088 //
00089 
00090 //BEGIN_SCOPE(Njn)
00091 //BEGIN_SCOPE(Function)
00092 
00093       template <typename T> T bitsToNats (T x_) {return x_ * DoubleType::LN_2;}
00094       template <typename T> T natsToBits (T x_) {return x_ / DoubleType::LN_2;}
00095       template <typename T> T hartleysToNats (T x_) {return x_ * DoubleType::LN_10;}
00096       template <typename T> T natsToHartleys (T x_) {return x_ / DoubleType::LN_10;}
00097       template <typename T> T hartleysToBits (T x_) {return hartleysToNats (natsToBits (x_));}
00098       template <typename T> T bitsToHartleys (T x_) {return bitsToNats (natsToHartleys (x_));}
00099 
00100       template <typename T> T exp2 (T x_) {return exp (DoubleType::LN_2 * (x_));}
00101       template <typename T> T log2 (T x_) {return log (x_) / DoubleType::LN_2;}
00102       template <typename T> T exp10 (T x_) {return exp (DoubleType::LN_10 * (x_));}
00103       template <typename T> T log10 (T x_) {return log (x_) / DoubleType::LN_10;}
00104 
00105       template <typename T> T max (T x_, T y_) {return x_ > y_ ? x_ : y_;}
00106       template <typename T> T max3 (T a_, T b_, T c_) {return max <T> (a_, max <T> (b_, c_));}
00107       template <typename T> T min (T x_, T y_) {return x_ < y_ ? x_ : y_;}
00108       template <typename T> T positive (T x_) {return max <T> (x_, static_cast <T> (0));}
00109       template <typename T> T negative (T x_) {return max <T> (-x_, static_cast <T> (0));}
00110       template <typename T> T signum (T x_) {return x_ > 0.0 ? 1.0 : (x_ == 0.0 ? 0.0 : -1.0);}
00111       template <typename T> T heaviside (T x_) {return x_ < 0.0 ? 0.0 : 1.0;}
00112 
00113       template <typename T> T psqrt (T x_) {return positive <T> (sqrt (x_));}
00114       template <typename T> T square (T x_) {return x_ * x_;}
00115 
00116       template <typename T> T bound (T x_, T xlo_, T xhi_) {
00117          if (x_ < xlo_) return xlo_;
00118          if (x_ < xhi_) return x_;
00119          return xhi_;
00120       }
00121 
00122       template <typename T> T probability (T x_) {return bound <T> (x_, 0.0, 1.0);}
00123       template <typename T> T prob (T x_) {return probability <T> (x_);}
00124 
00125       template <typename T> bool isProb (T x_) {return 0.0 <= x_ && x_ <= 1.0;}; // the closest value to x_ in the interval [0.0, 1.0]
00126 
00127 END_SCOPE(Function)
00128 END_SCOPE(Njn)
00129 
00130 END_SCOPE(blast)
00131 END_NCBI_SCOPE
00132 
00133 #endif //! ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
Modified on Wed May 23 13:25:57 2012 by modify_doxy.py rev. 337098