cenreg.distribution package — cenreg 0.0.4 documentation

# cenreg.distribution package

## Submodules

## cenreg.distribution.empirical module

class cenreg.distribution.empirical.EmpiricalCDF(y: ndarray | None = None, sample_weight: ndarray | None = None)

  Bases: `object`

  Empirical Cumulative distribution functions (CDF).

  average_cdf(y: ndarray) → ndarray

    Compute the average CDF values.

    Parameters:

      y (np.ndarray) – CDF values are computed for values y.

    Returns:

      cdf_values – Compute CDF values for each value in y.

    Return type:

      np.ndarray

  cdf(y: ndarray)

    Cumulative distribution function (i.e., inverse of quantile function).

    Parameters:

      y (np.ndarray) – CDF values are computed for values y.

    Returns:

      cdf_values – Compute CDF values for each value in y. Array shape is equal to the shape of y.

    Return type:

      np.ndarray

  icdf(quantiles: float | ndarray) → ndarray

    Inverse cumulative distribution function (i.e., quantile function).

    Parameters:

      quantiles (float | np.ndarray) – Quantiles for which the inverse CDF is computed.

    Returns:

      icdf_values – Compute inverse CDF values for each value in quantiles. Array shape is equal to the shape of quantiles.

    Return type:

      np.ndarray

  set(y: ndarray, sample_weight: ndarray | None = None)

    Compute CDF based on y and sample_weight. The observed values y are weightd by sample_weight.

    Parameters:

      - y (np.ndarray) – One-dimensional ndarray containing observed values.

      - sample_weight (np.ndarray) – One or two-dimensional ndarray containing weight for each value.

## cenreg.distribution.linear module

class cenreg.distribution.linear.LinearCDF(boundaries: ndarray, values: ndarray = None, apply_cumsum: bool = True)

  Bases: `object`

  Cumulative distribution functions (CDF) with linear interpolation.

  CDF values are stored for pre-defined boundaries, and the values between the boundaries are linear interpolated.

  average_cdf(y: ndarray, mask: ndarray | None = None, add_edge: bool = False) → ndarray

    Compute the average CDF values.

    Parameters:

      - y (np.ndarray) – CDF values are computed for values y. If dimension of y is one, then cdf(y) is computed for all CDFs. If dimension of y is two, then cdf(y) is computed for each corresponding CDF.

      - mask (np.ndarray) – Mask to compute CDF for a subset of CDFs.

      - add_edge (bool) – If True, then the output is ensured to have output[0]=0.0 and output[-1]=1.0. If you need output satisfies this condition, it is better to set add_edges to True and remove the first and last elements from y.

    Returns:

      cdf_values – Compute CDF values for each value in y.

    Return type:

      np.ndarray

  cdf(y: ndarray, mask: ndarray | None = None, add_edges: bool = False)

    Cumulative distribution function (i.e., inverse of quantile function).

    Parameters:

      - y (np.ndarray) – CDF values are computed for values y. If dimension of y is one, then cdf(y) is computed for all CDFs. If dimension of y is two, then cdf(y) is computed for each corresponding CDF.

      - mask (np.ndarray) – Mask to compute CDF for a subset of CDFs. Array must be one-dimensional and its length must be equal to the number of CDFs.

      - add_edges (bool) – If True, then the output is ensured to have output[0]=0.0 and output[-1]=1.0. If you need output satisfies this condition, it is better to set add_edges to True and remove the first and last elements from y.

    Returns:

      cdf_values – Compute CDF values for each value in y. Array shape is equal to the shape of y.

    Return type:

      np.ndarray

  get_boundary_lengths()
  icdf(alpha: ndarray | float, mask: ndarray | None = None, add_edges: bool = False) → ndarray

    Quantile function (i.e., inverse of cumulative distribution function).

    Parameters:

      - alpha (np.ndarray or float) – Quantile values are computed for quantile levels alpha. If dimension of alpha is one, then icdf(alpha) is computed for all CDFs. If dimension of alpha is two, then icdf(alpha) is computed for each corresponding CDF.

      - mask (np.ndarray) – Mask to compute CDF for a subset of CDFs. Array must be one-dimensional and its length must be equal to the number of CDFs.

      - add_edges (bool) – If True, then the inverse of the CDF values at quantiles 0.0 and 1.0 are added. If you need quantiles at 0.0 and 1.0, it is better to set add_edges to True and remove 0.0 and 1.0 from alpha.

    Returns:

      y – Compute y. Array shape is equal to the shape of alpha.

    Return type:

      np.ndarray

  set_knot_values(values: ndarray, apply_cumsum: bool = True)

    Set CDF values.

    Parameters:

      - values (np.ndarray) – Array containing the CDF values. The length of the last dimension must be equal to the length of boundaries.

      - apply_cumsum (bool) – If True, then values is assumed to be the probablity distribution functions (PDFs) and the cumulative sum of values is computed.

class cenreg.distribution.linear.LinearQuantileFunction(qk_levels: ndarray, qk_values: ndarray | None = None, apply_cumsum: bool = True)

  Bases: `object`

  Quantile functions with linear interpolation.

  A quantile function is defined by a set of quantile values (qk_values) at pre-defined quantile levels (qk_levels). The values between quantile values are computed by using linear interpolation.

  If qk_values are two-dimensional array, then each row corresponds to a quantile function.

  average_cdf(y: ndarray, mask: ndarray | None = None, add_edge: bool = False)
  cdf(y: ndarray, mask: ndarray | None = None, add_edges: bool = False)

    Cumulative distribution function (i.e., inverse of quantile function).

    Parameters:

      - y (np.ndarray) – Quantile levels are computed for quantile values y. If dimension of y is one, then cdf(y) is computed for all quantile functions. If dimension of y is two, then cdf(y) is computed for each corresponding quantile function.

      - mask (np.ndarray) – Mask to compute quantile function for a subset of quantile functions. Array must be one-dimensional and its length must be equal to the number of quantile functions.

      - add_edges (bool) – If True, then the CDF values at the boundaries are added.

    Returns:

      q_levels – Compute quantile levels for each value in y. Array shape is equal to the shape of y.

    Return type:

      np.ndarray

  get_qk_lengths()
  icdf(alpha: ndarray | float, mask: ndarray | None = None, add_edges: bool = False)

    Quantile function (i.e., inverse of cumulative distribution function).

    Parameters:

      - alpha (np.ndarray or float) – Quantile values are computed for quantile levels alpha. If dimension of alpha is one, then quantile values in alpha are computed for all quantile functions. If dimension of alpha is two, then quantile values in alpha are computed for each corresponding quantile function.

      - mask (np.ndarray) – Mask to compute quantile function for a subset of quantile functions. Array must be one-dimensional and its length must be equal to the number of quantile functions.

      - add_edges (bool) – If True, then the inverse of the CDF values at the boundaries are added.

    Returns:

      y – Array shape is equal to the shape of alpha.

    Return type:

      np.ndarray

  set_knot_values(qk_values: ndarray, apply_cumsum: bool = True)

    Set values of quantile knots.

    Parameters:

      - qk_values (np.ndarray) – One or two-dimensional array containing the values of quantile knots. If qk_values is two-dimensional array, then each row corresponds to a quantile function and qk_values[:,j] stores the value of quantile function at qk_levels[j]. Array shape must be [num_quantile_function, len(qk_levels)].

      - apply_cumsum (bool) – If True, then qk_values is assumed to be the differences of quantile values and the cumulative sum of qk_values is computed.

## Module contents