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 namespace fawkes {
30 
31 /** The normal distribution
32  * @param diff the differance: (x - mu) for the mean mu and the randomvariable x
33  * @param sigma the variance
34  * @return probability in normal distribution
35  */
36 inline float
37 gauss(const float diff, const float sigma = 1.0)
38 {
39  return sigma == 0.0
40  ? (diff == 0.0 ? 1.0 : 0.0)
41  : (1.0 / sqrtf(2.0 * M_PI)) * 1 / sigma * expf(-0.5 * ((diff * diff) / (sigma * sigma)));
42 }
43 
44 /** Computes the intersection integral of two gaussians given
45  * @param mu1 mean of first gaussian
46  * @param sigma1 variance of first gaussian
47  * @param mu2 mean of second gaussian
48  * @param sigma2 variance of second gaussian
49  * @param step discretization steps for the integral computation
50  * @return computed integral
51  */
52 inline float
53 intersection_integral_oftwo_gaussians(float mu1, float sigma1, float mu2, float sigma2, float step)
54 {
55  float begin = std::max(mu1 - 3 * sigma1, mu2 - 3 * sigma2);
56  float end = std::min(mu1 + 3 * sigma1, mu2 + 3 * sigma2);
57  float integral = 0;
58  for (float i = begin; i < end; i += step) {
59  integral += std::min(gauss(mu1 - i, sigma1), gauss(mu2 - i, sigma2));
60  }
61  integral *= step;
62  return integral;
63 }
64 
65 } // end namespace fawkes
66 
67 #endif
fawkes
fawkes::intersection_integral_oftwo_gaussians
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:59
fawkes::gauss
float gauss(const float diff, const float sigma=1.0)
The normal distribution.
Definition: probdist.h:43