OpenFPM_pdata  4.1.0 Project that contain the implementation of distributed structures
Gaussian.hpp
1 //
2 // Created by jstark on 14.06.21.
3 //
4
5 #ifndef OPENFPM_NUMERICS_GAUSSIAN_HPP
6 #define OPENFPM_NUMERICS_GAUSSIAN_HPP
7
8 #include "cmath"
9
10
11 static double hermite_polynomial(double x, double sigma, int order)
12 {
13  double h;
14  switch(order)
15  {
16  case 0:
17  h = 1;
18  break;
19  case 1:
20  h = -x / (sigma * sigma);
21  break;
22  case 2:
23  h = (x*x - sigma*sigma) / (sigma*sigma*sigma*sigma);
24  break;
25  default:
26  std::cout << "Only gaussian derivatives of order 0, 1, and 2 implemented. Aborting..." << std::endl;
27  abort();
28  }
29  return h;
30 }
31
32 template <typename point_type>
33 double gaussian_1D(const point_type & x, const double mu, const double sigma)
34 {
35  const double pi = 3.14159265358979323846;
36  const double sqrt2pi = sqrt(2*pi);
37
38  double sum = (x - mu) * (x - mu) / (sigma*sigma);;
39  double normalization_factor = 1 / (sqrt2pi * sigma);
40
41  return normalization_factor * exp(-0.5 * sum);
42 }
43
44 template <typename point_type>
45 double gaussian(const point_type & x, const double mu, const double sigma)
46 {
47  double g = 1;
48  for(int d=0; d<point_type::dims; d++)
49  {
50  g *= gaussian_1D(x.get(d), mu, sigma);
51  }
52  return g;
53 }
54
55
56 #endif //OPENFPM_NUMERICS_GAUSSIAN_HPP
It model an expression expr1 + ... exprn.
Definition: sum.hpp:92