Skip to contents

Computes binary cross-entropy loss between predictions and binary targets.

Usage

mlx_binary_cross_entropy(
  predictions,
  targets,
  reduction = c("mean", "sum", "none")
)

Arguments

predictions

Predicted probabilities as an mlx array (values in [0,1]).

targets

Binary target values as an mlx array (0 or 1).

reduction

Type of reduction: "mean" (default), "sum", or "none".

Value

An mlx array containing the loss.

Examples

preds <- as_mlx(matrix(c(0.9, 0.2, 0.8), 3, 1))
targets <- as_mlx(matrix(c(1, 0, 1), 3, 1))
mlx_binary_cross_entropy(preds, targets)
#> mlx array []
#>   dtype: float32
#>   device: gpu
#>   values:
#> [1] 0.1838825