Skip to content

ltm: GF strict-monotonicity check (EPSILON=1e-10) flags numeric-import noise as Unknown #492

Closed

Description

@bpowers

Summary

analyze_graphical_function_polarity in src/simlin-engine/src/ltm.rs (around ltm.rs:2341, currently lines ~2378-2404) uses a strict EPSILON = 1e-10 to classify a graphical function as monotonically increasing, decreasing, or constant. Any per-segment slope inside [-EPSILON, +EPSILON] is treated as a plateau (which by itself is fine), but a single segment that crosses the threshold in the wrong direction collapses the whole table to Unknown.

In practice, lookup tables imported from Vensim/XMILE often carry round-trip numeric noise on the order of 1e-7 to 1e-3 (rounding during XML serialisation, conversion through float32 in legacy formats, manual data entry). With the current 1e-10 threshold, a table that is monotonically non-decreasing modulo noise -- e.g. y values [0.0, 0.5000001, 0.4999999, 1.0, 1.5] -- gets classified Unknown because of the second segment, even though the function is unambiguously increasing in spirit and in every other measure.

This is the second half of #480; the array-reducer half is being fixed in PR #491 and the polarity-analyzer reducer cases are already addressed there. This issue tracks the GF-monotonicity epsilon concern separately, so it can be picked up without re-investigating reducer behaviour.

Why this matters

Monotonic table-based relationships are very common in SD modelling (smooth dose-response curves, demand schedules, learning curves, allocation profiles). Misclassifying any of them as Unknown propagates through analyze_link_polarity and produces Undetermined loop classifications for any loop that crosses the lookup -- exactly the failure mode the rest of the LTM polarity analysis is trying to avoid.

Locations

Suggested fix

A plateau-tolerant monotonicity check that ignores noise below a configurable epsilon rather than the strict 1e-10. Two reasonable approaches:

  1. Relative threshold: scale epsilon by the maximum y-range of the table, e.g. EPSILON = max(1e-6 * (y_max - y_min), 1e-12). Tables with unit-scale y values get 1e-6 tolerance; tables with very-small or very-large absolute y values still get a sensible relative tolerance.
  2. Counted violations: allow up to N segments to violate strict monotonicity without flipping the verdict, where N scales with the number of segments and the magnitude of the violation (so a single tiny dip in a 50-segment increasing table is forgiven, but a real direction change is not).

Option 1 is simpler and probably enough; option 2 is more robust but harder to tune. A unit test should cover: (a) clean monotone tables retain their polarity, (b) noisy-but-monotone tables now retain their polarity, (c) genuinely non-monotone tables still return Unknown.

Severity

medium

References

Activity

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

    @bpowers
    OwnerAuthor

    Resolved by ee07c93 (test coverage hardened in 25a303d) — Phase 7 of the LTM arrays hardening plan (docs/design-plans/2026-05-11-ltm-arrays-hardening.md). The graphical-function strict-monotonicity check uses a y-range-relative epsilon — max(EPSILON, range_rel * (y_max - y_min)) — so numeric-import noise on a near-flat lookup arm no longer flips an otherwise-monotone curve to Unknown. (The residual nuance that the check compares the y-delta rather than the slope dy/dx — non-uniform x-spacing — is tracked separately as GH #536.)

  3. added 2 commits that reference this issue on Jun 10, 2026
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