Skip to main content

ClikaRT::ops::binary_cross_entropy

function

binary_cross_entropy()

Tensor binary_cross_entropy(
    Tensor input,
    Tensor target,
    OptionalTensor weight = {},
    Reduction reduction = Reduction::Mean
)

Binary cross-entropy on element-wise PROBABILITIES.

i=(yilogxi+(1yi)log(1xi))\ell_i = -\bigl(y_i \log x_i + (1 - y_i)\log(1 - x_i)\bigr)

input must already be probabilities in [0, 1] (apply sigmoid first, or use binary_cross_entropy_with_logits for the fused, numerically safer form). weight re-weights each element's loss.

Parameters

  • input: probabilities in [0, 1].
  • target: targets in [0, 1]; same shape as input.
  • weight: optional per-element weight; broadcastable to input.
  • reduction: None / Mean / Sum; default Mean.

Returns: the loss (0-D under Mean/Sum).

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) on a shape mismatch.

Declared in ClikaRT/compute/ops.h, line 2903