Skip to content

Commit 4b96a77

Browse files
author
jim-215-fisher
committed
update the exponential distribution
1 parent 36103e5 commit 4b96a77

9 files changed

+494
-755
lines changed

doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
2626
- [stats](./stdlib_stats.html) - Descriptive Statistics
2727
- [stats_distributions_uniform](./stdlib_stats_distribution_uniform.html) - Uniform Probability Distribution
2828
- [stats_distributions_normal](./stdlib_stats_distribution_normal.html) - Normal Probability Distribution
29+
- [stats_distributions_exponential](./stdlib_stats_distribution_exponential.html) - Exponential Probability Distribution
2930
- [string\_type](./stdlib_string_type.html) - Basic string support
3031
- [strings](./stdlib_strings.html) - String handling and manipulation routines
3132
- [stringlist_type](./stdlib_stringlist_type.html) - 1-Dimensional list of strings

doc/specs/stdlib_stats_distribution_exponential.md

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
11
---
2-
title: stats_distribution
2+
title: stats_distribution_exponential
33
---
44

5-
# Statistical Distributions -- Exponential Module
5+
# Statistical Distributions -- Exponential Distribution Module
66

77
[TOC]
88

9-
## `exponential_distribution_rvs` - exponential distribution random variates
9+
## `rvs_expon` - exponential distribution random variates
1010

1111
### Status
1212

1313
Experimental
1414

1515
### Description
1616

17-
An exponentially distributed random variate distribution is the distribution of time between events in a Poisson point process. The inverse scale parameter `lamda` specifies the rate of change.
17+
An exponentially distributed random variate distribution is the distribution of time between events in a Poisson point process. The inverse scale parameter `lambda` specifies the rate of change.
1818

19-
Without augument the function returns a standard exponential distributed random variate with `lamda = 1.0`. The function is elemental.
19+
Without argument the function returns a standard exponential distributed random variate E(1) with `lambda = 1`.
2020

21-
With single argument, the function returns an exponential distributed random variate E(lamda). The function is elemental. For complex auguments, the real and imaginary parts are independent of each other.
21+
With single argument, the function returns an exponential distributed random variate E(lambda). For complex arguments, the real and imaginary parts are independent of each other.
2222

23-
With two auguments the function returns a rank one array of random variates.
23+
With two arguments the function returns a rank one array of exponential distributed random variates.
24+
25+
Note: the algorithm used for generating normal random variates is fundamentally limited to double precision.
2426

2527
### Syntax
2628

27-
`result = [[stdlib_stats_distribution_exponential(module):exponential_distribution_rvs(interface)]]([lamda] [[, array_size]])`
29+
`result = [[stdlib_stats_distribution_exponential(module):rvs_expon(interface)]]([lambda] [[, array_size]])`
30+
31+
### Class
32+
33+
Function
2834

2935
### Arguments
3036

31-
`lamda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`.
37+
`lambda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`.
3238

33-
`array_size`: optional argument has `intent(in)` and is a scalar of type `integer`.
39+
`array_size`: optional argument has `intent(in)` and is a scalar of type `integer` with default kind.
3440

3541
### Return value
3642

37-
The result is a scalar or rank one array, with a size of `array_size`, of type `real` or `complex`.
43+
The result is a scalar or rank one array with a size of `array_size`, and as the same type of `lambda`.
3844

3945
### Example
4046

4147
```fortran
4248
program demo_exponential_rvs
43-
use stdlib_stats_distribution_PRNG, only : random_seed
44-
use stdlib_stats_distribution_exponential, only: &
45-
rexp => exponential_distribution_rvs
49+
use stdlib_random, only : random_seed
50+
use stdlib_stats_distribution_exponential, only: rexp => rvs_expon
4651
4752
implicit none
4853
real :: a(2,3,4)
@@ -56,70 +61,68 @@ program demo_exponential_rvs
5661
5762
! 0.358690143
5863
59-
print *, rexp(2.0) !exponential random variate with lamda=2.0
64+
print *, rexp(2.0) !exponential random variate with lambda=2.0
6065
6166
! 0.816459715
6267
63-
print *, rexp(0.3, 10) !an array of 10 variates with lamda=0.3
68+
print *, rexp(0.3, 10) !an array of 10 variates with lambda=0.3
6469
6570
! 1.84008647E-02 3.59742008E-02 0.136567295 0.262772143 3.62352766E-02
6671
! 0.547133625 0.213591918 4.10784185E-02 0.583882213 0.671128035
6772
68-
a(:,:,:) = 0.5
69-
print *, rexp(a) !a rank 3 array of 24 exponential random variates
70-
71-
! 0.219550118 0.318272740 0.426896989 0.803026378 0.395067871
72-
! 5.93891777E-02 0.809226036 1.27890170 1.38805652 0.179149821
73-
! 1.75288841E-02 7.23171830E-02 0.157068044 0.153069839 0.421180248
74-
! 0.517792642 2.09411430 0.785641313 0.116311245 0.295113146
75-
! 0.824005902 0.123385273 5.50238751E-02 3.52851897E-02
76-
7773
scale = (2.0, 0.7)
7874
print *, rexp(scale)
79-
!single complex exponential random variate with real part of lamda=2.0;
80-
!imagainary part of lamda=0.7
75+
!single complex exponential random variate with real part of lambda=2.0;
76+
!imagainary part of lambda=0.7
8177
8278
! (1.41435969,4.081114382E-02)
8379
8480
end program demo_exponential_rvs
8581
```
8682

