1 | /** |
---|
2 | * log normal function |
---|
3 | */ |
---|
4 | |
---|
5 | #include "logNormal.h" |
---|
6 | #include <math.h> |
---|
7 | #include <stdio.h> |
---|
8 | #include <stdlib.h> |
---|
9 | |
---|
10 | |
---|
11 | /** |
---|
12 | * Function to evaluate 1D Log normal function. |
---|
13 | * The function is normalized to the 'scale' parameter. |
---|
14 | * |
---|
15 | * f(x)=scale * 1/(sigma*math.sqrt(2pi))e^(-1/2*((math.log(x)-mu)/sigma)^2) |
---|
16 | * |
---|
17 | * @param pars: parameters of the log normal |
---|
18 | * @param x: x-value |
---|
19 | * @return: function value |
---|
20 | */ |
---|
21 | double logNormal_analytical_1D(LogNormalParameters *pars, double x) { |
---|
22 | double sigma2 = pow(pars->sigma, 2); |
---|
23 | return pars->scale / (x*sigma2) * exp( -pow((log(x) -pars->center), 2) / (2*sigma2)); |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * Function to evaluate 2D log normal function |
---|
28 | * The function is normalized to the 'scale' parameter. |
---|
29 | * |
---|
30 | * f(x,y) = LogNormal(x) * Lognormal(y) |
---|
31 | * |
---|
32 | * where both Gaussians share the same parameters. |
---|
33 | * |
---|
34 | * @param pars: parameters of the log normal |
---|
35 | * @param x: x-value |
---|
36 | * @param y: y-value |
---|
37 | * @return: function value |
---|
38 | */ |
---|
39 | double logNormal_analytical_2DXY(LogNormalParameters *pars, double x, double y) { |
---|
40 | return logNormal_analytical_1D(pars, x) * logNormal_analytical_1D(pars, y); |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Function to evaluate 2D log normal function |
---|
45 | * The function is normalized to the 'scale' parameter. |
---|
46 | * |
---|
47 | * f(x,y) = Lognormal(x) * Lognormal(y) |
---|
48 | * |
---|
49 | * where both log normal s share the same parameters. |
---|
50 | * |
---|
51 | * @param pars: parameters of the log normal |
---|
52 | * @param length: length of the (x,y) vector |
---|
53 | * @param phi: angle relative to x |
---|
54 | * @return: function value |
---|
55 | */ |
---|
56 | double logNormal_analytical_2D(LogNormalParameters *pars, double length, double phi) { |
---|
57 | return logNormal_analytical_2DXY(pars, length*cos(phi), length*sin(phi)); |
---|
58 | } |
---|