Exemplo n.º 1
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()
Exemplo n.º 2
0
import numpy as np
import sys
import utils

r = 10**-3
size = 3
iterations = 10 * 10**4

s1 = utils.randomize_mixed_strategy(size)
s2 = utils.randomize_mixed_strategy(size)
# s1 = np.array([.5, .5, 0, 0, 0, 0])
# s2 = np.array([0, 0, 0, 0, .5, .5])
print('initial strategy:', s1)
print('initial strategy:', s2)

vertex_payoff = utils.randomize_payoff_vector(size)
# vertex_payoff = np.array([-383, 843, 843])
vertex_payoff *= 1
print('payoff:', vertex_payoff)

distance_ratio_l = []
distance_old = 10**8
distance_ratio_old = 0
s1_l = []
s2_l = []
for i in range(iterations):
    s1_l.append(s1)
    s2_l.append(s2)
    distance = np.linalg.norm(s1 - s2)
    payoff_1 = s1.dot(vertex_payoff)
    payoff_2 = s2.dot(vertex_payoff)