Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43f88eb

Browse files
modified parameterisation for stats exp dist. procedures
1 parent c14d599 commit 43f88eb

File tree

5 files changed

+193
-170
lines changed

5 files changed

+193
-170
lines changed

‎example/stats_distribution_exponential/example_exponential_cdf.f90‎

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,72 @@ program example_exponential_cdf
44
rexp => rvs_exp
55

66
implicit none
7-
real, dimension(2, 3, 4) :: x, lambda
7+
real, dimension(2, 3, 4) :: x, loc, scale
88
real :: xsum
9-
complex :: scale
9+
complex :: cloc, cscale
1010
integer :: seed_put, seed_get, i
1111

1212
seed_put = 1234567
1313
call random_seed(seed_put, seed_get)
1414

15-
! standard exponential cumulative distribution at x=1.0
16-
print *, exp_cdf(1.0, 1.0)
15+
! standard exponential cumulative distribution at x=1.0 with loc=0.0, scale=1.0
16+
print *, exp_cdf(1.0, 0.0, 1.0)
1717
! 0.632120550
1818

19-
! cumulative distribution at x=2.0 with lambda=2
20-
print *, exp_cdf(2.0, 2.0)
19+
! cumulative distribution at x=2.0 with loc=0.0 and scale=0.5 (equivalent of lambda=2)
20+
print *, exp_cdf(2.0, 0.0, 0.5)
2121
! 0.981684387
2222

23-
! cumulative distribution at x=2.0 with lambda=-1.0 (out of range)
24-
print *, exp_cdf(2.0, -1.0)
23+
! cumulative distribution at x=2.5 with loc=0.5 and scale=0.5 (equivalent of lambda=2)
24+
print *, exp_cdf(2.5, 0.5, 0.5)
25+
! 0.981684387
26+
27+
! cumulative distribution at x=2.0 with loc=0.0 and scale=-1.0 (out of range)
28+
print *, exp_cdf(2.0, 0.0, -1.0)
2529
! NaN
2630

31+
! cumulative distribution at x=0.5 with loc=1.0 and scale=1.0, putting x below the minimum
32+
print *, exp_cdf(0.5, 1.0, 1.0)
33+
! 0.00000000
34+
2735
! standard exponential random variates array
28-
x = reshape(rexp(0.5, 24), [2, 3, 4])
36+
x = reshape(rexp(0.0, 2.0, 24), [2, 3, 4])
2937

3038
! a rank-3 exponential cumulative distribution
31-
lambda(:, :, :) = 0.5
32-
print *, exp_cdf(x, lambda)
39+
loc(:, :, :) = 0.0
40+
scale(:, :, :) = 2.0
41+
print *, exp_cdf(x, loc, scale)
3342
! 0.301409245 0.335173965 5.94930053E-02 0.113003314
3443
! 0.365694344 0.583515942 0.113774836 0.838585377
3544
! 0.509324908 0.127967060 0.857194781 0.893231630
3645
! 0.355383813 0.470882893 0.574203610 0.799321830
3746
! 0.546216846 0.111995399 0.801794767 0.922525287
38-
! 0.937719882 0.301136374 3.44503522E-02 0.134661376
47+
! 0.937719882 0.301136374 3.44503522E-02 0.134661376
48+
3949

40-
! cumulative distribution array where lambda<=0.0 for certain elements
41-
print *, exp_cdf([1.0, 1.0, 1.0], [1.0, 0.0, -1.0])
50+
! cumulative distribution array where scale<=0.0 for certain elements
51+
print *, exp_cdf([1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, -1.0])
4252
! 0.632120550 NaN NaN
4353

