probability_extra_functions¶
shortfx.fxNumeric.probability_extra_functions
¶
Pure-Python probability distributions not requiring scipy.
Provides PDF/PMF, CDF and basic moments for distributions covered in
Murray R. Spiegel's Mathematical Handbook of Formulas and Tables
that are absent from the scipy-based distribution_functions module:
geometric, Cauchy, uniform (continuous & discrete), Pareto, Bernoulli,
and Maxwell-Boltzmann.
Functions¶
bernoulli_mean(p: float) -> float
¶
Mean of the Bernoulli distribution: E[X] = p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Success probability in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Example
bernoulli_mean(0.7) 0.7
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
bernoulli_pmf(k: int, p: float) -> float
¶
Probability mass function of the Bernoulli distribution.
P(X=k) = p^k (1-p)^(1-k) for k in {0, 1}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Outcome (0 or 1). |
required |
p
|
float
|
Success probability in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
P(X=k). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If k not in {0,1} or p not in [0,1]. |
Example
bernoulli_pmf(1, 0.3) 0.3
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
bernoulli_variance(p: float) -> float
¶
Variance of the Bernoulli distribution: Var(X) = p(1-p).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Success probability in [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Example
bernoulli_variance(0.5) 0.25
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
cauchy_cdf(x: float, x0: float = 0.0, gamma: float = 1.0) -> float
¶
Cumulative distribution function of the Cauchy distribution.
F(x) = (1/π) arctan((x-x0)/γ) + 1/2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
x0
|
float
|
Location parameter. |
0.0
|
gamma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
CDF value at x. |
Example
cauchy_cdf(0) 0.5
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
cauchy_pdf(x: float, x0: float = 0.0, gamma: float = 1.0) -> float
¶
Probability density function of the Cauchy distribution.
f(x) = 1 / (π γ [1 + ((x-x0)/γ)²]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
x0
|
float
|
Location parameter (median). |
0.0
|
gamma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
PDF value at x. |
Example
round(cauchy_pdf(0), 6) 0.318310
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
cauchy_quantile(p: float, x0: float = 0.0, gamma: float = 1.0) -> float
¶
Quantile (inverse CDF) of the Cauchy distribution.
Q(p) = x0 + γ tan(π(p - 1/2)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability in (0, 1). |
required |
x0
|
float
|
Location parameter. |
0.0
|
gamma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Quantile value. |
Example
cauchy_quantile(0.5) 0.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
geometric_cdf(k: int, p: float) -> float
¶
Cumulative distribution function of the geometric distribution.
P(X <= k) = 1 - (1-p)^k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of trials (k >= 1). |
required |
p
|
float
|
Success probability in (0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
P(X <= k). |
Example
geometric_cdf(3, 0.5) 0.875
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
geometric_mean_dist(p: float) -> float
¶
Mean of the geometric distribution: E[X] = 1/p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Success probability in (0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Example
geometric_mean_dist(0.25) 4.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
geometric_pmf(k: int, p: float) -> float
¶
Probability mass function of the geometric distribution.
P(X=k) = (1-p)^(k-1) * p for k = 1, 2, 3, ... (number of trials until first success).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Trial number (k >= 1). |
required |
p
|
float
|
Success probability in (0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
P(X=k). |
Example
round(geometric_pmf(3, 0.5), 4) 0.125
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
geometric_variance_dist(p: float) -> float
¶
Variance of the geometric distribution: Var(X) = (1-p)/p².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Success probability in (0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Example
geometric_variance_dist(0.5) 2.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
log_logistic_cdf(x: float, alpha: float, beta: float) -> float
¶
CDF of the log-logistic distribution.
F(x) = 1 / (1 + (x/α)^(-β)) for x > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
alpha
|
float
|
Scale parameter (> 0). |
required |
beta
|
float
|
Shape parameter (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
CDF value. |
Example
log_logistic_cdf(1, 1, 2) 0.5
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
log_logistic_pdf(x: float, alpha: float, beta: float) -> float
¶
PDF of the log-logistic distribution.
f(x) = (β/α)(x/α)^(β-1) / (1 + (x/α)^β)² for x > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate (> 0). |
required |
alpha
|
float
|
Scale parameter (> 0). |
required |
beta
|
float
|
Shape parameter (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
PDF value. |
Example
round(log_logistic_pdf(1, 1, 2), 4) 0.5
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
maxwell_boltzmann_cdf(x: float, a: float = 1.0) -> float
¶
CDF of the Maxwell-Boltzmann distribution.
F(x) = erf(x/(a√2)) - √(2/π)(x/a) exp(-x²/(2a²)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Speed value (>= 0). |
required |
a
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
CDF value. |
Example
round(maxwell_boltzmann_cdf(1, 1), 6) 0.198748
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
maxwell_boltzmann_mean(a: float = 1.0) -> float
¶
Mean of the Maxwell-Boltzmann distribution: 2a√(2/π).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Example
round(maxwell_boltzmann_mean(1), 6) 1.595769
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
maxwell_boltzmann_pdf(x: float, a: float = 1.0) -> float
¶
PDF of the Maxwell-Boltzmann distribution.
f(x) = √(2/π) x² exp(-x²/(2a²)) / a³ for x >= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Speed value (>= 0). |
required |
a
|
float
|
Scale parameter (> 0), related to √(kT/m). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
PDF value. |
Example
round(maxwell_boltzmann_pdf(1, 1), 6) 0.483941
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
pareto_cdf(x: float, x_m: float, alpha: float) -> float
¶
CDF of the Pareto distribution.
F(x) = 1 - (x_m/x)^α for x >= x_m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
x_m
|
float
|
Scale parameter (> 0). |
required |
alpha
|
float
|
Shape parameter (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
CDF value. |
Example
pareto_cdf(2, 1, 2) 0.75
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
pareto_mean(x_m: float, alpha: float) -> float
¶
Mean of the Pareto distribution: α x_m / (α-1) for α > 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_m
|
float
|
Scale parameter (> 0). |
required |
alpha
|
float
|
Shape parameter (> 1). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alpha <= 1. |
Example
pareto_mean(1, 3) 1.5
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
pareto_pdf(x: float, x_m: float, alpha: float) -> float
¶
PDF of the Pareto distribution.
f(x) = α x_m^α / x^(α+1) for x >= x_m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
x_m
|
float
|
Scale parameter (minimum value, > 0). |
required |
alpha
|
float
|
Shape parameter (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
PDF value. |
Example
pareto_pdf(1, 1, 2) 2.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
pareto_variance(x_m: float, alpha: float) -> float
¶
Variance of the Pareto distribution: x_m² α / ((α-1)²(α-2)) for α > 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_m
|
float
|
Scale parameter (> 0). |
required |
alpha
|
float
|
Shape parameter (> 2). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If alpha <= 2. |
Example
round(pareto_variance(1, 3), 4) 0.75
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
rayleigh_cdf(x: float, sigma: float = 1.0) -> float
¶
CDF of the Rayleigh distribution.
F(x) = 1 - exp(-x²/(2σ²)) for x >= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
sigma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
CDF value. |
Example
round(rayleigh_cdf(1, 1), 6) 0.393469
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
rayleigh_mean(sigma: float = 1.0) -> float
¶
Mean of the Rayleigh distribution: σ√(π/2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Example
round(rayleigh_mean(1), 6) 1.253314
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
rayleigh_pdf(x: float, sigma: float = 1.0) -> float
¶
PDF of the Rayleigh distribution.
f(x) = (x/σ²) exp(-x²/(2σ²)) for x >= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate (>= 0). |
required |
sigma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
PDF value. |
Example
round(rayleigh_pdf(1, 1), 6) 0.606531
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
rayleigh_variance(sigma: float = 1.0) -> float
¶
Variance of the Rayleigh distribution: (4-π)/2 σ².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
Scale parameter (> 0). |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Example
round(rayleigh_variance(1), 6) 0.429204
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_continuous_cdf(x: float, a: float, b: float) -> float
¶
CDF of the continuous uniform distribution U(a, b).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
a
|
float
|
Lower bound. |
required |
b
|
float
|
Upper bound (b > a). |
required |
Returns:
| Type | Description |
|---|---|
float
|
CDF value. |
Example
uniform_continuous_cdf(0.25, 0, 1) 0.25
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_continuous_mean(a: float, b: float) -> float
¶
Mean of U(a, b): (a+b)/2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Lower bound. |
required |
b
|
float
|
Upper bound. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean. |
Example
uniform_continuous_mean(2, 8) 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_continuous_pdf(x: float, a: float, b: float) -> float
¶
PDF of the continuous uniform distribution U(a, b).
f(x) = 1/(b-a) for a <= x <= b, else 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Point to evaluate. |
required |
a
|
float
|
Lower bound. |
required |
b
|
float
|
Upper bound (b > a). |
required |
Returns:
| Type | Description |
|---|---|
float
|
PDF value. |
Example
uniform_continuous_pdf(0.5, 0, 1) 1.0
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_continuous_variance(a: float, b: float) -> float
¶
Variance of U(a, b): (b-a)²/12.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Lower bound. |
required |
b
|
float
|
Upper bound (b > a). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Example
round(uniform_continuous_variance(0, 1), 6) 0.083333
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_discrete_cdf(k: int, a: int, b: int) -> float
¶
CDF of the discrete uniform distribution.
P(X <= k) = (floor(k) - a + 1) / (b - a + 1) for a <= k <= b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Integer value. |
required |
a
|
int
|
Lower bound. |
required |
b
|
int
|
Upper bound. |
required |
Returns:
| Type | Description |
|---|---|
float
|
P(X <= k). |
Example
uniform_discrete_cdf(3, 1, 6) 0.5
Complexity: O(1)
Source code in shortfx/fxNumeric/probability_extra_functions.py
uniform_discrete_pmf(k: int, a: int, b: int) -> float
¶
PMF of the discrete uniform distribution on {a, a+1, ..., b}.
P(X=k) = 1/(b-a+1) for a <= k <= b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Integer value. |
required |
a
|
int
|
Lower bound (integer). |
required |
b
|
int
|
Upper bound (integer, b >= a). |
required |
Returns:
| Type | Description |
|---|---|
float
|
P(X=k). |
Example
round(uniform_discrete_pmf(3, 1, 6), 6) 0.166667
Complexity: O(1)