Skip to content

FIX: Address issues in AS and its tests - #235

Merged
oyamad merged 6 commits into
mainfrom
as_fixes
Jul 2, 2026
Merged

oyamad merged 6 commits into
mainfrom
as_fixes

Conversation

@oyamad

@oyamad oyamad commented Jul 2, 2026

Copy link
Copy Markdown
Member

This PR addresses several issues in the AS implementation and its tests,
found in a review of the code introduced in #65 and #191. Four independent
changes, one commit each:

1. TST: Make vertices_match_expected check both directions

The test helper introduced in #191 only checked that every computed vertex
matches some expected vertex, so a strict subset of the expected vertices —
or even an empty matrix — would pass all the AS testsets. The helper now
also requires that every expected vertex is matched by some computed vertex,
i.e., the two vertex sets must coincide as sets of points within tolerance.
This still accommodates the near-duplicate vertices that the exact
arithmetic path may return (e.g., the (6, 2) result in the AS
docstring example), without pinning the vertex count.

2. FIX: Update threat point componentwise in AS

The threat point update replaced the whole vector u whenever any
component of the new minima exceeded the corresponding component of u,
which could lower the other component if the new minima are not
componentwise weakly greater — possible under floating point roundoff, even
though exact arithmetic guarantees monotonicity. Now takes the
componentwise maximum.

3. FIX: Detect IC boundary vertices with explicit atol in AS

Vertices of the intersection polyhedron lying on the IC boundaries were
detected with isapprox at its defaults (atol=0, relative tolerance
only). A relative tolerance never holds at an IC boundary located at 0
unless the computed coordinate is exactly zero, so any rounding in the
intersection computation would silently drop such boundary vertices in the
Float64 path. The check now uses an absolute tolerance proportional to
the payoff scale; in exact arithmetic the tolerance is zero, preserving the
exact comparison.

Note: this guards a latent failure mode. I could not trigger it on games
with clean payoffs (CDDLib returns exact zeros there, and the Float64
results agree with the exact arithmetic ground truth before and after the
change).

4. ENH: Preserve rows and eltype in uniquetolrows

uniquetolrows deduplicated by rounding all entries to about
-log10(tol) digits, which (i) returned rounded values instead of the
input rows, (ii) changed the element type (e.g., Rational{BigInt} →
BigFloat), and (iii) failed to merge rows within tol that straddle a
rounding boundary (e.g., rows at 0.00049999 and 0.00050001 with
tol=1e-3). It now deduplicates by greedy clustering: scanning from the
top, a row is dropped iff it is within tol, in Chebyshev distance, of a
row retained earlier; the retained rows keep their exact values and element
type.

Behavior change for callers relying on the rounded/float output of
uniquetolrows. The AS docstring example is updated accordingly.

