elegy/losses/mean_absolute_percentage_error.py
def mean_percentage_absolute_error(
    y_true: jnp.ndarray, y_pred: jnp.ndarray
) -> jnp.ndarray:
    """
    Computes the mean absolute percentage error (MAPE) between labels and predictions.

    After computing the absolute distance between the true value and the prediction value
    and divide by the true value, the mean value over the last dimension is returned.

    Usage:

    ```python
    rng = jax.random.PRNGKey(42)

    y_true = jax.random.randint(rng, shape=(2, 3), minval=0, maxval=2)
    y_pred = jax.random.uniform(rng, shape=(2, 3))

    loss = elegy.losses.mean_percentage_absolute_error(y_true, y_pred)

    assert loss.shape == (2,)

    assert jnp.array_equal(loss, 100. * jnp.mean(jnp.abs((y_pred - y_true) / jnp.clip(y_true, utils.EPSILON, None))))
    ```

    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.

    Returns:
        Mean absolute percentage error values. shape = `[batch_size, d0, .. dN-1]`.
    """
    y_true = y_true.astype(y_pred.dtype)
    diff = jnp.abs((y_pred - y_true) / jnp.maximum(jnp.abs(y_true), utils.EPSILON))
    return 100.0 * jnp.mean(diff, axis=-1)

    Computes the mean absolute percentage error (MAPE) between labels and predictions.

    After computing the absolute distance between the true value and the prediction value
    and divide by the true value, the mean value over the last dimension is returned.

    Usage:

    ```python
    rng = jax.random.PRNGKey(42)

    y_true = jax.random.randint(rng, shape=(2, 3), minval=0, maxval=2)
    y_pred = jax.random.uniform(rng, shape=(2, 3))

    loss = elegy.losses.mean_percentage_absolute_error(y_true, y_pred)

    assert loss.shape == (2,)

    assert jnp.array_equal(loss, 100. * jnp.mean(jnp.abs((y_pred - y_true) / jnp.clip(y_true, utils.EPSILON, None))))
    ```

    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.

    Returns:
        Mean absolute percentage error values. shape = `[batch_size, d0, .. dN-1]`.
    
Computes the mean absolute percentage error (MAPE) between labels and predictions.
After computing the absolute distance between the true value and the prediction value
and divide by the true value, the mean value over the last dimension is returned.












Computes the mean absolute percentage error ( MAPE ) between labels and predictions . After computing the absolute distance between the true value and the prediction value and divide by the true value the mean value over the last dimension is returned .
def mean_percentage_absolute_error(
    y_true: jnp.ndarray, y_pred: jnp.ndarray
) -> jnp.ndarray:
    y_true = y_true.astype(y_pred.dtype)
    diff = jnp.abs((y_pred - y_true) / jnp.maximum(jnp.abs(y_true), utils.EPSILON))
    return 100.0 * jnp.mean(diff, axis=-1)
def mean_percentage_absolute_error ( y_true : jnp . ndarray , y_pred : jnp . ndarray ) -> jnp . ndarray : y_true = y_true . astype ( y_pred . dtype ) diff = jnp . abs ( ( y_pred - y_true ) / jnp . maximum ( jnp . abs ( y_true ) , utils . EPSILON ) ) return 100.0 * jnp . mean ( diff , axis = - 1 )
Computes the mean absolute percentage error (MAPE) between labels and predictions.
Computes the mean absolute percentage error ( MAPE ) between labels and predictions .
"""
    Computes the mean absolute percentage error (MAPE) between labels and predictions.

    After computing the absolute distance between the true value and the prediction value
    and divide by the true value, the mean value over the last dimension is returned.

    Usage:

    ```python
    rng = jax.random.PRNGKey(42)

    y_true = jax.random.randint(rng, shape=(2, 3), minval=0, maxval=2)
    y_pred = jax.random.uniform(rng, shape=(2, 3))

    loss = elegy.losses.mean_percentage_absolute_error(y_true, y_pred)

    assert loss.shape == (2,)

    assert jnp.array_equal(loss, 100. * jnp.mean(jnp.abs((y_pred - y_true) / jnp.clip(y_true, utils.EPSILON, None))))
    ```

    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.

    Returns:
        Mean absolute percentage error values. shape = `[batch_size, d0, .. dN-1]`.
    """
Mean absolute percentage error values. shape = `[batch_size, d0, ..
Mean absolute percentage error values . shape = ` [ batch_size d0 ..
y_true
jnp.ndarray
Ground truth values. shape = `[batch_size, d0, .. dN]`.
Ground truth values . shape = ` [ batch_size d0 .. dN ] ` .
y_pred
jnp.ndarray
The predicted values. shape = `[batch_size, d0, .. dN]`.
The predicted values . shape = ` [ batch_size d0 .. dN ] ` .