Distribution
Distribution(family, params)A univariate distribution from the ported Numerics library.
The 38 families of the USACE-RMC Numerics library that take a flat parameter vector are all supported, from Normal and Gumbel through GeneralizedNormal (the three-parameter LogNormal) and KappaFour; :func:distribution_names returns them. The five composite families it lists under "structured" have no flat parameter vector and are built by :func:dist_truncated, :func:dist_mixture, :func:dist_competing_risks, :func:dist_empirical, and :func:dist_kde instead.
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])GeneralizedNormal is the three-parameter LogNormal: at shape 0 it is the Normal.
>>> Distribution("GeneralizedNormal", [100, 15, 0]).cdf(100)
0.5Attributes
| Name | Description |
|---|---|
| family | str: The distribution family name. |
| is_composite | bool: Whether this is one of the five composite families (see :func:dist_truncated |
| 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. |
| to_json | This distribution as the JSON spec the shared C++ core parses. |
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 (every composite family: no composite distribution implements ILinearMomentEstimation upstream). |
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. |
to_json
Distribution.to_json()This distribution as the JSON spec the shared C++ core parses.
A composite (see :func:dist_truncated and friends) returns its stored spec; a flat family returns {"family": ..., "parameters": [...]}. Matches the grammar corehydror’s to_spec_json() emits, so a :class:Distribution embeds directly as a nested component of another composite, a :class:~corehydropy.copula.Copula marginal, or a :class:~corehydropy.mvdist.MultivariateDistribution.
Returns
| Name | Type | Description |
|---|---|---|
| str | The spec JSON. |