Skip to content
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 -- Beta Distribution Module #286

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
edf8e54
change in Makefile.manual
Jim-215-Fisher Oct 18, 2020
2a495ab
Add files via upload
Jim-215-Fisher Dec 22, 2020
8e95e05
Add files via upload
Jim-215-Fisher Dec 22, 2020
3d8e3e6
Add files via upload
Jim-215-Fisher Dec 22, 2020
7d4fc50
initial commit
Jim-215-Fisher Dec 29, 2020
8ef3516
initial commit
Jim-215-Fisher Dec 29, 2020
b7af23c
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
f5d37c8
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
d5c2e0b
initial commit
Jim-215-Fisher Dec 29, 2020
734ab02
initial commit
Jim-215-Fisher Dec 29, 2020
67a5093
initial commit
Jim-215-Fisher Dec 29, 2020
229ec35
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
25dce48
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
e779c56
initial commit
Jim-215-Fisher Dec 29, 2020
fe4eb31
Update index.md
Jim-215-Fisher Dec 29, 2020
8e3b715
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
17013cd
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
afb881e
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
8abb168
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
a16faec
Merge pull request #2 from fortran-lang/master
Jim-215-Fisher Dec 29, 2020
157dba8
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
d7643cb
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
5651f5e
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
5afcba5
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
4cb0041
Update CMakeLists.txt
Jim-215-Fisher Dec 29, 2020
91c1ad4
Update Makefile.manual
Jim-215-Fisher Dec 29, 2020
04dbbd0
Update CMakeLists.txt
Jim-215-Fisher Dec 31, 2020
3e42dc9
Update Makefile.manual
Jim-215-Fisher Dec 31, 2020
55d3fb6
Merge pull request #8 from Jim-215-Fisher/master
Jim-215-Fisher Dec 31, 2020
4619081
Update Makefile.manual
Jim-215-Fisher Dec 31, 2020
e6c80b8
Update CMakeLists.txt
Jim-215-Fisher Jan 1, 2021
3a6f26f
Merge pull request #9 from fortran-lang/master
Jim-215-Fisher Jan 19, 2021
3e89cdc
Update Makefile.manual
Jim-215-Fisher Jan 21, 2021
349d0eb
Merge pull request #14 from fortran-lang/master
Jim-215-Fisher Jan 21, 2021
c7cf916
Update CMakeLists.txt
Jim-215-Fisher Jan 22, 2021
ba70104
Update CMakeLists.txt
Jim-215-Fisher Jan 22, 2021
1a81a48
Update CMakeLists.txt
Jim-215-Fisher Jan 22, 2021
bc1e8a8
Update Makefile.manual
Jim-215-Fisher Jan 22, 2021
3a2caff
Merge pull request #19 from Jim-215-Fisher/master
Jim-215-Fisher Jan 22, 2021
f2c07ce
Update Makefile.manual
Jim-215-Fisher Jan 22, 2021
0741c17
Add files via upload
Jim-215-Fisher Jan 22, 2021
2358f4e
Add files via upload
Jim-215-Fisher Jan 22, 2021
7a5e9ea
Update CMakeLists.txt
Jim-215-Fisher Jan 22, 2021
c1f87bc
Update Makefile.manual
Jim-215-Fisher Jan 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/specs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This is and index/directory of the specifications (specs) for each new module/fe
- [optval](./stdlib_optval.html) - Fallback value for optional arguments
- [quadrature](./stdlib_quadrature.html) - Numerical integration
- [stats](./stdlib_stats.html) - Descriptive Statistics
- [stats_distribution_beta](./stdlib_stats_distribution_beta.html) - Beta Distribution


## Missing specs

Expand Down
243 changes: 243 additions & 0 deletions doc/specs/stdlib_stats_distribution_beta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
---

title: stats_distribution
---

# Statistical Distributions -- Beta Distribution Module

[TOC]

## `beta_distribution_rvs` - beta distribution random variates

### Status

Experimental

### Description

With two auguments for shape parameters a>0, b>0, the function returns a beta distributed random variate Beta(a,b), also known as the beta distribution of the first kind. The function is elemental. For complex auguments, the real and imaginary parts are independent of each other.

With three auguments, the function return a rank one array of beta distributed random variate Beta(a, b).

### Syntax

`result = [[stdlib_stats_distribution_beta(module):beta_distribution_rvs(interface)]](a, b [, array_size])`

### Arguments

`a` : has `intent(in)` ans is a scalar of type `real` or `complex`.

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

