def expected_calibration_error(
    preds: Array,
    probs: Array,
    targets: Array,
    plot: bool = False,
    plot_options: Optional[Dict] = None,
) -> jnp.ndarray:
    """
    Compute the Expected Calibration Error (ECE)
    (see `Naeini et al., 2015 <https://people.cs.pitt.edu/~milos/research/AAAI_Calibration.pdf>`__ and
    `Guo et al., 2017 <http://proceedings.mlr.press/v70/guo17a/guo17a.pdf>`__). Optionally, plot and save a reliability
    diagram.

    Parameters
    ----------
    preds: Array
        A one-dimensional array of predictions over the data points.
    probs: Array
        A two-dimensional array of class probabilities for each data point.
    targets: Array
        A one-dimensional array of target variables.
    plot: bool
        Whether to plot a reliability diagram.
    plot_options: dict
        Options for the reliability diagram plot; see :func:`~fortuna.plot.plot_reliability_diagram`.

    Returns
    -------
    jnp.ndarray
        The value of the ECE.
    """
    counts, confs, accs = compute_counts_confs_accs(
        preds, probs, targets, plot, plot_options
    )
    ece = jnp.sum(counts * jnp.abs(accs - confs)) / preds.shape[0]
    return ece

    Compute the Expected Calibration Error (ECE)
    (see `Naeini et al., 2015 <https://people.cs.pitt.edu/~milos/research/AAAI_Calibration.pdf>`__ and
    `Guo et al., 2017 <http://proceedings.mlr.press/v70/guo17a/guo17a.pdf>`__). Optionally, plot and save a reliability
    diagram.

    Parameters
    ----------
    preds: Array
        A one-dimensional array of predictions over the data points.
    probs: Array
        A two-dimensional array of class probabilities for each data point.
    targets: Array
        A one-dimensional array of target variables.
    plot: bool
        Whether to plot a reliability diagram.
    plot_options: dict
        Options for the reliability diagram plot; see :func:`~fortuna.plot.plot_reliability_diagram`.

    Returns
    -------
    jnp.ndarray
        The value of the ECE.
    
fortuna/metric/classification.py