Content is user-generated and unverified.

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:


Total Cost Function

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 + cRe

The 5 Individual Cost Terms (inside evaluate())

1. Gain Error — target: 26 dB (closed-loop voltage gain = 1 + Rf/Rin)

js
const gain    = 1 + Rf / Rin;
const gainDB  = 20 * Math.log10(gain);
const gErr    = (gainDB - 26) / 26;
const cGain   = gErr * gErr * 4;          // weight 4, quadratic

2. Low-frequency −3 dB — target: < 10 Hz (input RC pole)

js
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)

js
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

js
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

js
const cRe = Math.pow((Math.log10(Re) - Math.log10(0.47)), 2) * 0.8;

Summary Table

TermWhat it penalizesWeight / form
cGainGain deviation from 26 dB×4, quadratic
cFlowLow-frequency cutoff above 10 Hz×2, quadratic
cFhiHigh-frequency cutoff below 100 kHz×2, quadratic
cBiasRb1/Rb2 asymmetry (thermal drift)×2.5, power 1.5
cReRe deviation from 0.47 Ω×0.8, log-quadratic

How A* Uses It

  • g(n) = steps taken (search depth) — incremented by 1 per neighbor expansion
  • h(n) = evaluate(state).total — the circuit performance cost above
  • f(n) = g + h — the priority key in the min-heap (open set)

The heuristic is admissible since it can always reach 0 when all targets are met, meaning A* is guaranteed to find the optimal component combination.

Content is user-generated and unverified.
    Class AB A* Cost Function: Circuit Optimization Guide | Claude