Beispiel #1
0
import numpy as np
import utils

iters = 1 * 10 ** 5
rate = 10 ** -5
payoff_scale = 10 ** 0

display_game = True
use_LH = True

# str_row_init = np.array([0.1667, 0.5, 0.3333])
# str_col_init = np.array([0.3333, 0.5, 0.1667])
str_row_init = utils.randomize_mixed_strategy(3)
str_col_init = utils.randomize_mixed_strategy(3)

payoff_matrix_row = np.array([
    [678, 110, -33],
    [-673, 942, -995],
    [-683, 725, -372]])
payoff_matrix_col = np.array([
    [328.0, 976.0, 442.0],
    [-19.0, 669.0, 701.0],
    [587.0, -209.0, -55.0]])
Beispiel #2
0
    def FPI(self):
        s = self.init_strategy
        for i in range(self.iters):
            payoff = s.dot(self.vertex_payoff)
            vertex_gain = np.where((self.vertex_payoff - payoff) > 0, self.vertex_payoff - payoff, 0)
            # vertex_gain = np.apply_along_axis(lambda x: 10 ** 4 * x * x, 0, vertex_gain)
            vertex_gain = np.apply_along_axis(lambda x: x, 0, vertex_gain)
            s = utils.vector_update(s, vertex_gain, self.rate)
        self.vertex_gain = vertex_gain
        self.strategy = s
        self.angle = utils.vector_angle(self.strategy, self.vertex_gain)
        self.payoff = payoff
        self.gamma = vertex_gain.dot(vertex_gain) / (1 / self.rate + vertex_gain.sum())

    def stats(self):
        print('strategy: %s\nvertex gain: %s\npayoff: %s vertex gain sum: %s angle: %s gamma: %s' % (
            self.strategy.tolist(), self.vertex_gain.tolist(), self.payoff, self.vertex_gain.sum(), self.angle, self.gamma))
        print('***')


if __name__ == "__main__":
    size = 6
    strategy = Strategy(
        utils.randomize_mixed_strategy(size),
        utils.randomize_payoff_vector(size) * 100,
        200 * 10 ** 4,
        10 ** -3)

    strategy.FPI()
    strategy.stats()
Beispiel #3
0
import numpy as np
import sys
sys.path.append('../')
import utils

iters = 10 * 10**4
rate = 10**-4
payoff_scale = 10**0

png_name = '60X40-disconv.png'

rows = 60
cols = 40

str_row_init = utils.randomize_mixed_strategy(rows)
str_col_init = utils.randomize_mixed_strategy(cols)

payoff_matrix_row, payoff_matrix_col = utils.randomize_payoff_matrix(
    rows, cols)
Beispiel #4
0
             [settings.payoff_matrix_row, settings.payoff_matrix_col])
if display_game:
    fpi.print_game()
fpi.converge(rate, iters)
FPI_2P.display_eqpt(fpi.eqpt())
if use_LH:
    fpi.lemke_howson()
if contraction_test:
    pass

# ############################# contraction test #############################
if contraction_test:
    import contraction
    import utils
    rows, cols = settings.payoff_matrix_row.shape
    strategies_profile_1 = (utils.randomize_mixed_strategy(rows),
                            utils.randomize_mixed_strategy(cols))
    strategies_profile_2 = (utils.randomize_mixed_strategy(rows),
                            utils.randomize_mixed_strategy(cols))
    distance_function = contraction.distance_function_1
    payoff_matrices = (settings.payoff_matrix_row, settings.payoff_matrix_col)
    rate = settings.rate
    iters = settings.iters

    distance_l = []
    for i in range(iters):
        distance = distance_function(strategies_profile_1,
                                     strategies_profile_2)
        distance_l.append(np.log(distance))
        strategies_profile_1 = contraction.FPI_transformation_once(
            strategies_profile_1, payoff_matrices, rate)
Beispiel #5
0
import numpy as np
import utils

iters = 1 * 10**5
rate = 10**-5
payoff_scale = 10**0

display_game = True
use_LH = True

