Unfreeze & train
This program starts as the exact soft switch (t = 4, k = 1, hi = 10, lo = 12). Its constants live in cells, so circuit.backpropagateReference gives their gradients. Pick a target and train.
Interactive demo
threshold t
slope k
on value hi
off value lo
loss (MSE)
steps
What is being trained?
The circuit computes s = clamp(k × (a − t), 0, 1) with two ReLUs, then y = s × hi + (1 − s) × lo with emitSelect. Each step evaluates 21 sample points, backpropagates the squared error, and moves t, k, hi and lo by plain gradient descent.
Why does the threshold sometimes get stuck?
Gradients only reach t and k where the ramp is between 0 and 1; outside it the ReLUs are flat. That's the general rule from upstream's notes: exact decisions have zero slope, continuous quantities train well. Upstream's Learned gallery trains a much larger network (244 coefficients) with Adam.