// Score binary probability calibration from logits with the Brier loss and its chain-rule gradient. use graph_io; pub fn fd_brier_fit(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%x: tensor, %target: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.logistic %x : tensor", rows, width); // p = sig(x) fd_line(" %v2 = stablehlo.subtract %v1, %target : tensor", rows, width); // r = p-target fd_line(" %v3 = stablehlo.multiply %v2, %v2 : tensor", rows, width); // loss = r*r fd_line(" %v4 = stablehlo.constant dense<2.00000000000000000e+00> : tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %v4, %v2 : tensor", rows, width); fd_line(" %v6 = stablehlo.multiply %v5, %v1 : tensor", rows, width); fd_line(" %v7 = stablehlo.constant dense<1.00000000000000000e+00> : tensor", rows, width); fd_line(" %v8 = stablehlo.subtract %v7, %v1 : tensor", rows, width); fd_line(" %v9 = stablehlo.multiply %v6, %v8 : tensor", rows, width); // grad = 2*r*p*(1-p) fd_line(" return %v3, %v9 : tensor, tensor", rows, width); println!(" }"); println!("}"); }