87-
## `exponential_distribution_pdf` - exponential probability density function
83+
## `pdf_expon` - exponential distribution probability density function
8884

8985
### Status
9086

9187
Experimental
9288

9389
### Description
9490

95-
The probability density function of the continuous exponential distribution.
91+
The probability density function (pdf) of the single real variable exponential distribution:
92+
93+
$$f(x)=\begin{cases} \lambda e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$
9694

97-
$$ f(x)=\begin{cases}lamda \times e^{-lamda \times x} &x\geqslant 0 \\\\ 0 &x< 0\end{} $$
95+
For complex varible (x + y i) with independent real x and imaginary y parts, the joint probability density function is the product of corresponding marginal pdf of real and imaginary pdf (ref. "Probability and Random Processes with Applications to Signal Processing and Communications", 2nd ed., Scott L. Miller and Donald Childers, 2012, p.197):
96+
97+
$$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 &otherwise\end{}$$
9898

9999
### Syntax
100100

101-
`result = [[stdlib_stats_distribution_exponential(module):exponential_distribution_pdf(interface)]](x, lamda)`
101+
`result = [[stdlib_stats_distribution_exponential(module):pdf_expon(interface)]](x, lambda)`
102+
103+
### Class
104+
105+
Elemental function
102106

103107
### Arguments
104108

105109
`x`: has `intent(in)` and is a scalar of type `real` or `complex`.
106110

107-
`lamda`: has `intent(in)` and is a scalar of type `real` or `complex`.
111+
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`.
108112

109-
The function is elemental, i.e., all auguments could be arrays conformable to each other. All arguments must have the same type.
113+
All arguments must have the same type.
110114

111115
### Return value
112116

113-
The result is a scalar or an array, with a shape conformable to auguments, of type `real`.
117+
The result is a scalar or an array, with a shape conformable to arguments, and as the same type of input arguments.
114118

115119
### Example
116120

117121
```fortran
118122
program demo_exponential_pdf
119-
use stdlib_stats_distribution_PRNG, only : random_seed
120-
use stdlib_stats_distribution_exponential, only: &
121-
exp_pdf => exponential_distribution_pdf, &
122-
rexp => exponential_distribution_rvs
123+
use stdlib_random, only : random_seed
124+
use stdlib_stats_distribution_exponential, only: exp_pdf => pdf_expon, &
125+
rexp => rvs_expon
123126
124127
implicit none
125128
real :: x(2,3,4),a(2,3,4)
@@ -133,7 +136,7 @@ program demo_exponential_pdf
133136
134137
! 0.367879450
135138
136-
print *, exp_pdf(2.0,2.0) !a probability density at 2.0 with lamda=2.0
139+
print *, exp_pdf(2.0,2.0) !a probability density at 2.0 with lambda=2.0
137140
138141
! 3.66312787E-02
139142
@@ -150,50 +153,56 @@ program demo_exponential_pdf
150153
scale = (1.0, 2.)
151154
print *, exp_pdf((1.5,1.0), scale)
152155
! a complex expon probability density function at (1.5,1.0) with real part
153-
!of lamda=1.0 and imaginary part of lamda=2.0
156+
!of lambda=1.0 and imaginary part of lambda=2.0
154157
155158
! 6.03947677E-02
156159
157160
end program demo_exponential_pdf
158161
```
159162

160-
## `exponential_distribution_cdf` - exponential cumulative distribution function
163+
## `cdf_expon` - exponential distribution cumulative distribution function
161164

162165
### Status
163166

164167
Experimental
165168

166169
### Description
167170

168-
Cumulative distribution function of the exponential continuous distribution
171+
Cumulative distribution function (cdf) of the single real variable exponential distribution:
169172

170-
$$ F(x)=\begin{cases}1 - e^{-lamda \times x} &x\geqslant 0 \\\\ 0 &x< 0\end{} $$
173+
$$F(x)=\begin{cases}1 - e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$
171174

175+
For the complex variable (x + y i) with independent real x and imaginary y parts, the joint cumulative distribution function is the product of corresponding marginal cdf of real and imaginary cdf (ref. "Probability and Random Processes with Applications to Signal Processing and Communications", 2nd ed., Scott L. Miller and Donald Childers, 2012, p.197):
176+
177+
$$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 &otherwise \end{}$$
172178

173179
### Syntax
174180

175-
`result = [[stdlib_stats_distribution_exponential(module):exponential_distribution_cdf(interface)]](x, lamda)`
181+
`result = [[stdlib_stats_distribution_exponential(module):cdf_expon(interface)]](x, lambda)`
182+
183+
### Class
184+
185+
Elemental function
176186

177187
### Arguments
178188

179189
`x`: has `intent(in)` and is a scalar of type `real` or `complex`.
180190

181-
`lamda`: has `intent(in)` and is a scalar of type `real` or `complex`.
191+
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`.
182192

