ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/platform/magstore/train.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/platform/magstore/train.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/platform/magstore/train.go
Original SHA-256805ffe4a80c58f1c28fff1df51467ee41b842bf3b4080b61804e7881f8b26bbc
Git blob SHA50d6bfc72195b3cac82dc0f9b1ca5d75b9e4cff5
Reading-copy SHA-256805ffe4a80c58f1c28fff1df51467ee41b842bf3b4080b61804e7881f8b26bbc

Original source ↗

Every recorded occurrence

These 10 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / internal/platform/magstore/train.gofeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / internal/platform/magstore/train.gocollision-deconfliction4ee5a09972608ed89f8377c6665542d5f450f0a6Open original
Janady13/missionmatch / internal/platform/magstore/train.gomaster1e9249840a4302ec82e123b9c9cb6f75badea3e4Open original
Janady13/missionmatch / internal/platform/magstore/train.gomag-substrateb82c7100a492dec67dfd1eda6b3f53def859be35Open original
Janady13/missionmatch / internal/platform/magstore/train.gotime-to-fill-survivalb66e1e505863d4f17741a4b9ede73509e45bd6c6Open original
Janady13/missionmatch / internal/platform/magstore/train.gopresentation-readinesseb574acaa29d71ce4d0f852572e87c275c79fdb7Open original
Janady13/missionmatch / internal/platform/magstore/train.govendor-intelligencefe9796a19c261951d3f2565206c0c1b5ac294465Open original
Janady13/missionmatch / internal/platform/magstore/train.gophase2-connectorse038d4c687aec16f8bd9bc4d907eea14d91f8704Open original
Janady13/missionmatch / internal/platform/magstore/train.gofeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original
Janady13/missionmatch / internal/platform/magstore/train.gocapture-readinessbae6af7cb2997e819174a9e9cfff5e16067a1975Open original

Recovered source transcript

package magstore import ( "context" "fmt" "math" "github.com/jackc/pgx/v5/pgxpool" "github.com/missionworkforce/missionmatch/internal/platform/learn" ) // DefaultCalibrationBins is the cold start resolution of the Platt calibration map: ten monotone bins of width // 0.1 over the raw probability range [0, 1]. A later isotonic fit past roughly a thousand labels can write a // finer map. const DefaultCalibrationBins = 10 // TrainResult summarizes a training run: whether it was skipped (and why), and, when it ran, the challenger // version written plus the fitted raw feature space coefficients and the sample composition. It is the value // both cmd/train-model logs and the integration test asserts on. type TrainResult struct { Skipped bool SkipReason string Version int N int Wins int Losses int FeatureNames []string Intercept float64 Coeffs []float64 // raw feature space, aligned to FeatureNames Iterations int Bins int } // Train reads the pooled decided bid labels, fits an interpretable win probability logistic model, and writes a // new CHALLENGER version (never a champion). It refuses to fit (Skipped) below the events per predictor floor or // on a single class, leaving the prior only champion in force. It converts the solver's standardized // coefficients into raw feature space (so the serve path applies them directly to gathered raw feature values) // and materializes a Platt calibration map into monotone bins. When dryRun is set it fits and returns the // coefficients but writes nothing. minEvents <= 0 auto computes the floor as twenty decided events per fitted // parameter (the intercept plus one per feature). func Train(ctx context.Context, pool *pgxpool.Pool, modelKey string, l2 float64, minEvents int, dryRun bool) (TrainResult, error) { rows, err := ReadLabeledBids(ctx, pool) if err != nil { return TrainResult{}, err } x, y, featureNames := learn.BuildDataset(rows) var res TrainResult res.FeatureNames = featureNames for _, v := range y { res.N++ if v == 1 { res.Wins++ } else { res.Losses++ } } floor := minEvents if floor <= 0 { floor = 20 * (len(featureNames) + 1) } if res.N < floor { res.Skipped = true res.SkipReason = fmt.Sprintf("%d decided bids is below the events floor of %d", res.N, floor) return res, nil } if res.Wins == 0 || res.Losses == 0 { res.Skipped = true res.SkipReason = fmt.Sprintf("the labels are a single class (%d win, %d loss)", res.Wins, res.Losses) return res, nil } model, err := learn.FitLogistic(x, y, l2) if err != nil { return TrainResult{}, err } res.Iterations = model.Iterations // Standardized to raw feature space: rawCoef_j = beta_j / scale_j; // rawIntercept = beta0 - SUM_j beta_j * mean_j / scale_j. res.Intercept = model.Intercept res.Coeffs = make([]float64, len(featureNames)) for j := range featureNames { res.Coeffs[j] = model.Coeffs[j] / model.Scales[j] res.Intercept -= model.Coeffs[j] * model.Means[j] / model.Scales[j] } // The in sample log odds for the Platt calibration fit. etas := make([]float64, len(x)) for i := range x { eta := res.Intercept for j := range featureNames { eta += res.Coeffs[j] * x[i][j] } etas[i] = eta } bins := materializeCalibration(etas, y, DefaultCalibrationBins) res.Bins = len(bins) if dryRun { return res, nil } notes := fmt.Sprintf("Challenger fit by cmd/train-model over %d decided bids (%d win, %d loss) pooled across tenants, ridge l2=%v. OutputKind opportunity_score, never a candidate score. champion=false until cmd/eval-model passes the four fifths gate and a human promotes it.", res.N, res.Wins, res.Losses, l2) // The training feature means are stored in the feature_spec so the serve path can impute a feature with no // history (a segment with no decided bids) at its mean, keeping a learned model at the base rate for a no // history segment rather than extrapolating off a misleading zero. means := make([]float64, len(featureNames)) copy(means, model.Means) version, err := WriteChallenger(ctx, pool, modelKey, Challenger{ FeatureNames: featureNames, Intercept: res.Intercept, Coeffs: res.Coeffs, Means: means, Bins: bins, Notes: notes, }) if err != nil { return TrainResult{}, err } res.Version = version return res, nil } // materializeCalibration fits Platt scaling on the in sample log odds and materializes it into monotone // calibration bins over the raw probability range [0, 1], the shape aedt_calibration_bins stores and the serve // path looks up. For each bin the empirical rate is the Platt calibrated probability at the bin midpoint // (calibrated = sigmoid(a * logit(mid) + b)). A Platt fit failure returns no bins, the honest identity map. func materializeCalibration(etas []float64, y []int, binCount int) []Bin { a, b, err := learn.FitPlatt(etas, y) if err != nil { return nil } bins := make([]Bin, 0, binCount) for k := 0; k < binCount; k++ { lo := float64(k) / float64(binCount) hi := float64(k+1) / float64(binCount) mid := (lo + hi) / 2 score := math.Log(mid / (1 - mid)) // logit of the midpoint; midpoints 0.05..0.95 are always in range cal := 1.0 / (1.0 + math.Exp(-(a*score + b))) bins = append(bins, Bin{Lo: lo, Hi: hi, EmpiricalRate: cal}) } return bins }

Mathematical records from this source

Search equations, builds, manuscript text, and recovered sources.