Verification

  • The full repeated-game testset passes after each commit.
  • The strengthened helper rejects subset/empty results while accepting the
    exact-arithmetic output with near-duplicate vertices.
  • For change 3, Float64 results on a game with minimax payoff exactly 0
    agree with the exact arithmetic (Int payoffs, 3//4 delta) ground truth.

Not included here: replacing the per-action-pair polyhedron intersections
with direct 2D polygon clipping (as in Abreu and Sannikov's own pivot
procedure), which would remove the fragility behind change 3 structurally
and speed up AS considerably. That is a larger rewrite, left for a
separate PR; the strengthened tests from this PR are a prerequisite for it.

🤖 Generated with Claude Code (Claude Fable 5)

oyamad and others added 4 commits July 2, 2026 15:09
The helper previously only checked that every computed vertex matches
some expected vertex, so a subset of the expected vertices -- or even an
empty matrix -- would pass. Require, in addition, that every expected
vertex is matched by some computed vertex, so that the two vertex sets
must coincide as sets of points within tolerance. This keeps
accommodating the near-duplicate vertices that the exact arithmetic
path may return, without pinning the vertex count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The threat point update replaced the whole vector u whenever any
component of the new minima u_ exceeded the corresponding component of
u, which could lower the other component whenever u_ is not
componentwise weakly greater -- possible under floating point roundoff
even though exact arithmetic guarantees monotonicity. Take the
componentwise maximum instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The vertices of the intersection polyhedron lying on the IC boundaries
were detected with `isapprox` at its defaults, i.e., `atol=0` and a
relative tolerance. A relative tolerance never holds at an IC boundary
located at 0 unless the computed vertex coordinate is exactly zero, so
any rounding in the intersection computation would silently drop such
boundary vertices in the Float64 path. Supply an absolute tolerance
proportional to the payoff scale instead. In exact arithmetic the
tolerance is zero, preserving the exact comparison (the previous
behavior, where the default relative tolerance for non-float types
is 0).

No behavioral change on the test games (Float64 results agree with the
exact arithmetic ground truth before and after); this guards a latent
failure mode for games whose IC boundaries pass through 0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
uniquetolrows previously deduplicated by rounding all entries to
roughly -log10(tol) digits, which (i) returned rounded values instead
of the input rows, (ii) changed the element type (e.g.,
Rational{BigInt} to BigFloat), and (iii) failed to merge rows within
tol that straddle a rounding boundary (e.g., rows at 0.00049999 and
0.00050001 with tol=1e-3). Deduplicate by greedy clustering instead:
scanning from the top, drop a row iff it is within tol, in Chebyshev
distance, of a row retained earlier. The retained rows are returned
with their exact values and element type.

Behavior change for callers relying on the rounded/float output; the
AS docstring example is updated accordingly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes correctness and robustness issues in the Abreu–Sannikov (AS) repeated-game algorithm implementation and strengthens its tests, addressing edge cases uncovered in prior reviews (notably around floating-point tolerances and vertex set comparisons).

Changes:

  • Strengthens the AS test helper to verify vertex sets match in both directions (preventing subset/empty false positives).
  • Fixes AS threat-point (u) updates to be componentwise monotone and adds an absolute-tolerance-aware IC-boundary vertex detection.
  • Updates uniquetolrows to preserve original rows and element type by deduplicating via tolerance-based greedy clustering (and updates the docstring example accordingly).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/test_repeated_game.jl Strengthens AS-related tests by enforcing two-way vertex-set matching within tolerance.
src/repeated_game.jl Fixes AS numerical robustness (IC boundary detection, threat-point update) and improves uniquetolrows semantics/docstring.

Comment thread src/repeated_game.jl Outdated
Comment on lines +681 to +682
atol_IC = S <: AbstractFloat ?
sqrt(eps(S)) * max(one(S), maximum(abs, v_old)) : zero(S)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, adopted in 3d14b2a: atol_IC now uses the actual max-abs payoff scale, falling back to 1 only when the scale is exactly 0.

One note on the cited risk: admitting a non-boundary vertex is the benign direction here. The point pushed for such a vertex w is (1-δ)g(a) + δw, which is a legitimate element of B_a(W) whether or not w is on the IC boundary, so it can only add redundant points that removevredundancy! discards. Missing a true boundary vertex is the harmful direction, which is why the tolerance originally erred large; the proportional version is cleaner and still covers the (relative) rounding errors involved.

(Reply drafted by Claude Fable 5.)

Comment thread src/repeated_game.jl
Comment on lines +787 to +791
for i in 1:size(V, 1)
if !any(j -> maximum(abs, V[i, :] - V[j, :]) < tol, keep)
push!(keep, i)
end
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopted in a33e8ab: the comparison is now <=, so tol=0 performs exact deduplication, matching the docstring wording. This is meaningful in particular for Rational matrices from the exact arithmetic path.

Left out the negative-tolerance check: with <=, a negative tol naturally deduplicates nothing, which seems a sensible degenerate behavior not worth an explicit branch.

(Reply drafted by Claude Fable 5.)

oyamad and others added 2 commits July 2, 2026 15:47
Follow up on review: atol_IC floored the payoff scale at 1, making the
boundary-detection tolerance larger than the payoff scale for games
with payoffs smaller than 1 in magnitude. Use the actual max-abs payoff
scale, falling back to 1 only when the scale is exactly 0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Follow up on review: the strict comparison meant tol=0 removed nothing,
not even exactly duplicate rows, contradicting the docstring wording
"within tol". With <=, tol=0 performs exact deduplication, which is
meaningful in particular for Rational matrices from the exact
arithmetic path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@oyamad
oyamad merged commit 7dc54cf into main Jul 2, 2026
5 checks passed
@oyamad
oyamad deleted the as_fixes branch July 2, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants