Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/aioe/simulate.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/aioe/simulate.go |
| Original SHA-256 | 9ad8d046e7e9f350e61a3cb3a544fbbe369a6743a4996919ab927c5514b768b6 |
| Git blob SHA | dc8f19891dc6f8f659d9dfdb69efd6c42b2293dc |
| Reading-copy SHA-256 | 9ad8d046e7e9f350e61a3cb3a544fbbe369a6743a4996919ab927c5514b768b6 |
Every recorded occurrence
These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/aioe/simulate.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/aioe/simulate.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓201 lines · 5.9 KB
package aioe
import (
"fmt"
"sort"
"strings"
"github.com/shopspring/decimal"
)
// Simulation characterizes the deterministic updater's behavior under a named outcome regime, over
// many cycles, WITHOUT any database or client data. It is a calibration and documentation harness:
// it proves the update converges sensibly, respects its clamps, and never runs away, and it produces
// a report for the AEDT model card. It does NOT produce shipped weights: the point is behavior
// characterization under a KNOWN synthetic oracle, not learning from fabricated outcomes.
type Simulation struct {
Regime string
Cycles int
Params Params
Start map[string]decimal.Decimal
End map[string]decimal.Decimal
MaxSeen map[string]decimal.Decimal
MinSeen map[string]decimal.Decimal
// SumAlways1 is true when every cycle's weights summed to exactly 1.0000.
SumAlways1 bool
// ClampsHeld is true when no dimension ever left [Floor, Ceiling].
ClampsHeld bool
// Converged is true when the last 5 cycles moved every dimension by less than 0.0005.
Converged bool
}
// Regime generates the synthetic events for one cycle. It is the ORACLE: the simulation only ever
// recovers the correlations the regime encodes, which is exactly why simulated weights are a
// validation artifact and never a shipped model.
type Regime struct {
Name string
Gen func(n int) []Event
}
// StandardRegimes are the characterization set: a dimension the outcomes reward, one they penalize,
// pure noise (must not move weights meaningfully), and an adversarial flip (alternating strong
// signals, the updater must stay bounded and not oscillate out of clamps).
func StandardRegimes() []Regime {
scored := func(vals map[string]string) map[string]decimal.Decimal {
out := make(map[string]decimal.Decimal, len(vals))
for k, v := range vals {
out[k] = decimal.RequireFromString(v)
}
return out
}
base := map[string]string{
"clearance": "80", "skills": "80", "certifications": "80",
"customer_experience": "80", "experience": "80", "location": "80",
}
withHigh := func(dim string) map[string]decimal.Decimal {
m := map[string]string{}
for k, v := range base {
m[k] = v
}
m[dim] = "98"
return scored(m)
}
return []Regime{
{
Name: "rewards-skills",
Gen: func(n int) []Event {
out := make([]Event, n)
for i := range out {
out[i] = Event{Signal: decimal.NewFromInt(1), DimScores: withHigh("skills")}
}
return out
},
},
{
Name: "penalizes-location",
Gen: func(n int) []Event {
out := make([]Event, n)
for i := range out {
// positive outcomes where location scored LOW: location matters less.
m := scored(base)
m["location"] = decimal.NewFromInt(10)
out[i] = Event{Signal: decimal.NewFromInt(1), DimScores: m}
}
return out
},
},
{
Name: "pure-noise",
Gen: func(n int) []Event {
out := make([]Event, n)
for i := range out {
sig := decimal.NewFromInt(1)
if i%2 == 0 {
sig = decimal.NewFromInt(-1)
}
out[i] = Event{Signal: sig, DimScores: scored(base)}
}
return out
},
},
{
Name: "adversarial-flip",
Gen: func(n int) []Event {
out := make([]Event, n)
for i := range out {
// alternate which dimension is rewarded, strongly, every event.
dim := "skills"
if i%2 == 0 {
dim = "location"
}
out[i] = Event{Signal: decimal.NewFromInt(1), DimScores: withHigh(dim)}
}
return out
},
},
}
}
// Simulate runs one regime for the given cycles from the default weights and returns the
// characterization. Deterministic: the same regime and params always produce the same report.
func Simulate(r Regime, cycles, eventsPerCycle int, p Params) Simulation {
w := DefaultWeightsMap()
start := cloneMap(w)
maxSeen, minSeen := cloneMap(w), cloneMap(w)
sim := Simulation{
Regime: r.Name, Cycles: cycles, Params: p, Start: start,
SumAlways1: true, ClampsHeld: true,
}
var history []map[string]decimal.Decimal
for c := 0; c < cycles; c++ {
next, _, _ := ComputeUpdate(w, r.Gen(eventsPerCycle), p)
sum := decimal.Zero
for _, d := range Dimensions {
sum = sum.Add(next[d])
if next[d].GreaterThan(maxSeen[d]) {
maxSeen[d] = next[d]
}
if next[d].LessThan(minSeen[d]) {
minSeen[d] = next[d]
}
if next[d].LessThan(p.Floor) || next[d].GreaterThan(p.Ceiling) {
sim.ClampsHeld = false
}
}
if !sum.Equal(decimal.NewFromInt(1)) {
sim.SumAlways1 = false
}
history = append(history, cloneMap(next))
w = next
}
sim.End = cloneMap(w)
sim.MaxSeen, sim.MinSeen = maxSeen, minSeen
sim.Converged = converged(history)
return sim
}
// converged reports whether the last 5 cycles each moved every dimension by under 0.0005.
func converged(history []map[string]decimal.Decimal) bool {
if len(history) < 6 {
return false
}
tol := decimal.RequireFromString("0.0005")
for i := len(history) - 5; i < len(history); i++ {
for _, d := range Dimensions {
if history[i][d].Sub(history[i-1][d]).Abs().GreaterThan(tol) {
return false
}
}
}
return true
}
// Report renders a stable, human readable summary for the model card.
func (s Simulation) Report() string {
var b strings.Builder
fmt.Fprintf(&b, "regime=%s cycles=%d sum_always_1=%v clamps_held=%v converged=%v\n",
s.Regime, s.Cycles, s.SumAlways1, s.ClampsHeld, s.Converged)
for _, d := range Dimensions {
fmt.Fprintf(&b, " %-20s %s -> %s (min %s max %s)\n",
d, s.Start[d].StringFixed(4), s.End[d].StringFixed(4),
s.MinSeen[d].StringFixed(4), s.MaxSeen[d].StringFixed(4))
}
return b.String()
}
func cloneMap(m map[string]decimal.Decimal) map[string]decimal.Decimal {
out := make(map[string]decimal.Decimal, len(m))
for _, d := range Dimensions {
out[d] = m[d]
}
return out
}
// SortedDimensions returns the canonical dimensions (a helper for report consumers that want a
// stable order without importing the package internals).
func SortedDimensions() []string {
out := append([]string(nil), Dimensions...)
sort.Strings(out)
return out
}