Ejemplo n.º 1
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))
Ejemplo n.º 2
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()