44-
! `cdf_exp` is pure and, thus, can be called concurrently
54+
! `cdf_exp` is pure and, thus, can be called concurrently
4555
xsum = 0.0
4656
do concurrent (i=1:size(x,3))
47-
xsum = xsum + sum(exp_cdf(x(:,:,i), lambda(:,:,i)))
57+
xsum = xsum + sum(exp_cdf(x(:,:,i), loc(:,:,i), scale(:,:,i)))
4858
end do
4959
print *, xsum
5060
! 11.0886612
5161

52-
! complex exponential cumulative distribution at (0.5,0.5) with real part of
53-
! lambda=0.5 and imaginary part of lambda=1.0
54-
scale = (0.5, 1.0)
55-
print *, exp_cdf((0.5, 0.5), scale)
62+
! complex exponential cumulative distribution at (0.5, 0.0, 2) with real part of
63+
! scale=2 and imaginary part of scale=1.0
64+
cloc = (0.0, 0.0)
65+
cscale = (2, 1.0)
66+
print *, exp_cdf((0.5, 0.5), cloc, cscale)
5667
! 8.70351046E-02
5768

58-
! As above, but with lambda%im < 0
59-
scale = (1.0, -2.0)
60-
print *, exp_cdf((1.5, 1.0), scale)
69+
! As above, but with scale%im < 0
70+
cloc = (0.0, 0.0)
71+
cscale = (1.0, -2.0)
72+
print *, exp_cdf((1.5, 1.0), cloc, cscale)
6173
! NaN
6274

6375
end program example_exponential_cdf

‎example/stats_distribution_exponential/example_exponential_pdf.f90‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,66 @@ program example_exponential_pdf
44
rexp => rvs_exp
55

66
implicit none
7-
real, dimension(2, 3, 4) :: x, lambda
7+
real, dimension(2, 3, 4) :: x, loc, scale
88
real :: xsum
9-
complex :: scale
9+
complex :: cloc, cscale
1010
integer :: seed_put, seed_get, i
1111

1212
seed_put = 1234567
1313
call random_seed(seed_put, seed_get)
1414

15-
! probability density at x=1.0 in standard exponential
16-
print *, exp_pdf(1.0, 1.0)
15+
! probability density at x=1.0 with loc=0 and in standard exponential
16+
print *, exp_pdf(1.0, 0.0, 1.0)
1717
! 0.367879450
1818

19-
! probability density at x=2.0 with lambda=2.0
20-
print *, exp_pdf(2.0, 2.0)
19+
! probability density at x=2.0 with loc=0.0 and scale=0.5 (lambda=2.0)
20+
print *, exp_pdf(2.0, 0.0, 0.5)
2121
! 3.66312787E-02
2222

23-
! probability density at x=2.0 with lambda=-1.0 (out of range)
24-
print *, exp_pdf(2.0, -1.0)
23+
! probability density at x=1.5 with loc=0.5 and scale=0.5 (lambda=2.0)
24+
print *, exp_pdf(2.5, 0.5, 0.5)
25+
! 3.66312787E-02
26+
27+
! probability density at x=2.0 with loc=0.0 and scale=-1.0 (out of range)
28+
print *, exp_pdf(2.0, 0.0, -1.0)
2529
! NaN
2630

27-
! standard exponential random variates array
28-
x = reshape(rexp(0.5, 24), [2, 3, 4])
31+
! standard exponential random variates array
32+
x = reshape(rexp(0.0, 2.0, 24), [2, 3, 4])
2933

3034
! a rank-3 exponential probability density
31-
lambda(:, :, :) = 0.5
32-
print *, exp_pdf(x, lambda)
35+
loc(:, :, :) = 0.0
36+
scale(:, :, :) = 2.0
37+
print *, exp_pdf(x, loc, scale)
3338
! 0.349295378 0.332413018 0.470253497 0.443498343 0.317152828
3439
! 0.208242029 0.443112582 8.07073265E-02 0.245337561 0.436016470
3540
! 7.14025944E-02 5.33841923E-02 0.322308093 0.264558554 0.212898195
3641
! 0.100339092 0.226891592 0.444002301 9.91026312E-02 3.87373678E-02
37-
! 3.11400592E-02 0.349431813 0.482774824 0.432669312
42+
! 3.11400592E-02 0.349431813 0.482774824 0.432669312
3843

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])
44+
! probability density array where scale<=0.0 for certain elements (loc = 0.0)
45+
print *, exp_pdf([1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, -1.0])
4146
! 0.367879450 NaN NaN
4247

