univariate_function

univariate_function(
    type,
    parameters,
    x=None,
    inverse=False,
    is_inverse=False,
    confidence_level=None,
)

Evaluate a univariate function.

Mirrors the Numerics linear, power, segmented power, composite, and ensemble function surfaces. A string type keeps the compact linear/power interface. A dictionary type is a function spec and parameters is then the evaluation vector. Composite specs contain nested functions and optional weights/mode. Ensemble specs contain a template, parameter_sets, and one of sample_index or sample_percentile.

Linear and power functions support optional normally distributed noise through confidence_level. is_inverse (PowerFunction’s own IsInverse switch) selects which of the forward power law or its algebraic inverse Function()/inverse=True evaluates – an independent axis from inverse itself, which picks Function() vs. InverseFunction() on whichever of the two is_inverse selects.

Parameters

Name Type Description Default
type ('linear', 'power', 'segmented_power') String names are matched case-insensitively. A dictionary follows the shared function spec grammar described above. "linear"
parameters array_like [alpha, beta, sigma] for "linear"; [alpha, beta, xi, sigma] for "power"; [h1, log10_alpha1, beta1, ..., sigma] for "segmented_power". When type is a dictionary, this argument supplies the values to evaluate. required
x array_like The values to evaluate the function at, or (when inverse=True) the values to evaluate the inverse function at. None
inverse bool If True, evaluates the inverse function (InverseFunction()) instead of the forward function (Function()). False
is_inverse bool "power"-only: PowerFunction’s own IsInverse property. An error for type="linear". False
confidence_level float If given, evaluates the non-deterministic path at this quantile level; if None (default), evaluates deterministically. None

Returns

Name Type Description
numpy.ndarray

Examples

>>> from corehydropy import univariate_function
>>> univariate_function("linear", [0, 1, 0], [1, 2, 3])
array([1., 2., 3.])
>>> univariate_function("power", [5, 2, 0, 3], 6)
array([180.])
>>> univariate_function("power", [5, 2, 0, 3], 6, confidence_level=0.75)
array([1361.614084])