示例#1
0
def alpharank_strategy(solver, return_joint=False, **unused_kwargs):
    """Returns AlphaRank distribution on meta game matrix.

  This method works for general games.

  Args:
    solver: GenPSROSolver instance.
    return_joint: a boolean specifying whether to return player-wise
      marginals.

  Returns:
    marginals: a list, specifying for each player the alpharank marginal
      distributions on their strategies.
    joint_distr: a list, specifying the joint alpharank distributions for all
      strategy profiles.
  """
    meta_games = solver.get_meta_game()
    meta_games = [
        np.array([[1.1, -10], [1, -1], [-1, 1]]),
        np.array([[-1.1, 10], [-1, 1], [1, -1]])
    ]
    meta_games = [np.asarray(x) for x in meta_games]

    if solver.symmetric_game:
        meta_games = [meta_games[0]]

        # Get alpharank distribution via alpha-sweep
        joint_distr = alpharank.sweep_pi_vs_epsilon(meta_games)
        joint_distr = remove_epsilon_negative_probs(joint_distr)

        marginals = 2 * [joint_distr]
        joint_distr = get_joint_strategy_from_marginals(marginals)
        if return_joint:
            return marginals, joint_distr
        else:
            return joint_distr

    else:
        joint_distr = alpharank.sweep_pi_vs_epsilon(meta_games)
        joint_distr = remove_epsilon_negative_probs(joint_distr)

        if return_joint:
            marginals = get_alpharank_marginals(meta_games, joint_distr)
            return marginals, joint_distr
        else:
            return joint_distr
示例#2
0
def _alpharank(meta_game, per_player_repeats, ignore_repeats=False):
  """AlphaRank."""
  if not ignore_repeats:
    meta_game = _expand_meta_game(meta_game, per_player_repeats)
  meta_dist = alpharank_lib.sweep_pi_vs_epsilon([mg for mg in meta_game])
  meta_dist[meta_dist < DIST_TOL] = 0.0
  meta_dist /= np.sum(meta_dist)
  meta_dist = np.reshape(meta_dist, meta_game.shape[1:])
  if not ignore_repeats:
    meta_dist = _unexpand_meta_dist(meta_dist, per_player_repeats)
  return meta_dist, dict()