bce_with_logits

std.loss.bce_with_logits · Level L5

Binary cross-entropy taken from logits: max(z, 0) − z·t + log1p(e^(−|z|)). It never forms the probability, so it stays finite and accurate where sigmoid would round to 0 or 1.

mean( max(z, 0) − z·t + log1p(e^(−|z|)) )

Signature

bce_with_logits(z: f64[n], t: f64[n]) → f64[]

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

zf64[n]tf64[n]0.0absazMultiplyztMaximumposNegatenazSubtractdExpeLog1psoftAddsMeanllf64[]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size.
  • Agrees with the reference mean(t·log(1 + e^(−z)) + (1 − t)·log(1 + e^z)) to 80 digits (100-digit arithmetic), on all 40 test cases.
  • All 40 float64 results inside the running error bound; the closest uses 21% of it.
  • Interpreter and NumPy backend return bit-identical results.
Accuracy in detail
correctly rounded (the float64 nearest the exact value)
78%
bit-equal to the NumPy formula in float64
60%
largest error, in units in the last place
1.53

Note

The reference is −t·log σ(z) − (1 − t)·log(1 − σ(z)) with each log written out as log(1 + e^(∓z)), in exact arithmetic: no 1 − σ is ever formed, so nothing cancels even at 100 digits.

Identity

Calls
Called by
—
sha256:f468daa04419c960dc91c9f134e0c909c0ca6f6b1ab07e0590d42ed1f04b65ec

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.