calibration

package
v0.207.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package calibration implements Phase 2 conformal threshold calibration for the local-offload harness. It reads the JSONL ledger produced by package ledger, derives per-task margin thresholds using Conformal Risk Control, and writes the resulting thresholds to a JSON file for the pipeline to consume.

Algorithm (Conformal Risk Control, margin formulation):

For each task, collect labeled calls: (margin, correct).
correct = (Grounded != nil && *Grounded) || (EscalatedAgreed != nil && *EscalatedAgreed).
Skip: no usable label, Margin==0, CacheHit.
For a candidate threshold t (a margin cutoff), ACCEPT a call when margin >= t.
empirical error among accepted = count(accepted && !correct) / count(accepted).
Adjusted rate = (n_accepted * err(t) + 1) / (n_accepted + 1).
Choose the LARGEST t such that the adjusted rate <= alpha.
If no t qualifies, fall back to the most conservative (largest) observed margin.
Tasks with < 60 labeled rows are omitted (pipeline uses its constant instead).
The floor was lowered from 100 to 60 to match the confhead emission gate so
the calibration and training steps share the same data-sufficiency criterion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ledgerPath string, defaultAlpha float64, alphas map[string]float64, outPath, scale string) (thresholds map[string]float64, report string, err error)

Run reads the ledger at ledgerPath, computes per-task conformal margin thresholds, writes a pretty-printed JSON map[task]float64 to outPath, and returns the map plus a human-readable summary report.

alphas overrides the per-task target error rate; missing tasks fall back to defaultAlpha. Tasks with fewer than 60 usable labeled rows are omitted from the returned map (pipeline falls back to its hardcoded constant). scale names the margin scale to calibrate ON (core.MarginScaleMatched or core.MarginScaleFull; empty reads as matched, the rule stored rows follow). Rows on any other scale are excluded and counted in the report: the two scales are ~10x apart (register D-130), and a cutoff derived from a mix of them belongs to neither while still gating production.

func RunSources added in v0.206.0

func RunSources(paths []string, defaultAlpha float64, alphas map[string]float64, outPath, scale string) (thresholds map[string]float64, report string, err error)

RunSources is Run over every labeled-row source the box writes (register D-126): the ledger AND the confhead labels sidecar. The only classify/triage label writer (pipeline.labelAgreement) appends to cfg.ConfHeadLabelsPath, while the ledger row of the same call carries the margin and no label — so a calibration read from the ledger alone found 0 usable rows in 9,217 and never fitted a threshold; the 60-row floor was never the blocker. Every source is a JSONL file of ledger.Entry rows; a missing file is a 0-row source, and the report names each source with its usable-row count so the plumbing is visible in the output rather than inferred from a silent skip.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL