Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

NormalDistribution.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010  */
00011 
00012 
00013 //
00014 // NormalDistribution
00015 //
00016 // 20 July 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_NORMALDISTRIBUTION_HPP
00020 #define INDRI_NORMALDISTRIBUTION_HPP
00021 
00022 //
00023 // The normal distribution class is used to generate document priors
00024 // based on some integer attribute of a document.
00025 //
00026 namespace indri
00027 {
00028   namespace query
00029   {
00030     
00031     class NormalDistribution {
00032     private:
00033       double _mu;
00034       double _sigma;
00035 
00036       double _cdf( double x ) {
00037         const double a_1 = 0.4361836;
00038         const double a_2 = -0.1201676;
00039         const double a_3 = 0.9372980;
00040         const double p = 0.33267;
00041         const double pi = 3.1415926535;
00042 
00043         double t = 1./(1.+p*x);
00044         double zx = ( 1. / sqrt(2*pi*_sigma) ) * exp( pow( -((x-_mu)/_sigma), 2 ) );
00045 
00046         double cdf = 1 - zx * ( a_1*t + a_2*pow(t,2) + a_3*pow(t,3) );
00047         return cdf;
00048       }
00049 
00050     public:
00051       NormalDistribution( double mu, double sigma ) {
00052         _mu = mu;
00053         _sigma = sigma;
00054       }
00055 
00056       // The value returned here corresponds to the probability mass
00057       // on the Gaussian curve between value-0.5 and value+0.5
00058 
00059       double operator () ( INT64 value ) {
00060         // compute lower bound cdf
00061         double low = _cdf( value-0.5 );
00062         double high = _cdf( value+0.5 );
00063         return high - low;
00064       }
00065     };
00066   }
00067 }
00068 
00069 #endif // INDRI_NORMALDISTRIBUTION_HPP
00070 

Generated on Tue Jun 15 11:02:54 2010 for Lemur by doxygen 1.3.4