annotate_game_details = False
png_name = '3X3-1eq3sp-repellor'

payoff_matrix_row = np.array([[678, 110, -33], [-673, 942, -995],
                              [-683, 725, -372]])
payoff_matrix_col = np.array([[328.0, 976.0, 442.0], [-19.0, 669.0, 701.0],
                              [587.0, -209.0, -55.0]])

eqpts = [
    (np.array([0.1555637623931138, 0.3850174710945712, 0.459418766512315]),
     np.array([0.2116999757925876, 0.5821356134801096, 0.20616441072730282]))
]

devi = 0.00001
str_row_init_l = [
    utils.pick_a_neighour(eqpts[0][0], devi=devi) for i in range(5)
] + [utils.randomize_mixed_strategy(3) for i in range(5)]
str_col_init_l = [
    utils.pick_a_neighour(eqpts[0][1], devi=devi) for i in range(5)
] + [utils.randomize_mixed_strategy(3) for i in range(5)]
Beispiel #6
0
 def init_mixed_strategies(self):
     self.mixed_strategy = utils.randomize_mixed_strategy(
         self.pure_strategies_num)
Beispiel #7
0
import numpy as np
import utils

iters = 10**5
rate = 10**-5
payoff_scale = 10**0

display_game = True
use_LH = True

annotate_game_details = False
png_name = '3X3-2eq2sp-attractor'

paths = 10
str_row_init_l = [np.array([0.2372, 0.4233, 0.3395]), np.array([0.1076, 0.4191, 0.4733])] + \
    [utils.randomize_mixed_strategy(3) for i in range(paths - 2)]
str_col_init_l = [np.array([0.5481, 0.3365, 0.1154]), np.array([0.2, 0.4176, 0.3824])] + \
    [utils.randomize_mixed_strategy(3) for i in range(paths - 2)]

payoff_matrix_row = np.array([[-231.0, -505.0, 525.0], [-552.0, 831.0, -928.0],
                              [-74.0, -96.0, -604.0]])
payoff_matrix_col = np.array([[175.0, -350.0, -770.0],
                              [-641.0, -222.0, -189.0], [302.0, 504.0, 767.0]])
eqpts = [(np.array([0.3297872340425532, 0.0, 0.6702127659574468]),
          np.array([0.8779160186625193, 0.0, 0.12208398133748055])),
         (np.array([0.0728476821192053, 0.9271523178807947, 0.0]),
          np.array([0.0, 0.5209752599498029, 0.4790247400501973]))]
Beispiel #8
0
import numpy as np
import utils

iters = 1 * 10**5
rate = 10**-5
payoff_scale = 10**0

display_game = True
use_LH = True

str_row_init = utils.randomize_mixed_strategy(
    3)  # np.array([0.2811, 0.4424, 0.2765])
str_col_init = utils.randomize_mixed_strategy(
    3)  # np.array([0.3251, 0.3086, 0.3663])

payoff_matrix_row = np.array([[-503, -349, 177], [-868, 855, -199],
                              [660, 429, 206]])

payoff_matrix_col = np.array([[49.0, 780.0, -105.0], [789.0, -404.0, 226.0],
                              [387.0, 642.0, -756.0]])
Beispiel #9
0
import numpy as np
import utils

iters = 3 * 10**5
rate = 10**-5
payoff_scale = 10**0

display_game = False
use_LH = False

str_row_init = utils.randomize_mixed_strategy(1000)
str_col_init = utils.randomize_mixed_strategy(800)
payoff_matrix_row, payoff_matrix_col = utils.randomize_payoff_matrix(1000, 800)
Beispiel #10
0
import numpy as np
import sys
sys.path.append('../')
import utils

iters = 10 * 10**4
rate = 10**-4
payoff_scale = 10**0

# settings
rows = 120
cols = 100

str_row_init = utils.randomize_mixed_strategy(rows) * payoff_scale
str_col_init = utils.randomize_mixed_strategy(cols) * payoff_scale

payoff_matrix_row, payoff_matrix_col = utils.randomize_payoff_matrix(
    rows, cols)