`array_size`: optional argument has `intent(in)` and is a scalar of type `integer`.

### Return value

The result is a scalar or rank one array, with a size of `array_size`, of type `real` or `complex`.

### Example

```fortran
program demo_beta_rvs
use stdlib_stats_distribution_PRNG, only : random_seed
use stdlib_stats_distribution_beta, only: rbeta => beta_distribution_rvs

implicit none
real :: aa(2,3,4), bb(2,3,4)
complex :: a, b
integer :: put, get

put = 1234567
call random_seed(put, get)

print *, rbeta(0.5, 2.0)
!single standard beta random variate with shape a=0.5, b=2.0

! 3.38860527E-02

print *, rbeta(3.0,2.0) !beta random variate with a=3.0, b=2.0

! 0.570277154

aa(:,:,:) = 0.8; bb(:,:,:)=0.6
print *, rbeta(aa, bb)
!a rank 3 array of 24 beta random variates with a=0.8, b=0.6

! 0.251766384 0.578202426 0.539138556 0.210130826 0.908130825
! 0.880996943 9.49194748E-03 0.945992589 0.290732056 0.803920329
! 7.64303207E-02 0.943150401 0.927998245 0.831781328 0.671169102
! 0.983966410 0.289062619 0.801237404 0.891931713 0.897902310
! 0.845606744 1.50359496E-02 0.913162351 0.915781260

print *, rbeta(1.2,0.7,10)
! an array of 10 random variates with a=1.2, b=0.7

! 3.69704030E-02 0.748639643 0.896924615 0.350249082 0.813054740
! 0.448072791 9.39368978E-02 0.475665420 0.567661405 0.893835664

a = (3.0, 4.0)
b = (2.0, 0.7)
print *, rbeta(a, b)
!single complex beta random variate with real part of a = 3.0, b=2.0;
!imagainary part of a=4.0, b=0.7

! (0.730923295,0.878909111)

end program demo_beta_rvs
```

## `beta_distribution_pdf` - beta probability density function

### Status

Experimental

### Description

The probability density function of the continuous beta distribution.

$$f(x)=\frac{x^{a-1}(1-x)^{b-1}}{B(a,b)}; where\; B(a,b)=\frac{\Gamma (a)\Gamma(b)}{\Gamma(a+b)}$$

x is supported in [0, 1]

### Syntax

`result = [[stdlib_stats_distribution_beta(module):beta_distribution_pdf(interface)]](x, a, b)`

### Arguments

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

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

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

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

### Return value

The result is a scalar or an array, with a shape conformable to auguments, of type `real`.

### Example

```fortran
program demo_beta_pdf
use stdlib_stats_distribution_PRNG, onyl : random_seed
use stdlib_stats_distribution_beta, only: rbeta => beta_distribution_rvs,&
beta_pdf => beta_distribution_pdf

implicit none
real :: x(2,3,4),aa(2,3,4),bb(2,3,4)
complex :: a, b
integer :: put, get

put = 1234567
call random_seed(put, get)

print *, beta_pdf(0.65, 1.0, 1.0)
!a probability density at 0.65 with a=1.0, b=1.0

! 1.00000000

aa(:,:,:) = 2.0
bb(:,:,:) = 1.0
x = reshape(rbeta(2.0, 1.0, 24),[2,3,4]) ! beta random variates array
print *, beta_pdf(x,aa,bb) ! a rank 3 beta probability density array

! 1.59333873 1.60591197 1.26951313 0.825298846 1.84633350 0.715566635
! 0.589380264 1.71169996 1.20676148 1.79188335 0.853198409 1.60287392
! 0.818829894 1.05774701 0.608810604 1.40428901 1.45229220 1.92566359
! 1.81786251 1.69419682 1.60652530 1.87064970 1.78721440 0.851465702

a = (1.0, 1.5)
b = (1.0, 2.)
print *, beta_pdf((0.5,0.3), a, b)
! a complex expon probability density function at (1.5,1.0) with real part of
!a=1.0, b=1.0 and imaginary part of a=1.5, b=2.0

! 1.43777180

end program demo_beta_pdf
```

## `beta_distribution_cdf` - beta cumulative distribution function

### Status

Experimental

### Description

Cumulative distribution function of the beta continuous distribution

$$F(x)=\frac{B(x; a, b)}{B(a, b)}; where \; B(x; a, b) = \int_{0}^{x}t^{a-1}(1-t)^{b-1}dt$$

x is supported in [0, 1]

### Syntax

