Repository navigation
Conversation
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>
There was a problem hiding this comment.
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
AStest helper to verify vertex sets match in both directions (preventing subset/empty false positives). - Fixes
ASthreat-point (u) updates to be componentwise monotone and adds an absolute-tolerance-aware IC-boundary vertex detection. - Updates
uniquetolrowsto 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. |
| atol_IC = S <: AbstractFloat ? | ||
| sqrt(eps(S)) * max(one(S), maximum(abs, v_old)) : zero(S) |
There was a problem hiding this comment.
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.)
| for i in 1:size(V, 1) | ||
| if !any(j -> maximum(abs, V[i, :] - V[j, :]) < tol, keep) | ||
| push!(keep, i) | ||
| end | ||
| end |
There was a problem hiding this comment.
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.)
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>
This PR addresses several issues in the
ASimplementation 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_expectedcheck both directionsThe 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
AStestsets. The helper nowalso 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 theASdocstring example), without pinning the vertex count.
2. FIX: Update threat point componentwise in
ASThe threat point update replaced the whole vector
uwhenever anycomponent 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
atolinASVertices of the intersection polyhedron lying on the IC boundaries were
detected with
isapproxat its defaults (atol=0, relative toleranceonly). 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
Float64path. The check now uses an absolute tolerance proportional tothe 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
Float64results agree with the exact arithmetic ground truth before and after the
change).
4. ENH: Preserve rows and eltype in
uniquetolrowsuniquetolrowsdeduplicated by rounding all entries to about-log10(tol)digits, which (i) returned rounded values instead of theinput rows, (ii) changed the element type (e.g.,
Rational{BigInt}→BigFloat), and (iii) failed to merge rows withintolthat straddle arounding boundary (e.g., rows at
0.00049999and0.00050001withtol=1e-3). It now deduplicates by greedy clustering: scanning from thetop, a row is dropped iff it is within
tol, in Chebyshev distance, of arow retained earlier; the retained rows keep their exact values and element
type.
Behavior change for callers relying on the rounded/float output of
uniquetolrows. TheASdocstring example is updated accordingly.Verification
exact-arithmetic output with near-duplicate vertices.
Float64results on a game with minimax payoff exactly 0agree with the exact arithmetic (
Intpayoffs,3//4delta) 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
ASconsiderably. That is a larger rewrite, left for aseparate PR; the strengthened tests from this PR are a prerequisite for it.
🤖 Generated with Claude Code (Claude Fable 5)