Skip to content

ltm-augment: STDDEV/RANK partials silently fall back to delta-ratio #483

Closed

Description

@bpowers

Summary

generate_nonlinear_partial in src/simlin-engine/src/ltm_augment.rs returns the target variable itself for STDDEV and RANK, yielding a delta-ratio (target - PREV(target)) / (source[d] - PREV(source[d])) instead of a true ceteris-paribus partial. Under uniform scaling of all elements, STDDEV does not change but the delta-ratio still reports nonzero per-element attributions -- the score is silently wrong.

MIN and MAX (the scalar two-arg forms) are now handled correctly via explicit nested binary calls with selective PREVIOUS() wrapping at ltm_augment.rs:1348-1372. Only STDDEV and RANK remain.

Locations

  • src/simlin-engine/src/ltm_augment.rs:1374-1381 -- the catch-all returning target_q.to_string() for STDDEV and RANK
  • src/simlin-engine/src/ltm_augment.rs:1375 -- code comment now documents the limitation

Suggested fix

Unroll STDDEV element-by-element with the standard formula, holding the source element live and wrapping all other elements in PREVIOUS():

sqrt(((s[d] - mean_p)^2 + sum_{i != d}(PREV(s[i]) - mean_p)^2) / N)

where

mean_p = (s[d] + sum_{i != d} PREV(s[i])) / N

Similar element-by-element unroll applies to RANK (compare against PREV of all other elements).

Severity

medium (silent correctness)

References

Activity

  1. added
    engine
    ltm
    on May 1, 2026
  2. bpowers commented on May 13, 2026

    @bpowers
    OwnerAuthor

    Resolved by 26ed48d, dd838dd, e866d8a — Phase 6 of the LTM arrays hardening plan (docs/design-plans/2026-05-11-ltm-arrays-hardening.md). generate_nonlinear_partial now builds the analytic STDDEV ceteris-paribus partial — the unrolled population-variance sqrt formula (divisor N, matching vm.rs::Opcode::ArrayStddev, with the mean string-inlined; single-element variance is identically 0) — instead of the delta-ratio stand-in. RANK keeps the delta-ratio by design (an order statistic, non-differentiable, and unreachable as a real scalar/A2A reducer RHS since it returns an array), pinned by test_generate_rank_keeps_delta_ratio so the choice is explicit, not a silent fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions