Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 
00027 class NormalDistribution {
00028 private:
00029   double _mu;
00030   double _sigma;
00031 
00032   double _cdf( double x ) {
00033     const double a_1 = 0.4361836;
00034     const double a_2 = -0.1201676;
00035     const double a_3 = 0.9372980;
00036     const double p = 0.33267;
00037     const double pi = 3.1415926535;
00038 
00039     double t = 1./(1.+p*x);
00040     double zx = ( 1. / sqrt(2*pi*_sigma) ) * exp( pow( -((x-_mu)/_sigma), 2 ) );
00041 
00042     double cdf = 1 - zx * ( a_1*t + a_2*pow(t,2) + a_3*pow(t,3) );
00043     return cdf;
00044   }
00045 
00046 public:
00047   NormalDistribution( double mu, double sigma ) {
00048     _mu = mu;
00049     _sigma = sigma;
00050   }
00051 
00052   // The value returned here corresponds to the probability mass
00053   // on the Gaussian curve between value-0.5 and value+0.5
00054 
00055   double operator () ( INT64 value ) {
00056     // compute lower bound cdf
00057     double low = _cdf( value-0.5 );
00058     double high = _cdf( value+0.5 );
00059     return high - low;
00060   }
00061 };
00062 
00063 #endif // INDRI_NORMALDISTRIBUTION_HPP
00064 

Generated on Wed Nov 3 12:59:00 2004 for Lemur Toolkit by doxygen1.2.18