// Train conditional quantiles with pinball loss. Supply a quantile between zero and one. Use zero subgradient at a tie. use graph_io; pub fn fd_quantile_fit(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%x: tensor, %target: tensor, %tau: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.subtract %target, %x : tensor", rows, width); // r = target-x fd_line(" %v2 = stablehlo.multiply %tau, %v1 : tensor", rows, width); fd_line(" %v3 = stablehlo.constant dense<1.00000000000000000e+00> : tensor", rows, width); fd_line(" %v4 = stablehlo.subtract %tau, %v3 : tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %v4, %v1 : tensor", rows, width); fd_line(" %v6 = stablehlo.maximum %v2, %v5 : tensor", rows, width); // loss = maximum(tau*r,(tau-1)*r) fd_line(" %v7 = stablehlo.compare GT, %v1, %v0, FLOAT : (tensor, tensor) -> tensor", rows, width); fd_line(" %v8 = stablehlo.negate %tau : tensor", rows, width); fd_line(" %v9 = stablehlo.compare LT, %v1, %v0, FLOAT : (tensor, tensor) -> tensor", rows, width); fd_line(" %v10 = stablehlo.subtract %v3, %tau : tensor", rows, width); fd_line(" %v11 = stablehlo.select %v9, %v10, %v0 : tensor, tensor", rows, width); fd_line(" %v12 = stablehlo.select %v7, %v8, %v11 : tensor, tensor", rows, width); // grad = choose(r>0,-tau,choose(r<0,1-tau,0)) fd_line(" return %v6, %v12 : tensor, tensor", rows, width); println!(" }"); println!("}"); }