Jump to text
On this page
Copy and source
Published source confirmed at last check

Source changed 2026-11-23 00:01:58 UTC · snapshot created 2026-11-23 00:02:28 UTC · last check 2026-11-23 06:15:10 UTC

Engineering.Reference:26.4.5.3 - Fit a first policy and use the fresh return

For the four histories, stipulate teacher probabilities of choice 1 q=(.8,.05,.9,.85). The service contract supports these target directions. Generate and qualify the three demonstrations above, then retain one representative per sufficient history. This four-row training set removes duplicate start/pending rows. SmartAD instead selects a demonstration per question by its stated NLL score.

Start all logits at zero. Choose weights (1,2,2,1) to give the two status-dependent decisions more of this small update, with Z=6, and a descent rate η=0.6. The normalized binary cross-entropy/KL gradient is w_i(p_i-q_i)/Z. Thus

θ_i' = θ_i + η w_i(q_i-p_i)/Z.

Hard demonstrated targets (1,0,1,1) produce logits (.05,-.10,.10,.05). The soft teacher targets produce (.03,-.09,.08,.035). These are different first trained policies, even though both used the same decisions and support. Equal soft-target weights produce (.045,-.0675,.06,.0525); selecting a weight changes the update, while renaming a mask would not.

The following finite simulator creates the demonstrations, constructs both updates and executes the changed policy. Its observations come from the service model. Each policy step retains the history and old probability needed by the next construction.

from math import exp, log, sqrt


def sigmoid(x):
    return 1 / (1 + exp(-x))


Q = (.8, .05, .9, .85)  # probabilities of choice 1 at the four histories
WEIGHTS = (1., 2., 2., 1.)


def fit_targets(theta, targets, weights=WEIGHTS, rate=.6):
    z = sum(weights)
    return tuple(t + rate*w*(q-sigmoid(t))/z for t, q, w in zip(theta, targets, weights))


def execute(theta, status, draws, broken=False):
    assert status in ("pending", "committed")
    draws = iter(draws)
    steps, events = [], [("task", "report the checked job status")]
    calls = 0

    def choose(i):
        p = sigmoid(theta[i])
        y = int(next(draws) < p)
        steps.append({"i": i, "y": y, "p": p if y else 1-p,
                      "q": Q[i] if y else 1-Q[i], "history": tuple(events)})
        return y

    if not choose(0):
        events.append(("action", "claim_complete_without_check"))
        return {"reward": 0, "steps": steps, "events": events, "calls": calls}
    events.append(("action", "inspect_status"))
    calls += 1
    if broken:
        events.append(("observation", "schema_error"))
        if not choose(3):
            events += [("action", "repeat_old_call"), ("observation", "schema_error")]
            return {"reward": 0, "steps": steps, "events": events, "calls": calls+1}
        events += [("action", "obtain_current_interface"), ("observation", "status/v2"),
                   ("action", "inspect_with_current_interface")]
        calls += 2  # obtain supported interface, then read current status
    events.append(("observation", status))
    y = choose(1 if status == "pending" else 2)
    events.append(("action", "report_complete" if y else "report_pending"))
    return {"reward": int(bool(y) == (status == "committed")),
            "steps": steps, "events": events, "calls": calls}


def expected(theta, broken=False):
    p = tuple(map(sigmoid, theta))
    return p[0]*(p[3] if broken else 1)*((1-p[1])+p[2])/2


old = (0.,)*4
teacher = tuple(log(q/(1-q)) for q in Q)
demos = [
    execute(teacher, "pending", (.2,.2)),
    execute(teacher, "committed", (.2,.2)),
    execute(teacher, "pending", (.2,.2,.2), broken=True),
]
chosen = {}
for episode in demos:
    assert episode["reward"] == 1
    for s in episode["steps"]:
        if s["i"] in chosen:
            assert chosen[s["i"]]["y"] == s["y"]
        chosen.setdefault(s["i"], s)
hard = fit_targets(old, tuple(float(chosen[i]["y"]) for i in range(4)))
soft = fit_targets(old, Q)
equal_soft = fit_targets(old, Q, (1.,)*4)
for name, theta in (("old",old), ("hard",hard), ("soft",soft), ("equal",equal_soft)):
    print(name, tuple(map(sigmoid,theta)), expected(theta), expected(theta,True))
for theta in (old, soft):
    print(execute(theta,"pending",(.49,.49))["events"])
print(execute(soft,"committed",(.49,.49))["events"])
for theta in (old,soft):
    print(execute(theta,"pending",(.49,.505,.49),broken=True)["events"])

With equal probabilities of pending and committed in this stipulated later population, expected valid-report probability is p_start * ((1-p_pending)+p_committed)/2. It changes from 0.25 to 0.2690504668 after the hard-target step and to 0.2645275262 after the soft-target step. Equal soft weights yield 0.2637692806. If every initial call meets the recoverable schema error, multiply by p_repair: the corresponding values are 0.125, 0.1378876638, 0.1345781427 and 0.1353458172. The ranking of the two soft-weight choices reverses between those populations. A loss-weight choice therefore needs the receiving work distribution and retained support, not just training loss.

The printed pending episode uses the same draws (.49,.49). The old policy inspects and falsely reports completion; the soft-trained policy inspects and reports pending. With a fresh committed observation it instead reports complete. In the changed-interface episode, draws (.49,.505,.49) make the old policy repeat the failed call, while the soft-trained policy obtains the current interface, inspects again and reports pending. The repair is performed by the supported runner; the learned decision selects it. The expected probabilities describe the stipulated population.