STK++ 1.0
STK_Funct_poisson_raw.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  Analysis
00027  * Purpose:  implementation of the poisson function
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  **/
00030 
00036 #include <cmath>
00037 
00038 #include "../include/STK_Const_Math.h"
00039 
00040 #include "../include/STK_Funct_gamma.h"
00041 
00042 #include "../include/STK_Funct_util.h"
00043 
00044 #include "../include/STK_Funct_raw.h"
00045 
00046 namespace STK
00047 {
00048   
00049 namespace Funct
00050 {
00064 Real poisson_pdf_raw(Real const& x, Real const& lambda)
00065 {
00066   // check trivial values
00067   if (x<0.) return( 0. );
00068   // if lambda is 0, we have P(X=0) = 1
00069   if (lambda==0.) return( (x==0.) ? 1. : 0. );
00070   // special value
00071   if (x==0.) return( exp(-lambda) );
00072   // stirling approximation and deviance
00073   return( exp(-gammaLnStirlingError(x)-dev0(x, lambda))
00074         / (Const::_SQRT2PI_*sqrt(x))
00075         );
00076 }
00077 
00091 Real poisson_pdf_raw(Integer const& x, Real const& lambda)
00092 {
00093   // check trivial values
00094   if (x<0) return( 0. );
00095   // if lambda is 0, we have P(X=0) = 1
00096   if (lambda==0) return( (x==0) ? 1. : .0 );
00097   // special value
00098   if (x==0) return( exp(-lambda) );
00099   // stirling approximation and deviance
00100   return( exp(-gammaLnStirlingError(x)-dev0(x, lambda))
00101         / (Const::_SQRT2PI_*sqrt(x))
00102         );
00103 }
00104 
00105 
00106 } // namespace Funct
00107 
00108 } // namespace STK