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 e7984cb

Browse files
reintroduced old interface through wrappers and updated specs
1 parent 43f88eb commit e7984cb

File tree

6 files changed

+399
-104
lines changed

6 files changed

+399
-104
lines changed

‎doc/specs/stdlib_stats_distribution_exponential.md‎

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ Experimental
1515
### Description
1616

1717
An exponential distribution is the distribution of time between events in a Poisson point process.
18-
The inverse scale parameter `lambda` specifies the average time between events (\(\lambda\)), also called the rate of events.
18+
The inverse `scale` parameter `lambda` specifies the average time between events (\(\lambda\)), also called the rate of events. The location `loc` specifies the value by which the distribution is shifted.
1919

20-
Without argument, the function returns a random sample from the standard exponential distribution \(E(\lambda=1)\).
20+
Without argument, the function returns a random sample from the unshifted standard exponential distribution \(E(\lambda=1)\) or \(E(loc=0, scale=1)\).
2121

22-
With a single argument, the function returns a random sample from the exponential distribution \(E(\lambda=\text{lambda})\).
22+
With a single argument of type `real`, the function returns a random sample from the exponential distribution \(E(\lambda=\text{lambda})\).
2323
For complex arguments, the real and imaginary parts are sampled independently of each other.
2424

25-
With two arguments, the function returns a rank-1 array of exponentially distributed random variates.
25+
With one argument of type `real` and one argument of type `integer`, the function returns a rank-1 array of exponentially distributed random variates for (E(\lambda=\text{lambda})\).
26+
27+
With two arguments of type `real`, the function returns a random sample from the exponential distribution \(E(loc=loc, scale=scale)\).
28+
For complex arguments, the real and imaginary parts are sampled independently of each other.
29+
30+
With two arguments of type `real` and one argument of type `integer`, the function returns a rank-1 array of exponentially distributed random variates for \(E(loc=loc, scale=scale)\).
2631

2732
@note
2833
The algorithm used for generating exponential random variates is fundamentally limited to double precision.[^1]
@@ -31,6 +36,10 @@ The algorithm used for generating exponential random variates is fundamentally l
3136

3237
`result = ` [[stdlib_stats_distribution_exponential(module):rvs_exp(interface)]] `([lambda] [[, array_size]])`
3338

39+
or
40+
41+
`result = ` [[stdlib_stats_distribution_exponential(module):rvs_exp(interface)]] `([loc, scale] [[, array_size]])`
42+
3443
### Class
3544

3645
Elemental function
@@ -40,13 +49,21 @@ Elemental function
4049
`lambda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`.
4150
If `lambda` is `real`, its value must be positive. If `lambda` is `complex`, both the real and imaginary components must be positive.
4251

52+
`loc`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`.
53+
54+
`scale`: optional argument has `intent(in)` and is a positive scalar of type `real` or `complex`.
55+
If `scale` is `real`, its value must be positive. If `scale` is `complex`, both the real and imaginary components must be positive.
56+
4357
`array_size`: optional argument has `intent(in)` and is a scalar of type `integer` with default kind.
4458

4559
### Return value
4660

47-
The result is a scalar or rank-1 array with a size of `array_size`, and the same type as `lambda`.
61+
If `lambda` is passed, the result is a scalar or rank-1 array with a size of `array_size`, and the same type as `lambda`.
4862
If `lambda` is non-positive, the result is `NaN`.
4963

64+
If `loc` and `scale` are passed, the result is a scalar or rank-1 array with a size of `array_size`, and the same type as `scale`.
65+
If `scale` is non-positive, the result is `NaN`.
66+
5067
### Example
5168

5269
```fortran
@@ -69,10 +86,16 @@ For a complex variable \(z=(x + y i)\) with independent real \(x\) and imaginary
6986

7087
$$f(x+\mathit{i}y)=f(x)f(y)=\begin{cases} \lambda_{x} \lambda_{y} e^{-(\lambda_{x} x + \lambda_{y} y)} &x\geqslant 0, y\geqslant 0 \\\\ 0 &\text{otherwise}\end{cases}$$
7188

89+
Instead of of the inverse scale parameter `lambda`, it is possible to pass `loc` and `scale`, where \(scale = \frac{1}{\lambda}\) and `loc` specifies the value by which the distribution is shifted.
90+
7291
### Syntax
7392

7493
`result = ` [[stdlib_stats_distribution_exponential(module):pdf_exp(interface)]] `(x, lambda)`
7594

95+
or
96+
97+
`result = ` [[stdlib_stats_distribution_exponential(module):pdf_exp(interface)]] `(x, loc, scale)`
98+
7699
### Class
77100