43-
! `pdf_exp` is pure and, thus, can be called concurrently
48+
! `pdf_exp` is pure and, thus, can be called concurrently
4449
xsum = 0.0
4550
do concurrent (i=1:size(x,3))
46-
xsum = xsum + sum(exp_pdf(x(:,:,i), lambda(:,:,i)))
51+
xsum = xsum + sum(exp_pdf(x(:,:,i), loc(:,:,i), scale(:,:,i)))
4752
end do
4853
print *, xsum
4954
! 6.45566940
5055

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
53-
scale = (1.0, 2.)
54-
print *, exp_pdf((1.5, 1.0), scale)
56+
! complex exponential probability density function at (1.5, 0.0, 1.0) with real part
57+
! of scale=1.0 and imaginary part of scale=0.5
58+
cloc = (0.0, 0.0)
59+
cscale = (1.0, 0.5)
60+
print *, exp_pdf((1.5, 1.0), cloc, cscale)
5561
! 6.03947677E-02
5662

57-
! As above, but with lambda%re < 0
58-
scale = (-1.0, 2.)
59-
print *, exp_pdf((1.5, 1.0), scale)
63+
! As above, but with scale%re < 0
64+
cloc = (0.0, 0.0)
65+
cscale = (-1.0, 2.0)
66+
print *, exp_pdf((1.5, 1.0), cloc, cscale)
6067
! NaN
6168

6269
end program example_exponential_pdf

‎example/stats_distribution_exponential/example_exponential_rvs.f90‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@ program example_exponential_rvs
33
use stdlib_stats_distribution_exponential, only: rexp => rvs_exp
44

55
implicit none
6-
complex :: scale
6+
complex :: cloc, cscale
77
integer :: seed_put, seed_get
88

99
seed_put = 1234567
1010
call random_seed(seed_put, seed_get)
1111

1212
print *, rexp() !single standard exponential random variate
13-
1413
! 0.358690143
1514

16-
print *, rexp(2.0) !exponential random variate with lambda=2.0
17-
18-
! 0.816459715
19-
20-
print *, rexp(0.3, 10) !an array of 10 variates with lambda=0.3
15+
print *, rexp(0.6, 0.2) !exponential random variate with loc=0.6 and scale=0.5 (lambda=2)
16+
! 0.681645989
2117

22-
! 1.84008647E-02 3.59742008E-02 0.136567295 0.262772143 3.62352766E-02
23-
! 0.547133625 0.213591918 4.10784185E-02 0.583882213 0.671128035
18+
print *, rexp(0.0, 3.0, 10) !an array of 10 variates with loc=0.0 and scale=3.0 (lambda=1/3)
19+
! 0.184008643 0.359742016 1.36567295 2.62772131 0.362352759
20+
! 5.47133636 2.13591909 0.410784155 5.83882189 6.71128035
2421

25-
scale = (2.0, 0.7)
26-
print *, rexp(scale)
27-
!single complex exponential random variate with real part of lambda=2.0;
28-
!imagainary part of lambda=0.7
22+
cloc = (0.0, 0.0)
23+
cscale = (0.5, 1.6)
24+
print *, rexp(cloc, cscale)
25+
!single complex exponential random variate with real part of scale=0.5 (lambda=2.0);
26+
!imagainary part of scale=1.6 (lambda=0.625)
2927

30-
! (1.41435969,4.081114382E-02)
28+
! (0.219550118,1.01847279)
3129

3230
end program example_exponential_rvs

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /