|
| 1 | +--- |
| 2 | +title: stats_distribution_exponential |
| 3 | +--- |
| 4 | + |
| 5 | +# Statistical Distributions -- Exponential Distribution Module |
| 6 | + |
| 7 | +[TOC] |
| 8 | + |
| 9 | +## `rvs_exp` - exponential distribution random variates |
| 10 | + |
| 11 | +### Status |
| 12 | + |
| 13 | +Experimental |
| 14 | + |
| 15 | +### Description |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | +Without argument the function returns a random sample from the standard exponential distribution `E(1)` with `lambda = 1`. |
| 20 | + |
| 21 | +With a single argument, the function returns a random sample from the exponential distribution `E(lambda)`. |
| 22 | +For complex arguments, the real and imaginary parts are sampled independently of each other. |
| 23 | + |
| 24 | +With two arguments the function returns a rank one array of exponentially distributed random variates. |
| 25 | + |
| 26 | +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). |
| 27 | + |
| 28 | +### Syntax |
| 29 | + |
| 30 | +`result = [[stdlib_stats_distribution_exponential(module):rvs_exp(interface)]]([lambda] [[, array_size]])` |
| 31 | + |
| 32 | +### Class |
| 33 | + |
| 34 | +Function |
| 35 | + |
| 36 | +### Arguments |
| 37 | + |
| 38 | +`lambda`: optional argument has `intent(in)` and is a scalar of type `real` or `complex`. The value of `lambda` has to be non-negative. |
| 39 | + |
| 40 | +`array_size`: optional argument has `intent(in)` and is a scalar of type `integer` with default kind. |
| 41 | + |
| 42 | +### Return value |
| 43 | + |
| 44 | +The result is a scalar or rank one array with a size of `array_size`, and has the same type of `lambda`. |
| 45 | + |
| 46 | +### Example |
| 47 | + |
| 48 | +```fortran |
| 49 | +program demo_exponential_rvs |
| 50 | + use stdlib_random, only : random_seed |
| 51 | + use stdlib_stats_distribution_exponential, only: rexp => rvs_exp |
| 52 | +
|
| 53 | + implicit none |
| 54 | + real :: a(2,3,4) |
| 55 | + complex :: scale |
| 56 | + integer :: seed_put, seed_get |
| 57 | +
|
| 58 | + seed_put = 1234567 |
| 59 | + call random_seed(seed_put, seed_get) |
| 60 | +
|
| 61 | + print *, rexp( ) !single standard exponential random variate |
| 62 | +
|
| 63 | +! 0.358690143 |
| 64 | +
|
| 65 | + print *, rexp(2.0) !exponential random variate with lambda=2.0 |
| 66 | +
|
| 67 | +! 0.816459715 |
| 68 | +
|
| 69 | + print *, rexp(0.3, 10) !an array of 10 variates with lambda=0.3 |
| 70 | +
|
| 71 | +! 1.84008647E-02 3.59742008E-02 0.136567295 0.262772143 3.62352766E-02 |
| 72 | +! 0.547133625 0.213591918 4.10784185E-02 0.583882213 0.671128035 |
| 73 | +
|
| 74 | + scale = (2.0, 0.7) |
| 75 | + print *, rexp(scale) |
| 76 | + !single complex exponential random variate with real part of lambda=2.0; |
| 77 | + !imagainary part of lambda=0.7 |
| 78 | +
|
| 79 | +! (1.41435969,4.081114382E-02) |
| 80 | +
|
| 81 | +end program demo_exponential_rvs |
| 82 | +``` |
| 83 | + |
| 84 | +## `pdf_exp` - exponential distribution probability density function |
| 85 | + |
| 86 | +### Status |
| 87 | + |
| 88 | +Experimental |
| 89 | + |
| 90 | +### Description |
| 91 | + |
| 92 | +The probability density function (pdf) of the single real variable exponential distribution: |
| 93 | + |
| 94 | +$$f(x)=\begin{cases} \lambda e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$ |
| 95 | + |
| 96 | +For a complex variable (x + y i) with independent real x and imaginary y parts, the joint probability density function |
| 97 | +is the product of the corresponding marginal pdf of real and imaginary pdf (for more details, see |
| 98 | +"Probability and Random Processes with Applications to Signal Processing and Communications", 2nd ed., Scott L. Miller and Donald Childers, 2012, p.197): |
| 99 | + |
| 100 | +$$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{}$$ |
| 101 | + |
| 102 | +### Syntax |
| 103 | + |
| 104 | +`result = [[stdlib_stats_distribution_exponential(module):pdf_exp(interface)]](x, lambda)` |
| 105 | + |
| 106 | +### Class |
| 107 | + |
| 108 | +Elemental function |
| 109 | + |
| 110 | +### Arguments |
| 111 | + |
| 112 | +`x`: has `intent(in)` and is a scalar of type `real` or `complex`. |
| 113 | + |
| 114 | +`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`. |
| 115 | + |
| 116 | +All arguments must have the same type. |
| 117 | + |
| 118 | +### Return value |
| 119 | + |
| 120 | +The result is a scalar or an array, with a shape conformable to arguments, and has the same type of input arguments. |
| 121 | + |
| 122 | +### Example |
| 123 | + |
| 124 | +```fortran |
| 125 | +program demo_exponential_pdf |
| 126 | + use stdlib_random, only : random_seed |
| 127 | + use stdlib_stats_distribution_exponential, only: exp_pdf => pdf_exp, & |
| 128 | + rexp => rvs_exp |
| 129 | +
|
| 130 | + implicit none |
| 131 | + real :: x(2,3,4),a(2,3,4) |
| 132 | + complex :: scale |
| 133 | + integer :: seed_put, seed_get |
| 134 | +
|
| 135 | + seed_put = 1234567 |
| 136 | + call random_seed(seed_put, seed_get) |
| 137 | +
|
| 138 | + print *, exp_pdf(1.0,1.0) !a probability density at 1.0 in standard expon |
| 139 | +
|
| 140 | +! 0.367879450 |
| 141 | +
|
| 142 | + print *, exp_pdf(2.0,2.0) !a probability density at 2.0 with lambda=2.0 |
| 143 | +
|
| 144 | +! 3.66312787E-02 |
| 145 | +
|
| 146 | + x = reshape(rexp(0.5, 24),[2,3,4]) ! standard expon random variates array |
| 147 | + a(:,:,:) = 0.5 |
| 148 | + print *, exp_pdf(x, a) ! a rank 3 standard expon probability density |
| 149 | +
|
| 150 | +! 0.457115263 0.451488823 0.492391467 0.485233188 0.446215510 |
| 151 | +! 0.401670188 0.485127628 0.316924453 0.418474048 0.483173639 |
| 152 | +! 0.307366133 0.285812140 0.448017836 0.426440030 0.403896868 |
| 153 | +! 0.334653258 0.410376132 0.485370994 0.333617479 0.263791025 |
| 154 | +! 0.249779820 0.457159877 0.495636940 0.482243657 |
| 155 | +
|
| 156 | + scale = (1.0, 2.) |
| 157 | + print *, exp_pdf((1.5,1.0), scale) |
| 158 | + ! a complex expon probability density function at (1.5,1.0) with real part |
| 159 | + !of lambda=1.0 and imaginary part of lambda=2.0 |
| 160 | +
|
| 161 | +! 6.03947677E-02 |
| 162 | +
|
| 163 | +end program demo_exponential_pdf |
| 164 | +``` |
| 165 | + |
| 166 | +## `cdf_exp` - exponential cumulative distribution function |
| 167 | + |
| 168 | +### Status |
| 169 | + |
| 170 | +Experimental |
| 171 | + |
| 172 | +### Description |
| 173 | + |
| 174 | +Cumulative distribution function (cdf) of the single real variable exponential distribution: |
| 175 | + |
| 176 | +$$F(x)=\begin{cases}1 - e^{-\lambda x} &x\geqslant 0 \\\\ 0 &x< 0\end{}$$ |
| 177 | + |
| 178 | +For a complex variable (x + y i) with independent real x and imaginary y parts, the joint cumulative distribution |
| 179 | +function is the product of corresponding marginal cdf of real and imaginary cdf (for more details, see |
| 180 | +"Probability and Random Processes with Applications to Signal Processing and Communications", 2nd ed., Scott L. Miller and Donald Childers, 2012, p.197): |
| 181 | + |
| 182 | +$$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{}$$ |
| 183 | + |
| 184 | +### Syntax |
| 185 | + |
| 186 | +`result = [[stdlib_stats_distribution_exponential(module):cdf_exp(interface)]](x, lambda)` |
| 187 | + |
| 188 | +### Class |
| 189 | + |
| 190 | +Elemental function |
| 191 | + |
| 192 | +### Arguments |
| 193 | + |
| 194 | +`x`: has `intent(in)` and is a scalar of type `real` or `complex`. |
| 195 | + |
| 196 | +`lambda`: has `intent(in)` and is a scalar of type `real` or `complex`. |
| 197 | + |
| 198 | +All arguments must have the same type. |
| 199 | + |
| 200 | +### Return value |
| 201 | + |
| 202 | +The result is a scalar or an array, with a shape conformable to arguments, and has the same type of input arguments. |
| 203 | + |
| 204 | +### Example |
| 205 | + |
| 206 | +```fortran |
| 207 | +program demo_exponential_cdf |
| 208 | + use stdlib_random, only : random_seed |
| 209 | + use stdlib_stats_distribution_exponential, only : exp_cdf => cdf_exp, & |
| 210 | + rexp => rvs_exp |
| 211 | +
|
| 212 | + implicit none |
| 213 | + real :: x(2,3,4),a(2,3,4) |
| 214 | + complex :: scale |
| 215 | + integer :: seed_put, seed_get |
| 216 | +
|
| 217 | + seed_put = 1234567 |
| 218 | + call random_seed(seed_put, seed_get) |
| 219 | +
|
| 220 | + print *, exp_cdf(1.0, 1.0) ! a standard exponential cumulative at 1.0 |
| 221 | +
|
| 222 | +! 0.632120550 |
| 223 | +
|
| 224 | + print *, exp_cdf(2.0, 2.0) ! a cumulative at 2.0 with lambda=2 |
| 225 | +
|
| 226 | +! 0.981684387 |
| 227 | +
|
| 228 | + x = reshape(rexp(0.5, 24),[2,3,4]) |
| 229 | + ! standard exponential random variates array |
| 230 | + a(:,:,:) = 0.5 |
| 231 | + print *, exp_cdf(x, a) ! a rank 3 array of standard exponential cumulative |
| 232 | +
|
| 233 | +! 8.57694745E-02 9.70223546E-02 1.52170658E-02 2.95336246E-02 |
| 234 | +! 0.107568979 0.196659625 2.97447443E-02 0.366151094 0.163051903 |
| 235 | +! 3.36527228E-02 0.385267735 0.428375721 0.103964329 0.147119939 |
| 236 | +! 0.192206264 0.330693483 0.179247737 2.92580128E-02 0.332765043 |
| 237 | +! 0.472417951 0.500440359 8.56802464E-02 8.72612000E-03 3.55126858E-02 |
| 238 | +
|
| 239 | + scale = (0.5,1.0) |
| 240 | + print *, exp_cdf((0.5,0.5),scale) |
| 241 | + !complex exponential cumulative distribution at (0.5,0.5) with real part of |
| 242 | + !lambda=0.5 and imaginary part of lambda=1.0 |
| 243 | +
|
| 244 | +! 8.70351046E-02 |
| 245 | +
|
| 246 | +end program demo_exponential_cdf |
| 247 | +
|
| 248 | +``` |
0 commit comments