pub enum ComparisonGradient {
Exact,
Surrogate {
width: f64,
},
RelativeSurrogate {
fraction: f64,
},
}Expand description
Gradient rule for the bit an emit_compare returns, a step function of its operands.
Variants§
Exact
Differentiate the comparison’s operations as built: zero almost everywhere, and a boolean atom inside it
follows boolean_gradient.
Surrogate
Treat the bit as sigmoid(d / width) in the backward pass only, where d is the comparison’s difference,
e.g. a - b for a > b; an equality bit as 4 × sigmoid × (1 - sigmoid), which peaks at d = 0. The
gradient goes straight to the operands; the forward values stay exact. width is in the operands’ units.
RelativeSurrogate
Surrogate with each comparison’s width set to fraction × the span of its difference’s
declared range, e.g. 0.1 × (max - min of a - b): scale-free, so dice and hit-point thresholds in one circuit
each get a width that fits them, with no annotations.