-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Probability Distribution and Statistical Functions -- Exponential Distribution Module #276
Changes from 52 commits
8061a1f
07dbee9
be5db33
68d99ee
cef48de
5b4b09b
f1a3de2
ae69954
8bdaa8c
bd5b66f
85848fc
c4ef626
07b1113
292dfa9
f72e197
3333365
4b429bd
917fe96
a70b6d2
1a5ba93
2f45d19
fc17bbb
dc6e894
8465f77
5c99c78
a2447d2
e760b8b
ac9342c
7eb2c46
e484595
aa81a50
4062389
cf10419
91ff3d4
b590e79
4cd7866
93b0fc4
b53a270
fe9aea4
47cd8f3
51be14b
4298807
1f40ba2
82109a1
36103e5
4b96a77
8531c3d
833c2a7
47e63d2
b77ec62
59280d2
ff0da26
212bc33
7d64c11
c0784e4
d802eb8
8c9fff1
93655f6
18cc7ae
a330f31
db5c109
15dd737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
--- | ||
title: stats_distribution_exponential | ||
--- | ||
|
||
# Statistical Distributions -- Exponential Distribution Module | ||
|
||
[TOC] | ||
|
||
## `rvs_expon` - exponential distribution random variates | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider replacing with:
|
||
|
||
Without argument the function returns a standard exponential distributed random variate E(1) with `lambda = 1`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider rephrasing as:
|
||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider replacing with:
|
||
|
||
With two arguments the function returns a rank one array of exponential distributed random variates. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Note: the algorithm used for generating normal random variates is fundamentally limited to double precision. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Also, is this a good point to include a reference to the algorithm (or just a statement about what it is)? |
||
|
||
### Syntax | ||
|
||
`result = [[stdlib_stats_distribution_exponential(module):rvs_expon(interface)]]([lambda] [[, array_size]])` | ||
|
||
### Class | ||
|
||
Function | ||
|
||
### Arguments | ||
|
||
`lambda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose |
||
|
||
`array_size`: optional argument has `intent(in)` and is a scalar of type `integer` with default kind. | ||
|
||
### Return value | ||
|
||
The result is a scalar or rank one array with a size of `array_size`, and as the same type of `lambda`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to finish with "and has the same type as |
||
|
||
### Example | ||
|
||
```fortran | ||
program demo_exponential_rvs | ||
use stdlib_random, only : random_seed | ||
use stdlib_stats_distribution_exponential, only: rexp => rvs_expon | ||
|
||
implicit none | ||
real :: a(2,3,4) | ||
complex :: scale | ||
integer :: seed_put, seed_get | ||
|
||
seed_put = 1234567 | ||
call random_seed(seed_put, seed_get) | ||
|
||
print *, rexp( ) !single standard exponential random variate | ||
|
||
! 0.358690143 | ||
|
||
print *, rexp(2.0) !exponential random variate with lambda=2.0 | ||
|
||
! 0.816459715 | ||
|
||
print *, rexp(0.3, 10) !an array of 10 variates with lambda=0.3 | ||
|
||
! 1.84008647E-02 3.59742008E-02 0.136567295 0.262772143 3.62352766E-02 | ||
! 0.547133625 0.213591918 4.10784185E-02 0.583882213 0.671128035 | ||
|
||
scale = (2.0, 0.7) | ||
print *, rexp(scale) | ||
!single complex exponential random variate with real part of lambda=2.0; | ||
!imagainary part of lambda=0.7 | ||
|
||
! (1.41435969,4.081114382E-02) | ||
|
||
end program demo_exponential_rvs | ||
``` | ||
|
||
## `pdf_expon` - exponential distribution probability density function | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
The probability density function (pdf) of the single real variable exponential distribution: | ||
|
||
$$f(x)=\begin{cases} \lambda e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$ | ||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing 'a', i.e. |
||
|
||
$$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{}$$ | ||
|
||
### Syntax | ||
|
||
`result = [[stdlib_stats_distribution_exponential(module):pdf_expon(interface)]](x, lambda)` | ||
|
||
### Class | ||
|
||
Elemental function | ||
|
||
### Arguments | ||
|
||
`x`: has `intent(in)` and is a scalar of type `real` or `complex`. | ||
|
||
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`. | ||
|
||
All arguments must have the same type. | ||
|
||
### Return value | ||
|
||
The result is a scalar or an array, with a shape conformable to arguments, and as the same type of input arguments. | ||
jvdp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Example | ||
|
||
```fortran | ||
program demo_exponential_pdf | ||
use stdlib_random, only : random_seed | ||
use stdlib_stats_distribution_exponential, only: exp_pdf => pdf_expon, & | ||
rexp => rvs_expon | ||
|
||
implicit none | ||
real :: x(2,3,4),a(2,3,4) | ||
complex :: scale | ||
integer :: seed_put, seed_get | ||
|
||
seed_put = 1234567 | ||
call random_seed(seed_put, seed_get) | ||
|
||
print *, exp_pdf(1.0,1.0) !a probability density at 1.0 in standard expon | ||
|
||
! 0.367879450 | ||
|
||
print *, exp_pdf(2.0,2.0) !a probability density at 2.0 with lambda=2.0 | ||
|
||
! 3.66312787E-02 | ||
|
||
x = reshape(rexp(0.5, 24),[2,3,4]) ! standard expon random variates array | ||
a(:,:,:) = 0.5 | ||
print *, exp_pdf(x, a) ! a rank 3 standard expon probability density | ||
|
||
! 0.457115263 0.451488823 0.492391467 0.485233188 0.446215510 | ||
! 0.401670188 0.485127628 0.316924453 0.418474048 0.483173639 | ||
! 0.307366133 0.285812140 0.448017836 0.426440030 0.403896868 | ||
! 0.334653258 0.410376132 0.485370994 0.333617479 0.263791025 | ||
! 0.249779820 0.457159877 0.495636940 0.482243657 | ||
|
||
scale = (1.0, 2.) | ||
print *, exp_pdf((1.5,1.0), scale) | ||
! a complex expon probability density function at (1.5,1.0) with real part | ||
!of lambda=1.0 and imaginary part of lambda=2.0 | ||
|
||
! 6.03947677E-02 | ||
|
||
end program demo_exponential_pdf | ||
``` | ||
|
||
## `cdf_expon` - exponential distribution cumulative distribution function | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
Cumulative distribution function (cdf) of the single real variable exponential distribution: | ||
|
||
$$F(x)=\begin{cases}1 - e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$ | ||
|
||
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): | ||
|
||
$$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{}$$ | ||
|
||
### Syntax | ||
|
||
`result = [[stdlib_stats_distribution_exponential(module):cdf_expon(interface)]](x, lambda)` | ||
|
||
### Class | ||
|
||
Elemental function | ||
|
||
### Arguments | ||
|
||
`x`: has `intent(in)` and is a scalar of type `real` or `complex`. | ||
|
||
`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`. | ||
|
||
All arguments must have the same type. | ||
|
||
### Return value | ||
|
||
The result is a scalar or an array, with a shape conformable to arguments, and as the same type of input arguments. | ||
jvdp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Example | ||
|
||
```fortran | ||
program demo_exponential_cdf | ||
use stdlib_random, only : random_seed | ||
use stdlib_stats_distribution_exponential, only : exp_cdf => cdf_expon, & | ||
rexp => rvs_expon | ||
|
||
implicit none | ||
real :: x(2,3,4),a(2,3,4) | ||
complex :: scale | ||
integer :: seed_put, seed_get | ||
|
||
seed_put = 1234567 | ||
call random_seed(seed_put, seed_get) | ||
|
||
print *, exp_cdf(1.0, 1.0) ! a standard exponential cumulative at 1.0 | ||
|
||
! 0.632120550 | ||
|
||
print *, exp_cdf(2.0, 2.0) ! a cumulative at 2.0 with lambda=2 | ||
|
||
! 0.981684387 | ||
|
||
x = reshape(rexp(0.5, 24),[2,3,4]) | ||
! standard exponential random variates array | ||
a(:,:,:) = 0.5 | ||
print *, exp_cdf(x, a) ! a rank 3 array of standard exponential cumulative | ||
|
||
! 8.57694745E-02 9.70223546E-02 1.52170658E-02 2.95336246E-02 | ||
! 0.107568979 0.196659625 2.97447443E-02 0.366151094 0.163051903 | ||
! 3.36527228E-02 0.385267735 0.428375721 0.103964329 0.147119939 | ||
! 0.192206264 0.330693483 0.179247737 2.92580128E-02 0.332765043 | ||
! 0.472417951 0.500440359 8.56802464E-02 8.72612000E-03 3.55126858E-02 | ||
|
||
scale = (0.5,1.0) | ||
print *, exp_cdf((0.5,0.5),scale) | ||
!complex exponential cumulative distribution at (0.5,0.5) with real part of | ||
!lambda=0.5 and imaginary part of lambda=1.0 | ||
|
||
! 8.70351046E-02 | ||
|
||
end program demo_exponential_cdf | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit surprised by the term
expon
. could it bervs_exp
? (probably a matter of taste).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If most people like rvs_exp, I can certainly change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I vote for
rvs_exp
. Among other reasons, I think it's consistent with the Fortran intrinsic exponential function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that
rvs_exp
is a good choice.