78101
Elemental function
@@ -84,11 +107,20 @@ Elemental function
84107
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`.
85108
If `lambda` is `real`, its value must be positive. If `lambda` is `complex`, both the real and imaginary components must be positive.
86109

110+
`loc`: has `intent(in)` and is a scalar of type `real` or `complex`.
111+
112+
`scale`: has `intent(in)` and is a positive scalar of type `real` or `complex`.
113+
If `scale` is `real`, its value must be positive. If `scale` is `complex`, both the real and imaginary components must be positive.
114+
87115
All arguments must have the same type.
88116

89117
### Return value
90118

91-
The result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `lambda` is non-positive, the result is `NaN`.
119+
If `lambda` is passed, the result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `lambda` is non-positive, the result is `NaN`.
120+
121+
122+
If `loc` and `scale` are passed, the result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `scale` is non-positive, the result is `NaN`.
123+
92124

93125
### Example
94126

@@ -112,10 +144,16 @@ For a complex variable \(z=(x + y i)\) with independent real \(x\) and imaginar
112144

113145
$$F(x+\mathit{i}y)=F(x)F(y)=\begin{cases} (1 - e^{-\lambda_{x} x})(1 - e^{-\lambda_{y} y}) &x\geqslant 0, \;\; y\geqslant 0 \\\\ 0 & \text{otherwise} \end{cases}$$
114146

147+
Instead of of the inverse scale parameter `lambda`, it is possible to pass `loc` and `scale`, where \(scale = \frac{1}{\lambda}\) and `loc` specifies the value by which the distribution is shifted.
148+
115149
### Syntax
116150

117151
`result = ` [[stdlib_stats_distribution_exponential(module):cdf_exp(interface)]] `(x, lambda)`
118152

153+
or
154+
155+
`result = ` [[stdlib_stats_distribution_exponential(module):cdf_exp(interface)]] `(x, loc, scale)`
156+
119157
### Class
120158

121159
Elemental function
@@ -127,11 +165,19 @@ Elemental function
127165
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`.
128166
If `lambda` is `real`, its value must be positive. If `lambda` is `complex`, both the real and imaginary components must be positive.
129167

168+
`loc`: has `intent(in)` and is a scalar of type `real` or `complex`.
169+
170+
`scale`: has `intent(in)` and is a positive scalar of type `real` or `complex`.
171+
If `scale` is `real`, its value must be positive. If `scale` is `complex`, both the real and imaginary components must be positive.
172+
130173
All arguments must have the same type.
131174

132175
### Return value
133176

134-
The result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `lambda` is non-positive, the result is `NaN`.
177+
If `lamba` is passed, the result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `lambda` is non-positive, the result is `NaN`.
178+
179+
180+
If `loc` and `scale` are passed, the result is a scalar or an array, with a shape conformable to the arguments, and the same type as the input arguments. If `scale` is non-positive, the result is `NaN`.
135181

136182
### Example
137183

‎example/stats_distribution_exponential/example_exponential_cdf.f90‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ program example_exponential_cdf
1212
seed_put = 1234567
1313
call random_seed(seed_put, seed_get)
1414

15+
! standard exponential cumulative distribution at x=1.0 with lambda=1.0
16+
print *, exp_cdf(1.0, 1.0)
17+
! 0.632120550
18+
1519
! standard exponential cumulative distribution at x=1.0 with loc=0.0, scale=1.0
1620
print *, exp_cdf(1.0, 0.0, 1.0)
1721
! 0.632120550
1822

23+
! cumulative distribution at x=2.0 with lambda=2
24+
print *, exp_cdf(2.0, 2.0)
25+
! 0.981684387
26+
1927
! cumulative distribution at x=2.0 with loc=0.0 and scale=0.5 (equivalent of lambda=2)
2028
print *, exp_cdf(2.0, 0.0, 0.5)
2129
! 0.981684387

‎example/stats_distribution_exponential/example_exponential_pdf.f90‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ program example_exponential_pdf
1212
seed_put = 1234567
1313
call random_seed(seed_put, seed_get)
1414

15-
! probability density at x=1.0 with loc=0 and in standard exponential
15+
! probability density at x=1.0 with lambda=1.0
16+
print *, exp_pdf(1.0, 1.0)
17+
! 0.367879450
18+
19+
! probability density at x=1.0 with loc=0 and scale=1.0
1620
print *, exp_pdf(1.0, 0.0, 1.0)
1721
! 0.367879450
1822

23+
! probability density at x=2.0 with lambda=2.0
24+
print *, exp_pdf(2.0, 2.0)
25+
! 3.66312787E-02
26+
1927
! probability density at x=2.0 with loc=0.0 and scale=0.5 (lambda=2.0)
2028
print *, exp_pdf(2.0, 0.0, 0.5)
2129
! 3.66312787E-02

‎example/stats_distribution_exponential/example_exponential_rvs.f90‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,32 @@ program example_exponential_rvs
99
seed_put = 1234567
1010
call random_seed(seed_put, seed_get)
1111

12-
print *, rexp() !single standard exponential random variate
13-
! 0.358690143
12+
! single standard exponential random variate
13+
print *, rexp()
14+
! 0.358690143
1415

15-
print *, rexp(0.6, 0.2) !exponential random variate with loc=0.6 and scale=0.5 (lambda=2)
16-
! 0.681645989
16+
! exponential random variate with lambda=2
17+
print *, rexp(2.0)
18+
! 0.204114929
1719

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
20+
! exponential random variate with loc=0 and scale=0.5 (lambda=2)
21+
print*, rexp(0.0, 0.5)
22+
! 0.122672431
2123

24+
! exponential random variate with loc=0.6 and scale=0.2 (lambda=5)
25+
print *, rexp(0.6, 0.2)
26+
! 0.681645989
27+
28+
! an array of 10 variates with loc=0.0 and scale=3.0 (lambda=1/3)
29+
print *, rexp(0.0, 3.0, 10)
30+
! 1.36567295 2.62772131 0.362352759 5.47133636 2.13591909
31+
! 0.410784155 5.83882189 6.71128035 1.31730068 1.90963650
32+
33+
! single complex exponential random variate with real part of scale=0.5 (lambda=2.0);
34+
! imagainary part of scale=1.6 (lambda=0.625)
2235
cloc = (0.0, 0.0)
2336
cscale = (0.5, 1.6)
2437
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)
27-
28-
! (0.219550118,1.01847279)
38+
! (0.426896989,2.56968451)
2939

3040
end program example_exponential_rvs

0 commit comments

Comments
(0)

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