Skip to content

Commit

Permalink
Fix numpy incompatibility change for PSRO's joint to marginal probabi…
Browse files Browse the repository at this point in the history
…lity function. See chat in #1148

Fixes: #1148.
PiperOrigin-RevId: 600726087
Change-Id: If5252c931874283f5fea4acb7885f90d4c83f8c0
  • Loading branch information
DeepMind Technologies Ltd authored and lanctot committed Jan 23, 2024
1 parent 5fb7522 commit 520fe93
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions open_spiel/python/algorithms/psro_v2/meta_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,18 @@ def renormalize(probabilities):


def get_joint_strategy_from_marginals(probabilities):
"""Returns a joint strategy matrix from a list of marginals.
"""Returns a joint strategy tensor from a list of marginals.
Args:
probabilities: list of probabilities.
Returns:
A joint strategy from a list of marginals.
A flat joint strategy from a list of marginals.
"""
probas = []
for i in range(len(probabilities)):
probas_shapes = [1] * len(probabilities)
probas_shapes[i] = -1
probas.append(probabilities[i].reshape(*probas_shapes))
result = np.prod(probas)
return result.reshape(-1)
res = np.ones((1,), dtype=np.float64)
for prob in probabilities:
res = res[..., None] @ np.asarray(prob).reshape((1,) * res.ndim + (-1,))
return res.reshape(-1)


def nash_strategy(solver, return_joint=False):
Expand Down

0 comments on commit 520fe93

Please sign in to comment.