예제 #1
0
def equilibrium_regrets(game, eq):
	if is_mixed_profile(eq):
		eq = game.toArray(eq)
	if is_mixture_array(eq):
		return game.getExpectedPayoff(eq).reshape(eq.shape[0],1) - \
				game.expectedValues(eq)
	regrets = {}
	for role in game.roles:
		regrets[role] = {}
		for strategy in game.strategies[role]:
			regrets[role][strategy] = -regret(game, eq, deviation=strategy)
	return regrets
예제 #2
0
def regret(game, prof, role=None, strategy=None, deviation=None, bound=False):
	if role == None and len(game.roles) == 1:
		role = game.roles[0] #in symmetric games we can deduce the role
	if is_pure_profile(prof):
		return profile_regret(game, prof, role, strategy, deviation, bound)
	if is_mixture_array(prof):
		return mixture_regret(game, prof, role, deviation, bound)
	if is_mixed_profile(prof):
		return mixture_regret(game, game.toArray(prof), role, deviation, bound)
	if is_profile_array(prof):
		return profile_regret(game, game.toProfile(prof), role, strategy, \
				deviation, bound)
	raise TypeError(one_line("unrecognized profile type: " + str(prof), 69))
예제 #3
0
def social_welfare(game, profile, role=None):
	"""
	Sums values for a pure profile or expected values for a mixed profile.

	Restricts sum to specified role if role != None.
	"""
	if is_pure_profile(profile):
		values = (game.values[game[profile]] * game.counts[game[profile]])
	elif is_mixture_array(profile):
		players = np.array([game.players[r] for r in game.roles])
		values = (game.getExpectedPayoff(profile) * players)
	elif is_profile_array(profile):
		return social_welfare(game, game.toProfile(profile))
	elif is_mixed_profile(profile):
		return social_welfare(game, game.toArray(profile))
	else:
		raise TypeError("unrecognized profile type: " + str(profile))
	if role == None:
		return values.sum()
	else:
		return values[game.index(role)].sum()