Distribution
Distribution(family, params)A univariate distribution from the ported Numerics library.
Parameters are positional, in the same order as the C# constructor for the family (for example Normal takes [mean, sd] and GeneralizedExtremeValue takes [location, scale, shape]). Use :attr:parameter_names to see the names for a family.
All numeric methods evaluate in the shared C++ core, so results are identical to the R package and to the upstream C# library.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| family | str | Distribution family name; see :func:distribution_names. |
required |
| params | array-like of float | Parameter vector, in constructor order. | required |
Examples
>>> d = Distribution("Normal", [100, 15])
>>> d.cdf(100)
0.5
>>> d.random(3, seed=123)
array([107.71408450, 108.43058699, 91.52951859])Attributes
| Name | Description |
|---|---|
| family | str: The distribution family name. |
| is_valid | bool: Whether the parameters are valid for this family. |
| parameter_names | dict: Parameter names, keys "full" and "short". |
| params | list of float: The parameter vector, in constructor order. |
Methods
| Name | Description |
|---|---|
| cdf | Cumulative distribution at x. |
| fit | Fit a distribution family to data. |
| linear_moments | The first four L-moments. |
| log_likelihood | Log-likelihood of data under the distribution. |
| log_pdf | Natural log of the probability density at x. |
| moments | Moments and support of the distribution. |
Probability density at x. |
|
| quantile | Quantile (inverse CDF) at probability p in (0, 1). |
| random | Draw n random values. |
cdf
Distribution.cdf(x)Cumulative distribution at x.
fit
Distribution.fit(family, data, method='mle')Fit a distribution family to data.
Mirrors the C# Estimate(data, ParameterEstimationMethod) API of the Numerics library.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| family | str | Distribution family name; see :func:distribution_names. |
required |
| data | array-like of float | Observations. | required |
| method | ('mle', 'lmom', 'mom') | Estimation method: maximum likelihood (default), L-moments, or product moments. Not every family supports every method; unsupported combinations raise. | "mle" |
Returns
| Name | Type | Description |
|---|---|---|
| Distribution | The fitted distribution. |
linear_moments
Distribution.linear_moments()The first four L-moments.
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the family has no L-moment support. |
log_likelihood
Distribution.log_likelihood(data)Log-likelihood of data under the distribution.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | array-like of float | Observations. | required |
log_pdf
Distribution.log_pdf(x)Natural log of the probability density at x.
moments
Distribution.moments()Moments and support of the distribution.
Returns
| Name | Type | Description |
|---|---|---|
| dict | Keys mean, median, mode, sd, skewness, kurtosis, minimum, maximum; values are nan where undefined. |
Distribution.pdf(x)Probability density at x.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | float or array - like | Quantiles. | required |
Returns
| Name | Type | Description |
|---|---|---|
| float or numpy.ndarray | Density values, scalar in, scalar out. |
quantile
Distribution.quantile(p)Quantile (inverse CDF) at probability p in (0, 1).
random
Distribution.random(n, seed=None)Draw n random values.
Draws come from the same seeded Mersenne Twister stream as the C# GenerateRandomValues(sampleSize, seed): a given seed reproduces the C# draws bit-for-bit (and matches corehydror exactly).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| n | int | Number of draws. | required |
| seed | int | Seed for reproducible draws; None (the default) seeds from the clock. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| numpy.ndarray | The n draws. |