-
Notifications
You must be signed in to change notification settings - Fork 193
Probability Distribution and Statistical Functions -- Exponential Distribution Module #276
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
Merged
gareth-nx
merged 62 commits into
fortran-lang:master
from
Jim-215-Fisher:Distribution-Exponential
Jan 2, 2022
Merged
Changes from 56 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
8061a1f
initial commit
Jim-215-Fisher 07dbee9
initial commit
Jim-215-Fisher be5db33
initial commit
Jim-215-Fisher 68d99ee
initial commit
Jim-215-Fisher cef48de
Update Makefile.manual
Jim-215-Fisher 5b4b09b
Update CMakeLists.txt
Jim-215-Fisher f1a3de2
Update Makefile.manual
Jim-215-Fisher ae69954
Update index.md
Jim-215-Fisher 8bdaa8c
Delete stdlib_stats_distribution_normal.md
Jim-215-Fisher bd5b66f
Update Makefile.manual
Jim-215-Fisher 85848fc
Add files via upload
Jim-215-Fisher c4ef626
Update Makefile.manual
Jim-215-Fisher 07b1113
Update Makefile.manual
Jim-215-Fisher 292dfa9
Update Makefile.manual
Jim-215-Fisher f72e197
Update Makefile.manual
Jim-215-Fisher 3333365
Update stdlib_stats_distribution_normal.fypp
Jim-215-Fisher 4b429bd
Update Makefile.manual
Jim-215-Fisher 917fe96
Update stdlib_stats_distribution_uniform.fypp
Jim-215-Fisher a70b6d2
Update stdlib_stats_distribution_exponential.md
Jim-215-Fisher 1a5ba93
Delete stdlib_stats_distribution_normal.fypp
Jim-215-Fisher 2f45d19
chg. complex number with kinds
Jim-215-Fisher fc17bbb
chg. complex number with kinds
Jim-215-Fisher dc6e894
Update index.md
Jim-215-Fisher 8465f77
Delete test_distribution_normal.f90
Jim-215-Fisher 5c99c78
Update CMakeLists.txt
Jim-215-Fisher a2447d2
Update Makefile.manual
Jim-215-Fisher e760b8b
remove tabs
Jim-215-Fisher ac9342c
Update stdlib_stats_distribution_exponential.md
Jim-215-Fisher 7eb2c46
Update Makefile.manual
Jim-215-Fisher e484595
Update Makefile.manual
Jim-215-Fisher aa81a50
Update CMakeLists.txt
Jim-215-Fisher 4062389
Update Makefile.manual
Jim-215-Fisher cf10419
Update Makefile.manual
Jim-215-Fisher 91ff3d4
Merge pull request #6 from Jim-215-Fisher/master
Jim-215-Fisher b590e79
Update Makefile.manual
Jim-215-Fisher 4cd7866
Update CMakeLists.txt
Jim-215-Fisher 93b0fc4
Update Makefile.manual
Jim-215-Fisher b53a270
Add files via upload
Jim-215-Fisher fe9aea4
Add files via upload
Jim-215-Fisher 47cd8f3
Update Makefile.manual
Jim-215-Fisher 51be14b
Merge pull request #16 from Jim-215-Fisher/master
Jim-215-Fisher 4298807
Update Makefile.manual
Jim-215-Fisher 1f40ba2
Add files via upload
Jim-215-Fisher 82109a1
Update Makefile.manual
Jim-215-Fisher 36103e5
Merge branch 'master' into Distribution-Exponential
4b96a77
update the exponential distribution
8531c3d
Merge remote-tracking branch 'upstream/master' into Distribution-Expo…
833c2a7
correct makefile
47e63d2
Update src/stdlib_stats_distribution_exponential.fypp
Jim-215-Fisher b77ec62
Update src/stdlib_stats_distribution_exponential.fypp
Jim-215-Fisher 59280d2
Update src/stdlib_stats_distribution_exponential.fypp
Jim-215-Fisher ff0da26
Update src/stdlib_stats_distribution_exponential.fypp
Jim-215-Fisher 212bc33
convert expon name to exp and some words change
7d64c11
Merge remote-tracking branch 'origin/master' into Distribution-Expone…
c0784e4
Merge'Exponential-1' into Exponential
d802eb8
Merge remote-tracking branch 'upstream/master' into Distribution-Expo…
8c9fff1
Update doc/specs/stdlib_stats_distribution_exponential.md
Jim-215-Fisher 93655f6
Update doc/specs/stdlib_stats_distribution_exponential.md
Jim-215-Fisher 18cc7ae
Update doc/specs/stdlib_stats_distribution_exponential.md
Jim-215-Fisher a330f31
Update doc/specs/stdlib_stats_distribution_exponential.md
Jim-215-Fisher db5c109
Update src/stdlib_stats_distribution_exponential.fypp
Jim-215-Fisher 15dd737
minor wording change
Jim-215-Fisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_exp` - exponential distribution random variates | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
An exponential distribution is the distribution of time between events in a Poisson point process. The inverse scale parameter `lambda` specifies the average time between events, also called the rate of events. | ||
|
||
Without argument the function returns a random sample from the standard exponential distribution `E(1)` with `lambda = 1`. | ||
|
||
With single argument, the function returns a random sample from the exponential distribution `E(lambda)`. For complex arguments, the real and imaginary parts are independent of each other. | ||
|
||
With two arguments the function returns a rank one array of exponentially distributed random variates. | ||
|
||
Note: the algorithm used for generating exponetial random variates is fundamentally limited to double precision. Ref.: Marsaglia, G. & Tsang, W.W. (2000) `The ziggurat method for generating random variables', J. Statist. Software, v5(8). | ||
|
||
### Syntax | ||
|
||
`result = [[stdlib_stats_distribution_exponential(module):rvs_exp(interface)]]([lambda] [[, array_size]])` | ||
|
||
### Class | ||
|
||
Function | ||
|
||
### Arguments | ||
|
||
`lambda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`. The value of `lambda` has to be non-negative. | ||
|
||
`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_exp | ||
|
||
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_exp` - 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 a 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): | ||
Jim-215-Fisher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$$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_exp(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_exp, & | ||
rexp => rvs_exp | ||
|
||
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_exp` - exponential distribution cumulative distribution function | ||
Jim-215-Fisher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 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 a 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): | ||
Jim-215-Fisher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$$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_exp(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_exp, & | ||
rexp => rvs_exp | ||
|
||
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 | ||
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.