Skip to content

Stochastic_fictitious_play fails for large valued payoff matrices #101

Open
@katiemcgoldrick

Description

@katiemcgoldrick

In #100 stochastic fictitious play is implemented but it fails for large values pay off matrices due to an overflow error when computing the exponential of large numbers.

>>> import nashpy as nash
>>> import numpy as np
>>> A = np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
>>> B = A + 71
>>> game=nash.Game(A,B)
>>> tuple(game.stochastic_fictitious_play(iterations=10))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-867513ac063a> in <module>
----> 1 x = tuple(game.stochastic_fictitious_play(iterations=10))

c:\users\kathr\desktop\nashpy\src\nashpy\learning\stochastic_fictitious_play.py in stochastic_fictitious_play(A, B, iterations, etha, epsilon_bar, play_counts)
     44         ]
     45 
---> 46         plays = [
     47             np.random.choice(range(len(distribution)), p=distribution)
     48             for distribution in distributions

c:\users\kathr\desktop\nashpy\src\nashpy\learning\stochastic_fictitious_play.py in <listcomp>(.0)
     45 
     46         plays = [
---> 47             np.random.choice(range(len(distribution)), p=distribution)
     48             for distribution in distributions
     49         ]

mtrand.pyx in numpy.random.mtrand.RandomState.choice()

ValueError: probabilities contain NaN

This breaks down because of :

>>> np.exp(700)
1.0142320547350045e+304
>>> np.exp(710)
inf

Speaking with @drvinceknight and @11michalis11 , two possible solutions are 1) catch the error and provide a better error message or 2) rescale the matrix automatically

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions