def wmape()

in src/entrypoint/gluonts_example/metrics.py [0:0]


def wmape(actual, forecast, version=0) -> float:
    r"""
    .. math::
        wmape = mape * (actual / sum(actual))

    This implementation assumes actual are positives -- FIXME: would it be
    better to enforce this assumption by using sum(abs(actual))?

    Args:
        actual (np.array): Ground truths
        forecast (np.array): Forecasts
        version (int, optional): mape version to use. See mape(). Defaults to 0 (which
            may perform division-by-zero).

    Returns:
        array of floats: wmape values
    """
    # we take two series and calculate an output a wmape from it.
    # - NOTE: as-is implementation from Logbooks/Med_Low/Weekly_AutoArima.ipynb

    # make a series called mape
    se_mape = mape(actual, forecast, version=version)

    # get a float of the sum of the actual
    # - NOTE: this as-is implementation assumes actual are positives. Would it
    # be better to enforce this assumption by using np.sum(np.abs(actual))?
    ft_actual_sum = actual.sum()

    # get a series of the multiple of the actual & the mape
    se_actual_prod_mape = actual * se_mape

    # summate the prod of the actual and the mape
    ft_actual_prod_mape_sum = se_actual_prod_mape.sum()

    # float: wmape of forecast
    ft_wmape_forecast = ft_actual_prod_mape_sum / ft_actual_sum

    # return a float
    return ft_wmape_forecast