Fawkes API  Fawkes Development Version
probdist.h
1 
2 /***************************************************************************
3  * probdist.h probabilistic distributions
4  *
5  * Created: Wed Jan 4 2009
6  * Copyright 2009 Masrur Doostdar
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __UTILS_MATH_PROBDIST_H_
25 #define __UTILS_MATH_PROBDIST_H_
26 
27 #include <cmath>
28 
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** The normal distribution
36  * @param diff the differance: (x - mu) for the mean mu and the randomvariable x
37  * @param sigma the variance
38  * @return probability in normal distribution
39  */
40 inline float gauss( const float diff,
41  const float sigma = 1.0 )
42 {
43  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))) ;
44 }
45 
46 
47 
48 /** Computes the intersection integral of two gaussians given
49  * @param mu1 mean of first gaussian
50  * @param sigma1 variance of first gaussian
51  * @param mu2 mean of second gaussian
52  * @param sigma2 variance of second gaussian
53  * @param step discretization steps for the integral computation
54  * @return computed integral
55  */
56 inline float intersection_integral_oftwo_gaussians(float mu1,float sigma1, float mu2, float sigma2, float step){
57  float begin=std::max(mu1-3*sigma1, mu2-3*sigma2);
58  float end=std::min(mu1+3*sigma1, mu2+3*sigma2);
59  float integral=0;
60  for (float i=begin;i<end; i+=step){
61  integral+=std::min(gauss(mu1-i,sigma1), gauss(mu2-i,sigma2));
62  }
63  integral*=step;
64  return integral;
65 }
66 
67 
68 } // end namespace fawkes
69 
70 #endif
Fawkes library namespace.
float gauss(const float diff, const float sigma=1.0)
The normal distribution.
Definition: probdist.h:40
float intersection_integral_oftwo_gaussians(float mu1, float sigma1, float mu2, float sigma2, float step)
Computes the intersection integral of two gaussians given.
Definition: probdist.h:56