Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
ltqnorm.h
00001 /**************************************************************************
00002  * Copyright (c) 2004-2011 T. M. Murali                                   *
00003  *                                                                        *
00004  * This file is part of Biorithm.                                         *
00005  *                                                                        *
00006  * Biorithm is free software: you can redistribute it and/or modify       *
00007  * it under the terms of the GNU General Public License as published by   *
00008  * the Free Software Foundation, either version 3 of the License, or      *
00009  * (at your option) any later version.                                    *
00010  *                                                                        *
00011  * Biorithm is distributed in the hope that it will be useful,            *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00014  * GNU General Public License for more details.                           *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00018  *                                                                        *
00019  **************************************************************************/
00020 
00027 #ifndef _LTQNORM_H
00028 #define _LTQNORM_H
00029 
00030 #ifdef HAVE_GSL
00031 #include "gsl/gsl_cdf.h"
00032 #endif
00033 
00034 
00035 extern "C" 
00036 {
00037   double ltqnorm(double p);
00038 
00040   double gaussianPvalue(double r, double mean = 0, double sigma = 1);
00041 }
00042 
00043 const double LTQNORM_LARGEST_Z = 8.20954;
00044 // to keep the parallel with Corban's code.
00045 // const double LTQNORM_LARGEST_Z = 30;
00046 const double LTQNORM_SMALLEST_INVERSE = 1.11022e-16;
00047 
00048 // largestZ = 8.20954;
00049 // smallestInverse = 1.11022e-16;
00050 
00054 inline MyNT computeInverseNormalPvalueTransform(MyNT x)
00055 {
00056 #ifdef HAVE_GSL
00057   return(gsl_cdf_ugaussian_Qinv(x));
00058 #else
00059   // \todo HACKHACKHACK. this check should not be based on running
00060   // ltqnormThreshold() and manually entering the values in ltqhorm.h.
00061   if (x <= LTQNORM_SMALLEST_INVERSE)
00062     return(LTQNORM_LARGEST_Z);
00063   return(ltqnorm(1 - x));
00064 #endif  
00065 }
00066 
00069 struct inverseNormalPvalueTransform : public unary_function< MyNT, MyNT > 
00070 {
00071   MyNT operator()(const MyNT __x) const
00072     {
00073       return(computeInverseNormalPvalueTransform(__x));
00074     }
00075   
00076 };
00077 
00084 inline void ltqnormThreshold(MyNT &x, MyNT &inverse, unsigned int num = 100)
00085 {
00086   x = 1;
00087   while (true)
00088     {
00089       // pass just x because computeInverseNormalPvalueTransform invokes ltqnorm(1 - x).
00090       inverse = computeInverseNormalPvalueTransform(x);
00091 //      inverse = ltqnorm(1 - x);
00092       cout << "x = " << x << ", inverse = " << inverse << endl;
00093 //       if (inverse != inf)
00094         x = x/2;
00095 //       else
00096 //         break;
00097         num--;
00098         if (0 == num)
00099           break;
00100     }
00101   
00102 
00103 }
00104 
00105 
00106 
00107 #endif // _LTQNORM_H 
 All Classes Functions Variables Typedefs Friends