Exponential Distribution#
statista.distributions.Exponential
#
Bases: AbstractDistribution
Exponential distribution.
-
The exponential distribution assumes that small values occur more frequently than large values.
-
The probability density function (PDF) of the Exponential distribution is:
\[ f(x; \delta, \beta) = \begin{cases} \frac{1}{\beta} e^{-\frac{x - \delta}{\beta}} & \quad x \geq \delta \\ 0 & \quad x < \delta \end{cases} \] -
The probability density function above uses the location parameter \(\delta\) and the scale parameter \(\beta\) to define the distribution in a standardized form.
- A common parameterization for the exponential distribution is in terms of the rate parameter \(\lambda\), such that \(\lambda = 1 / \beta\).
- The Location Parameter (\(\delta\)): This shifts the starting point of the distribution. The distribution is defined for \(x \geq \delta\).
-
Scale Parameter (\(\beta\)): This determines the spread of the distribution. The rate parameter \(\lambda\) is the inverse of the scale parameter, so \(\lambda = \frac{1}{\beta}\).
-
The cumulative distribution functions.
\[ F(x; \delta, \beta) = \begin{cases} 1 - e^{-\frac{x - \delta}{\beta}} & \quad x \geq \delta \\ 0 & \quad x < \delta \end{cases} \]
Source code in src\statista\distributions\exponential.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
__init__(data=None, parameters=None)
#
Exponential Distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list
|
data time series. |
None
|
parameters
|
dict[str, float]
|
{"loc": val, "scale": val}
|
None
|
Source code in src\statista\distributions\exponential.py
pdf(plot_figure=False, parameters=None, data=None, *args, **kwargs)
#
pdf.
Returns the value of Gumbel's pdf with parameters loc and scale at x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, float]
|
None
|
|
data
|
ndarray
|
array if you want to calculate the pdf for different data than the time series given to the constructor method. default is None. |
None
|
plot_figure
|
bool
|
Default is False. |
False
|
kwargs
|
dict[str, Any]
|
fig_size(tuple): Default is (6, 5). xlabel (str): Default is "Actual data". ylabel (str): Default is "pdf". fontsize (int): Default is 15 |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
pdf |
array
|
probability density function pdf. |
fig |
Figure
|
Figure object. returned only if |
ax |
Axes
|
Axes object. returned only if |
Examples:
>>> import numpy as np
>>> from statista.distributions import Exponential
>>> data = np.loadtxt("examples/data/expo.txt")
>>> parameters = {'loc': 0, 'scale': 2}
>>> expo_dist = Exponential(data, parameters)
>>> _ = expo_dist.pdf(plot_figure=True)
Source code in src\statista\distributions\exponential.py
random(size, parameters=None)
#
Generate Random Variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
size of the random generated sample. |
required |
parameters
|
dict[str, str]
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
random generated data. |
Examples:
- To generate a random sample that follow the gumbel distribution with the parameters loc=0 and scale=1.
-
then we can use the
pdfmethod to plot the pdf of the random data.
Source code in src\statista\distributions\exponential.py
cdf(plot_figure=False, parameters=None, data=None, *args, **kwargs)
#
cdf.
cdf calculates the value of Gumbel's cdf with parameters loc and scale at x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, str]
|
None
|
|
data
|
ndarray
|
array if you want to calculate the cdf for different data than the time series given to the constructor method. default is None. |
None
|
plot_figure
|
bool
|
Default is False. |
False
|
kwargs
|
dict[str, Any]
|
fig_size: [tuple] Default is (6, 5). xlabel (str): Default is "Actual data". ylabel (str): Default is "cdf". fontsize (int): Default is 15. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
cdf |
array
|
probability density function cdf. |
fig |
Figure
|
Figure object is returned only if |
ax |
Axes
|
Axes object is returned only if |
Examples:
>>> import numpy as np
>>> from statista.distributions import Exponential
>>> data = np.loadtxt("examples/data/expo.txt")
>>> parameters = {'loc': 0, 'scale': 2}
>>> expo_dist = Exponential(data, parameters)
>>> _ = expo_dist.cdf(plot_figure=True)
Source code in src\statista\distributions\exponential.py
fit_model(method='mle', obj_func=None, threshold=None, test=True)
#
fit_model.
fit_model estimates the distribution parameter based on MLM (Maximum likelihood method), if an objective function is entered as an input
There are two likelihood functions (L1 and L2), one for values above some threshold (x>=C) and one for the values below (x < C), now the likeliest parameters are those at the max value of multiplication between two functions max(L1*L2).
In this case, the L1 is still the product of multiplication of probability density function's values at xi, but the L2 is the probability that threshold value C will be exceeded (1-F(C)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_func
|
function
|
function to be used to get the distribution parameters. |
None
|
threshold
|
numeric
|
Value you want to consider only the greater values. |
None
|
method
|
str
|
'mle', 'mm', 'lmoments', optimization |
'mle'
|
test
|
bool
|
Default is True |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
param |
list
|
shape, loc, scale parameter of the gumbel distribution in that order. |
Examples:
- Instantiate the
Exponentialclass only with the data. -
Then use the
fit_modelmethod to estimate the distribution parameters. the method takes the method as parameter, the default is 'mle'. thetestparameter is used to perform the Kolmogorov-Smirnov and chisquare test.- You can also use the>>> parameters = expo_dist.fit_model(method="mle", test=True) # doctest: +SKIP -----KS Test-------- Statistic = 0.019 Accept Hypothesis P value = 0.9937026761524456 Out[14]: {'loc': 0.0009, 'scale': 2.0498075} >>> print(parameters) # doctest: +SKIP {'loc': 0, 'scale': 2}lmomentsmethod to estimate the distribution parameters.
Source code in src\statista\distributions\exponential.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
inverse_cdf(cdf=None, parameters=None)
#
Theoretical Estimate.
Theoretical Estimate method calculates the theoretical values based on a given non-exceedance probability
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, str]
|
None
|
|
cdf
|
list
|
cumulative distribution function/ Non-Exceedance probability. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
theoretical value (numeric): Value based on the theoretical distribution |
Examples:
- Instantiate the Exponential class only with the data.
- We will generate a random numbers between 0 and 1 and pass it to the inverse_cdf method as a probabilities to get the data that coresponds to these probabilities based on the distribution.
Source code in src\statista\distributions\exponential.py
ks()
#
Kolmogorov-Smirnov (KS) test.
The smaller the D static, the more likely that the two samples are drawn from the same distribution IF Pvalue < significance level ------ reject
Returns:
| Name | Type | Description |
|---|---|---|
Dstatic |
numeric
|
The smaller the D static the more likely that the two samples are drawn from the same distribution |
Pvalue |
numeric
|
IF Pvalue < significance level ------ reject the null hypothesis |