`result = [[stdlib_stats_distribution_beta(module):beta_distribution_cdf(interface)]](x, shape, rate)`

### Arguments

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

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

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

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

### Return value

The result is a scalar of type `real` with a shape conformable to auguments.

### Example

```fortran
program demo_beta_cdf
use stdlib_stats_distribution_PRNG, onyl : random_seed
use stdlib_stats_distribution_beta, only: rbeta => beta_distribution_rvs,&
beta_cdf => beta_distribution_cdf

implicit none
real :: x(2,3,4),aa(2,3,4),bb(2,3,4)
complex :: a, b
integer :: seed_put, seed_get

seed_put = 1234567
call random_seed(seed_put, seed_get)

print *, beta_cdf(0.4, 0.5,1.0)
! a standard beta cumulative at 0.4 with a=0.5, b=1.0

! 0.632455528

print *, beta_cdf(0.8, 1.5,2.0)
! a cumulative at 0.8 with a a=1.5, b=2.0

! 0.930204272

aa(:,:,:) = 2.0
bb(:,:,:) = 3.0
x = reshape(rbeta(2.0, 3.0, 24),[2,3,4])
!beta random variates array with a a=2.0, b=3.0
print *, beta_cdf(x,aa,bb) ! a rank 3 standard beta cumulative array

! 0.671738267 0.630592465 0.557911158 0.157377750 0.808665335
! 8.00214931E-02 0.118469201 0.868274391 0.268321663 0.850062668
! 7.99631923E-02 0.756867588 0.201488778 0.228500694 0.100621507
! 0.412083119 0.480990469 0.831927001 0.791745305 0.654913783
! 0.528246164 0.275093734 0.757254481 0.212538764

a = (.7, 2.1)
b = (0.5,1.0)
print *, beta_cdf((0.5,0.5),a,b)
!complex beta cumulative distribution at (0.5,0.5) with real part of
!a=0.7,b=0.5 and imaginary part of a=2.1,b=1.0

! 9.32183489E-02

end program demo_beta_cdf

```
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ set(fppFiles
stdlib_quadrature.fypp
stdlib_quadrature_trapz.fypp
stdlib_quadrature_simps.fypp
stdlib_stats_distribution_PRNG.fypp
stdlib_stats_distribution_uniform.fypp
stdlib_stats_distribution_normal.fypp
stdlib_stats_distribution_special.fypp
stdlib_stats_distribution_gamma.fypp
stdlib_stats_distribution_beta.fypp
)


Expand Down
37 changes: 36 additions & 1 deletion src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ SRCFYPP =\
stdlib_stats_moment_all.fypp \
stdlib_stats_moment_mask.fypp \
stdlib_stats_moment_scalar.fypp \
stdlib_stats_var.fypp
stdlib_stats_var.fypp \
stdlib_stats_distribution_PRNG.fypp \
stdlib_stats_distribution_uniform.fypp \
stdlib_stats_distribution_normal.fypp \
stdlib_stats_distribution_gamma.fypp \
stdlib_stats_distribution_special.fypp \
stdlib_stats_distribution_beta.fypp

SRC = f18estop.f90 \
stdlib_ascii.f90 \
Expand Down Expand Up @@ -104,3 +110,32 @@ stdlib_stats_var.o: \
stdlib_optval.o \
stdlib_kinds.o \
stdlib_stats.o
stdlib_stats_distribution_PRNG.o: \
stdlib_kinds.o \
stdlib_error.o
stdlib_stats_distribution_uniform.o: \
stdlib_kinds.o \
stdlib_error.o \
stdlib_stats_distribution_PRNG.o
stdlib_stats_distribution_normal.o: \
stdlib_kinds.o \
stdlib_error.o \
stdlib_stats_distribution_PRNG.o \
stdlib_stats_distribution_uniform.o
stdlib_stats_distribution_special.o: \
stdlib_kinds.o \
stdlib_error.o
stdlib_stats_distribution_gamma.o: \
stdlib_kinds.o \
stdlib_error.o \
stdlib_stats_distribution_PRNG.o \
stdlib_stats_distribution_uniform.o \
stdlib_stats_distribution_normal.o \
stdlib_stats_distribution_special.o
stdlib_stats_distribution_beta.o: \
stdlib_kinds.o \
stdlib_error.o \
stdlib_stats_distribution_PRNG.o \
stdlib_stats_distribution_uniform.o \
stdlib_stats_distribution_special.o \
stdlib_stats_distribution_gamma.o
Loading