GithubHelp home page GithubHelp logo

cristal-smac / ipd Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 5.0 39.25 MB

All about Iterated Prisoner's Dilemma. Python code and jupyter notebooks. See how to build new strategies and evaluate them.

License: GNU Lesser General Public License v3.0

Jupyter Notebook 90.34% Python 9.66%
game-theory iterated-prisoners-dilemma multiagent-systems complex-systems strategies prisoners dilemma python game prisoner-dilemma-simulation

ipd's People

Contributors

celinepetitpre avatar cristal-smac avatar pmathieufr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ipd's Issues

Bug report on getAction function of Tf2t class

According to the definition of Tf2t, Tf2t strategy will defect only when the opponent defected in the previous two moves.
In your implementation of Tf2t, it will defect when the opponent defected in the previous move, so
I think the following program needs to be modified. We present the modified version as “After fix”.

Now

ipd/src/strategies.py

Lines 60 to 67 in e6862a8

def getAction(self, tick):
if tick == 0 or tick == 1:
return "C"
else:
if self.hisPast[-1] == "D" and self.hisPast[-2]:
return "D"
else:
return "C"

After fix

    def getAction(self, tick):
        if tick == 0 or tick == 1:
            return "C"
        else:
            if self.hisPast[-1] == "D" and self.hisPast[-2]=="D": #here
                return "D"
            else:
                return "C"

AttributeError: 'Game' object has no attribute 'ran'


AttributeError Traceback (most recent call last)
Cell In[38], line 13
9 bag += [setGenericName(strat)]
12 # Evolution of the initial class
---> 13 e1 = Ecological(g, mem11)
14 e1.run()
16 evol=e1.historic

File ~/Dropbox/newGit/prisoners del/src/ipd.py:127, in Ecological.init(self, tournament, pop, max_iter)
125 self.max_iter = max_iter
126 self.tournament = tournament
--> 127 if not tournament.ran:
128 print("warning: running passed Tournament. This step may take a while.")
129 self.tournament.run()

AttributeError: 'Game' object has no attribute 'ran'

Running a ecological simulation results in an error

Running the provided example or anything else as an ecological simulation fails:

Python version:

Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32

I'm running this on Windows 10 64-bit if that helps.

Error Message:

>>> e.run()
C:\Users\macbr\Programming\ipd\src\ipd.py:206: RuntimeWarning: overflow encountered in long_scalars
  self.base * parent * self.scores[strat.name] / total
C:\Users\macbr\Programming\ipd\src\ipd.py:193: RuntimeWarning: overflow encountered in long_scalars
  self.scores[strat.name]
C:\Users\macbr\Programming\ipd\src\ipd.py:192: RuntimeWarning: overflow encountered in long_scalars
  total += (
C:\Users\macbr\Programming\ipd\src\ipd.py:206: RuntimeWarning: invalid value encountered in long_scalars
  self.base * parent * self.scores[strat.name] / total
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\macbr\Programming\GitHub\ipd\src\ipd.py", line 205, in run
    self.historic.at[self.generation + 1, strat.name] = math.floor(
ValueError: cannot convert float NaN to integer

or

>>> e.run()
C:\Users\macbr\Programming\ipd\src\ipd.py:206: RuntimeWarning: overflow encountered in long_scalars
  self.base * parent * self.scores[strat.name] / total
C:\Users\macbr\Programming\ipd\src\ipd.py:193: RuntimeWarning: overflow encountered in long_scalars
  self.scores[strat.name]
C:\Users\macbr\Programming\ipd\src\ipd.py:192: RuntimeWarning: overflow encountered in long_scalars
  total += (
Warning : max_iter reached

at one point also:

>>> e.run()
C:\Users\macbr\Programming\ipd\src\ipd.py:206: RuntimeWarning: overflow encountered in long_scalars
  self.base * parent * self.scores[strat.name] / total
Warning : max_iter reached

DrawPlot() Results:

These are the drawPlot() results for the example in the README.md
Figure_

The affected readme for reference f2f766d

Unfortunately I don't have much experience with python, else I would try to fixing these issues myself.
Macbrayne

Are the ecological simulation examples working?

I'm having troubles executing the examples for running a ecological simulation. If I try running

from ipd import *
from strategies import *

bag=[Periodic("D"), HardMajority(), Tft(), Spiteful(),  Gradual()]
e= Ecological(g,bag, 1000, pop=[100])
e.run()
e.tournament.matrix
e.historic
e.drawPlot()

I get the error message:

Traceback (most recent call last):
  File "c:/Users/<redacted>/GitHub/ipd_experiments/test.py", line 5, in <module>
    e= Ecological(g,bag, 1000, pop=[100])
TypeError: __init__() got multiple values for argument 'pop'

I'm unfortunately not very experienced in Python; is this connected to your recent changes to the Ecological class?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.