|
1 | 1 | program example_exponential_pdf
|
2 | 2 | use stdlib_random, only: random_seed
|
3 | 3 | use stdlib_stats_distribution_exponential, only: exp_pdf => pdf_exp, &
|
4 |
| - rexp => rvs_exp |
| 4 | + rexp => rvs_exp |
5 | 5 |
|
6 | 6 | implicit none
|
7 |
| - real :: x(2, 3, 4), a(2, 3, 4) |
| 7 | + real, dimension(2, 3, 4) :: x, lambda |
| 8 | + real :: xsum |
8 | 9 | complex :: scale
|
9 |
| - integer :: seed_put, seed_get |
| 10 | + integer :: seed_put, seed_get, i |
10 | 11 |
|
11 | 12 | seed_put = 1234567
|
12 | 13 | call random_seed(seed_put, seed_get)
|
13 | 14 |
|
14 |
| - print *, exp_pdf(1.0, 1.0) !a probability density at 1.0 in standard expon |
15 |
| - |
16 |
| -! 0.367879450 |
17 |
| - |
18 |
| - print *, exp_pdf(2.0, 2.0) !a probability density at 2.0 with lambda=2.0 |
19 |
| - |
20 |
| -! 3.66312787E-02 |
21 |
| - |
22 |
| - x = reshape(rexp(0.5, 24), [2, 3, 4]) ! standard expon random variates array |
23 |
| - a(:, :, :) = 0.5 |
24 |
| - print *, exp_pdf(x, a) ! a rank 3 standard expon probability density |
25 |
| - |
26 |
| -! 0.457115263 0.451488823 0.492391467 0.485233188 0.446215510 |
27 |
| -! 0.401670188 0.485127628 0.316924453 0.418474048 0.483173639 |
28 |
| -! 0.307366133 0.285812140 0.448017836 0.426440030 0.403896868 |
29 |
| -! 0.334653258 0.410376132 0.485370994 0.333617479 0.263791025 |
30 |
| -! 0.249779820 0.457159877 0.495636940 0.482243657 |
31 |
| - |
| 15 | + ! probability density at x=1.0 in standard exponential |
| 16 | + print *, exp_pdf(1.0, 1.0) |
| 17 | + ! 0.367879450 |
| 18 | + |
| 19 | + ! probability density at x=2.0 with lambda=2.0 |
| 20 | + print *, exp_pdf(2.0, 2.0) |
| 21 | + ! 3.66312787E-02 |
| 22 | + |
| 23 | + ! probability density at x=2.0 with lambda=-1.0 (out of range) |
| 24 | + print *, exp_pdf(2.0, -1.0) |
| 25 | + ! NaN |
| 26 | + |
| 27 | + ! standard exponential random variates array |
| 28 | + x = reshape(rexp(0.5, 24), [2, 3, 4]) |
| 29 | + |
| 30 | + ! a rank-3 exponential probability density |
| 31 | + lambda(:, :, :) = 0.5 |
| 32 | + print *, exp_pdf(x, lambda) |
| 33 | + ! 0.349295378 0.332413018 0.470253497 0.443498343 0.317152828 |
| 34 | + ! 0.208242029 0.443112582 8.07073265E-02 0.245337561 0.436016470 |
| 35 | + ! 7.14025944E-02 5.33841923E-02 0.322308093 0.264558554 0.212898195 |
| 36 | + ! 0.100339092 0.226891592 0.444002301 9.91026312E-02 3.87373678E-02 |
| 37 | + ! 3.11400592E-02 0.349431813 0.482774824 0.432669312 |
| 38 | + |
| 39 | + ! probability density array where lambda<=0.0 for certain elements |
| 40 | + print *, exp_pdf([1.0, 1.0, 1.0], [1.0, 0.0, -1.0]) |
| 41 | + ! 0.367879450 NaN NaN |
| 42 | + |
| 43 | + ! `pdf_exp` is pure and, thus, can be called concurrently |
| 44 | + xsum = 0.0 |
| 45 | + do concurrent (i=1:size(x,3)) |
| 46 | + xsum = xsum + sum(exp_pdf(x(:,:,i), lambda(:,:,i))) |
| 47 | + end do |
| 48 | + print *, xsum |
| 49 | + ! 6.45566940 |
| 50 | + |
| 51 | + ! complex exponential probability density function at (1.5,1.0) with real part |
| 52 | + ! of lambda=1.0 and imaginary part of lambda=2.0 |
32 | 53 | scale = (1.0, 2.)
|
33 | 54 | print *, exp_pdf((1.5, 1.0), scale)
|
34 |
| -! a complex expon probability density function at (1.5,1.0) with real part |
35 |
| -!of lambda=1.0 and imaginary part of lambda=2.0 |
| 55 | + ! 6.03947677E-02 |
36 | 56 |
|
37 |
| -! 6.03947677E-02 |
| 57 | + ! As above, but with lambda%re < 0 |
| 58 | + scale = (-1.0, 2.) |
| 59 | + print *, exp_pdf((1.5, 1.0), scale) |
| 60 | + ! NaN |
38 | 61 |
|
39 | 62 | end program example_exponential_pdf
|
0 commit comments