---
title: "ClikaRT::ops::binary_cross_entropy"
sidebar_label: "binary_cross_entropy"
description: "Binary cross-entropy on element-wise PROBABILITIES. \\[ \\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_…"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## binary\_cross\_entropy() {#binary_cross_entropy}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`binary_cross_entropy`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `target`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`OptionalTensor`](../../index.md#OptionalTensor) `weight` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Reduction`](./index.md#Reduction) `reduction` `=` [`Reduction::Mean`](./index.md#Reduction)<br />
)

</div>

Binary cross-entropy on element-wise PROBABILITIES.

$$
\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`](./sigmoid.md#sigmoid) first, or use [`binary_cross_entropy_with_logits`](./binary_cross_entropy_with_logits.md#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.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2990

</div>
