def __init__(self,
                 name,
                 starting_distribution,
                 dist_params=None,
                 **params):
        """Initializes the team and gives it a starting strategy distribution.

        Args:
            params:
                dimension: the side length of the strategy distribution matrix
                number_of_teams: the total number of teams in the game
            starting_distribution: the type of distribution to start with
        """

        # Unpack parameters
        dimension = params['DIMENSION']
        number_of_teams = params['NUMBER_OF_TEAMS']

        self.name = name

        # Assume square strategy space
        shape = (dimension, dimension)

        # Initialize strategy distribution
        if starting_distribution == 'rand':
            self.distribution = random_array(shape)
        elif starting_distribution == 'cluster':
            self.distribution = binomial_product_array(shape, dist_params['p'])
        elif starting_distribution == 'uniform':
            self.distribution = uniform_array(shape)
        else:
            print "Critical error."
            sys.exit()

        # Initialize fitness
        self.scores = np.zeros((dimension, dimension))

        self.population = 1.0 / number_of_teams

        self.stats = pd.DataFrame(columns=('population', 'average_deal',
                                           'center_of_mass'))
示例#2
0
    def __init__(self, name, starting_distribution, dist_params=None, **params):
        """Initializes the team and gives it a starting strategy distribution.

        Args:
            params:
                dimension: the side length of the strategy distribution matrix
                number_of_teams: the total number of teams in the game
            starting_distribution: the type of distribution to start with
        """

        # Unpack parameters
        dimension = params['DIMENSION']
        number_of_teams = params['NUMBER_OF_TEAMS']

        self.name = name

        # Assume square strategy space
        shape = (dimension, dimension)

        # Initialize strategy distribution
        if starting_distribution == 'rand':
            self.distribution = random_array(shape)
        elif starting_distribution == 'cluster':
            self.distribution = binomial_product_array(shape, dist_params['p'])
        elif starting_distribution == 'uniform':
            self.distribution = uniform_array(shape)
        else:
            print "Critical error."
            sys.exit()

        # Initialize fitness
        self.scores = np.zeros((dimension, dimension))

        self.population = 1.0 / number_of_teams

        self.stats = pd.DataFrame(columns = ('population', 
                                             'average_deal',
                                             'center_of_mass'))
# INITIALIZE STRATEGIES

# TODO: Change this so that the teams can have different initial strategy types
# altogether.

if STARTING_DISTRIBUTION == 'rand':
    teams1 = np.random.random( (DIMENSION,DIMENSION))
    teams1 = teams1 / teams1.sum()   
    teams2 = np.random.random( (DIMENSION,DIMENSION))
    teams2 = teams2 / teams2.sum()  
    teams3 = np.random.random( (DIMENSION,DIMENSION))
    teams3 = teams3 / teams3.sum()   
    
elif STARTING_DISTRIBUTION == 'cluster':
    teams1 = binomial_product_array((DIMENSION, DIMENSION), (0.3, 0.7))
    teams2 = binomial_product_array((DIMENSION, DIMENSION), (0.7, 0.3))
    teams3 = binomial_product_array((DIMENSION, DIMENSION), (0.5, 0.5))
    
elif STARTING_DISTRIBUTION == 'uniform':
    teams1 = [STARTING_PCT] * DIMENSION ** 2
    teams1 = np.reshape(original_teams1, (DIMENSION, DIMENSION))
    teams2 = [STARTING_PCT] * DIMENSION ** 2
    teams2 = np.reshape(teams2, (DIMENSION, DIMENSION))
    teams3 = [STARTING_PCT] * DIMENSION ** 2
    teams3 = np.reshape(teams3, (DIMENSION, DIMENSION))

# To Andrew: it may be worth noting that you are creating pointers here, not
# creating copies.
data1, data2, data3 = teams1, teams2, teams3
# INITIALIZE STRATEGIES

# TODO: Change this so that the teams can have different initial strategy types
# altogether.

if STARTING_DISTRIBUTION == 'rand':
    teams1 = np.random.random((DIMENSION, DIMENSION))
    teams1 = teams1 / teams1.sum()
    teams2 = np.random.random((DIMENSION, DIMENSION))
    teams2 = teams2 / teams2.sum()
    teams3 = np.random.random((DIMENSION, DIMENSION))
    teams3 = teams3 / teams3.sum()

elif STARTING_DISTRIBUTION == 'cluster':
    teams1 = binomial_product_array((DIMENSION, DIMENSION), (0.3, 0.7))
    teams2 = binomial_product_array((DIMENSION, DIMENSION), (0.7, 0.3))
    teams3 = binomial_product_array((DIMENSION, DIMENSION), (0.5, 0.5))

elif STARTING_DISTRIBUTION == 'uniform':
    teams1 = [STARTING_PCT] * DIMENSION**2
    teams1 = np.reshape(original_teams1, (DIMENSION, DIMENSION))
    teams2 = [STARTING_PCT] * DIMENSION**2
    teams2 = np.reshape(teams2, (DIMENSION, DIMENSION))
    teams3 = [STARTING_PCT] * DIMENSION**2
    teams3 = np.reshape(teams3, (DIMENSION, DIMENSION))

# To Andrew: it may be worth noting that you are creating pointers here, not
# creating copies.
data1, data2, data3 = teams1, teams2, teams3