Based on reading the artifact's source code, the cost function used in this Class AB A* Optimizer is a weighted sum of squared errors — a composite penalty function. Here's the full breakdown:
f(n) = g(n) + h(n)where g(n) = number of steps taken so far, and h(n) = evaluate(state).total, computed as:
total = cGain + cFlow + cFhi + cBias + cReevaluate())1. Gain Error — target: 26 dB (closed-loop voltage gain = 1 + Rf/Rin)
const gain = 1 + Rf / Rin;
const gainDB = 20 * Math.log10(gain);
const gErr = (gainDB - 26) / 26;
const cGain = gErr * gErr * 4; // weight 4, quadratic2. Low-frequency −3 dB — target: < 10 Hz (input RC pole)
const fLow = 1 / (2 * π * Rin * C1);
const cFlow = fLow > 10 ? Math.pow((fLow/10 - 1), 2) * 2 : 0;3. High-frequency −3 dB — target: > 100 kHz (gain–bandwidth product)
const fHigh = GBW / gain;
const cFhi = fHigh < 1e5 ? Math.pow((1e5/fHigh - 1), 2) * 2 : 0;4. Bias symmetry — Rb1 ≈ Rb2 for best thermal tracking
const ratio = Rb1 / Rb2;
const cBias = Math.pow(Math.abs(ratio - 1.0), 1.5) * 2.5;5. Emitter resistor Re stability — target: 0.47 Ω optimal for audio power amp
const cRe = Math.pow((Math.log10(Re) - Math.log10(0.47)), 2) * 0.8;| Term | What it penalizes | Weight / form |
|---|---|---|
cGain | Gain deviation from 26 dB | ×4, quadratic |
cFlow | Low-frequency cutoff above 10 Hz | ×2, quadratic |
cFhi | High-frequency cutoff below 100 kHz | ×2, quadratic |
cBias | Rb1/Rb2 asymmetry (thermal drift) | ×2.5, power 1.5 |
cRe | Re deviation from 0.47 Ω | ×0.8, log-quadratic |
evaluate(state).total — the circuit performance cost aboveThe heuristic is admissible since it can always reach 0 when all targets are met, meaning A* is guaranteed to find the optimal component combination.