PoliciesMultiPlayers.Selfish module

Selfish: a multi-player policy where every player is selfish, playing on their side.

  • without knowing how many players there is,

  • and not even knowing that they should try to avoid collisions. When a collision happens, the algorithm simply receive a 0 reward for the chosen arm.

class PoliciesMultiPlayers.Selfish.SelfishChildPointer(mother, playerId)[source]

Bases: PoliciesMultiPlayers.ChildPointer.ChildPointer

Selfish version of the ChildPointer class (just pretty printed).

__str__()[source]

Return str(self).

__module__ = 'PoliciesMultiPlayers.Selfish'
PoliciesMultiPlayers.Selfish.PENALTY = None

Customize here the value given to a user after a collision XXX If it is None, then player.lower (default to 0) is used instead

class PoliciesMultiPlayers.Selfish.Selfish(nbPlayers, nbArms, playerAlgo, penalty=None, *args, **kwargs)[source]

Bases: PoliciesMultiPlayers.BaseMPPolicy.BaseMPPolicy

Selfish: a multi-player policy where every player is selfish, playing on their side.

  • without nowing how many players there is, and

  • not even knowing that they should try to avoid collisions. When a collision happens, the algorithm simply receives a 0 reward for the chosen arm (can be changed with penalty= argument).

__init__(nbPlayers, nbArms, playerAlgo, penalty=None, *args, **kwargs)[source]
  • nbPlayers: number of players to create (in self._players).

  • playerAlgo: class to use for every players.

  • nbArms: number of arms, given as first argument to playerAlgo.

  • *args, **kwargs: arguments, named arguments, given to playerAlgo.

Examples:

>>> from Policies import *
>>> import random; random.seed(0); import numpy as np; np.random.seed(0)
>>> nbArms = 17
>>> nbPlayers = 6
>>> s = Selfish(nbPlayers, nbArms, Uniform)
>>> [ child.choice() for child in s.children ]
[12, 13, 1, 8, 16, 15]
>>> [ child.choice() for child in s.children ]
[12, 9, 15, 11, 6, 16]
  • To get a list of usable players, use s.children.

  • Warning: s._players is for internal use ONLY!

Warning

I want my code to stay compatible with Python 2, so I cannot use the new syntax of keyword-only argument. It would make more sense to have *args, penalty=PENALTY, lower=0., amplitude=1., **kwargs instead of penalty=PENALTY, *args, **kwargs but I can’t.

nbPlayers = None

Number of players

penalty = None

Penalty = reward given in case of collision

children = None

List of children, fake algorithms

nbArms = None

Number of arms

__str__()[source]

Return str(self).

_handleCollision_one(playerId, arm, reward=None)[source]

Give a reward of 0, or player.lower, or self.penalty, in case of collision.

__module__ = 'PoliciesMultiPlayers.Selfish'