183-
The function is elemental, i.e., all auguments could be arrays conformable to each other. All arguments must have the same type.
193+
All arguments must have the same type.
184194

185195
### Return value
186196

187-
The result is a scalar or an array, with a shape conformable to auguments, of type `real`.
197+
The result is a scalar or an array, with a shape conformable to arguments, and as the same type of input arguments.
188198

189199
### Example
190200

191201
```fortran
192202
program demo_exponential_cdf
193-
use stdlib_stats_distribution_PRNG, only : random_seed
194-
use stdlib_stats_distribution_exponential, only : &
195-
exp_cdf => exponential_distribution_cdf, &
196-
rexp => exponential_distribution_rvs
203+
use stdlib_random, only : random_seed
204+
use stdlib_stats_distribution_exponential, only : exp_cdf => cdf_expon, &
205+
rexp => rvs_expon
197206
198207
implicit none
199208
real :: x(2,3,4),a(2,3,4)
@@ -207,7 +216,7 @@ program demo_exponential_cdf
207216
208217
! 0.632120550
209218
210-
print *, exp_cdf(2.0, 2.0) ! a cumulative at 2.0 with lamda=2
219+
print *, exp_cdf(2.0, 2.0) ! a cumulative at 2.0 with lambda=2
211220
212221
! 0.981684387
213222
@@ -225,7 +234,7 @@ program demo_exponential_cdf
225234
scale = (0.5,1.0)
226235
print *, exp_cdf((0.5,0.5),scale)
227236
!complex exponential cumulative distribution at (0.5,0.5) with real part of
228-
!lamda=0.5 and imaginary part of lamda=1.0
237+
!lambda=0.5 and imaginary part of lambda=1.0
229238
230239
! 8.70351046E-02
231240

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(fppFiles
3131
stdlib_stats_moment_scalar.fypp
3232
stdlib_stats_distribution_uniform.fypp
3333
stdlib_stats_distribution_normal.fypp
34+
stdlib_stats_distribution_exponential.fypp
3435
stdlib_stats_var.fypp
3536
stdlib_quadrature.fypp
3637
stdlib_quadrature_trapz.fypp

src/Makefile.manual

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SRCFYPP = \
3333
stdlib_stats_moment_scalar.fypp \
3434
stdlib_stats_distribution_uniform.fypp \
3535
stdlib_stats_distribution_normal.fypp \
36+
stdlib_stats_distribution_exponential.fypp \
3637
stdlib_stats_var.fypp \
3738
stdlib_math.fypp \
3839
stdlib_math_linspace.fypp \
@@ -173,6 +174,11 @@ stdlib_stats_distribution_normal.o: \
173174
stdlib_error.o \
174175
stdlib_random.o \
175176
stdlib_stats_distribution_uniform.o
177+
stdlib_stats_distribution_exponential.o: \
178+
stdlib_kinds.o \
179+
stdlib_error.o \
180+
stdlib_random.o \
181+
stdlib_stats_distribution_uniform.o
176182
stdlib_random.o: \
177183
stdlib_kinds.o \
178184
stdlib_error.o

0 commit comments

Comments
 (0)