probdist.h

00001 
00002 /***************************************************************************
00003  *  probdist.h  probabilistic distributions
00004  *
00005  *  Created: Wed Jan 4 2009
00006  *  Copyright  2009 Masrur Doostdar
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __UTILS_MATH_PROBDIST_H_
00025 #define __UTILS_MATH_PROBDIST_H_
00026 
00027 #include <cmath>
00028 
00029 
00030 namespace fawkes {
00031 #if 0 /* just to make Emacs auto-indent happy */
00032 }
00033 #endif
00034 
00035 /** The normal distribution
00036  * @param diff the differance: (x - mu) for the mean mu and the randomvariable x
00037  * @param sigma the variance
00038  * @return probability in normal distribution
00039  */
00040 inline float gauss( const float diff, 
00041                     const float sigma = 1.0 )
00042 {
00043   return sigma==0.0 ? (diff==0.0? 1.0 : 0.0) : (1.0 / sqrtf(2.0 * M_PI)) * 1/sigma * expf( -0.5 * ( (diff*diff) / (sigma*sigma))) ;  
00044 } 
00045 
00046 
00047 
00048 /** Computes the intersection integral of two gaussians given
00049  * @param mu1 mean of first gaussian
00050  * @param sigma1 variance of first gaussian
00051  * @param mu2 mean of second gaussian
00052  * @param sigma2 variance of second gaussian
00053  * @param step discretization steps for the integral computation
00054  * @return computed integral
00055  */
00056 inline float intersection_integral_oftwo_gaussians(float mu1,float sigma1, float mu2, float sigma2, float step){
00057   float begin=std::max(mu1-3*sigma1, mu2-3*sigma2);
00058   float end=std::min(mu1+3*sigma1, mu2+3*sigma2);
00059   float integral=0;
00060   for (float i=begin;i<end; i+=step){
00061     integral+=std::min(gauss(mu1-i,sigma1), gauss(mu2-i,sigma2));
00062   }
00063   integral*=step;
00064   return integral;
00065 }
00066 
00067 
00068 } // end namespace fawkes
00069 
00070 #endif

Generated on Tue Feb 22 13:31:27 2011 for Fawkes API by  doxygen 1.4.7