Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

635 Implementing spatial tournaments #654

Merged
merged 25 commits into from
Jul 18, 2016
Merged

635 Implementing spatial tournaments #654

merged 25 commits into from
Jul 18, 2016

Conversation

Nikoleta-v3
Copy link
Member

@Nikoleta-v3 Nikoleta-v3 commented Jul 13, 2016

Closes #635.

  • Implemented a new tournament class and a new match generator class for spatial tournaments
  • Appropriate tests for the new classes have been written
  • Created a doc file in the further issues for spatial tournaments.

After considering all the thoughts on how to implement a spatial structure tournament, I have decided to
simple consider a list that includes the edges. The new class SpatialMatches() creates
chunks where players - nodes only play players that are connected to with an edge. A tournament
class SpatialTournament was also implemented to pass the edges argument and SpatialMatches
as the match_generator. An error message was also included. Just in case a player is not interacting with anyone . If you have such a player is better to not include him in the tournament at all.

Before creating these classes I had written some tests. For SpatialMatches, SpatialTournament , as well as some property tests. Also a test for comparing the results of a complete multi-graph and a round robin tournament.

In the result set, seems that in the loop statements the self interaction have been counted twice each time. So an if statement had to be altered to an elif.
Also there was one test in the result_tests that seem to have been passing by change, so I altered the
implementation a little bit.

Furthermore, I have added in the docs of the Axelrod library a small explanation and example of how to create spatial tournaments. All tests seem to be working fine !

This class can be used from the tournament to create matches
with spatial structure topology. By spatial stucture, we mean
a graph where the players are the nodes and they only play
other players - nodes that are connected with a an edge.
SpatialMatches is class created in the match generator file in order to create matches where not all players play each other.
But instead the players, that are illustrated as nodes in a graph, only play with players that are connected to by an edge.
SpatialMatches inherit from RoundRobinMatches but there is need for an extra argument taken by the class which is an edge
dictionary. To achieve that we use the python function super.

Super takes the name of the class and a self argument, and
here we will replace what was previously written as super(RoundRobinMatches, self) with super(SpatialMatches, self).
SpatialTournament is a class which will be running a Spatial Tournament by calling the SpatialMatches class
we created before. It inherit for the class Tournament and these are some tests for the specific class.

The tests for the SpatialTournament do not contain the hypothesis tests yet. They will be added shortly.
We have run all the unit tests and we all 22 have passed.
The Spatial Tournament class is a class resposinble for creating a Spatial structure tournament, where the players
are respresented on a graph and they only matches are bewteen players-nodes connected with an edge. It does that
by using the SpatialMatch class and it inherit from the tournament class.

It's take a extra argument which is a dictionary called edges, that represents which nodes- players are connected
and will face each other in the tournament.

Proper testes for this class have been written and all are passing.
__init__.py file is responsible for importing functions and classes and putting everything together for axelrod library.
Now that Spatial Tournament is written is has to be added in to be imported as well.

The same was not needed to be done for SpatialMatches because __init__.py already imports everything for the
file Match, which contains SpatialMatches.
In case a tournament is created containing disconnected nodes-players an Error will be displayed.
That is because if a player does not have any interaction with any other player it should be removed from the tournament
as not active player  could not have a score or rank in the tournament. A player not participating is different from a player
scoring zero and this should be noted.

Also a test for this constrain was added in the test_match_generator.
This test was not correct as the number of repetitions is not the same as
the number of interactions.
These need to be refactored into test_resultsset.py
Currently the underlying graph is cyclic it needs to be random.
In a complete multigraph alla the nodes are connected to each other
and to themselves. Which in a round robin topology. Therefore, a test
to make sure that the results procuded by a complete
multigraph and a round robin are equivalent.
After running the tests with Travis has returned the following error: Data generation is extremely slow.
Decided to simply remove the tests.
The game object used to score the match
repetitions : int
The number of repetitions of a given match
edges : dictionary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this dictionary looks like? In the tests below it looks like a list.

@marcharper
Copy link
Member

marcharper commented Jul 13, 2016

Can we add a test that has a set of deterministic players on a complete graph compared to the non-spatial tournament? We should get the same results in both cases. (Not sure if this is already there.)

@Nikoleta-v3
Copy link
Member Author

First of all, it is a list ! I just happened to be calling it a dictionary for a long time... I will correct that, there seems to be more than once. Also for your second point. It has already been implemented, is the test for the complete multigraph.

@drvinceknight
Copy link
Member

Also for your second point. It has already been implemented, is the test for the complete multigraph.

Here: https://github.com/Axelrod-Python/Axelrod/pull/654/files#diff-74e02134acd0ef3b29c84d6643837201R593 (line 593):

+        def test_complete_tournament(self, strategies, turns):
+            """
+            A test to check that a spatial tournament on the complete multigraph
+            gives the same results as the round robin.
+            """

@marcharper
Copy link
Member

Great, sorry I'm not familiar with the term multigraph.

Is there an easy demo case that compares to the other tournaments in the documentation? There is an example that shows how many cooperators you need to overcome a defector, is there a topology that changes the number of cooperators needed (a cycle perhaps)? That would be a nice addition to the docs.

@drvinceknight
Copy link
Member

Great, sorry I'm not familiar with the term multigraph.

It could be better to just rename it to just 'complete graph'?

There is an example that shows how many cooperators you need to overcome a defector

If I remember correctly, I think that example is no longer there. It was in the early form of the docs which were far too complicated, before we simplified the tutorials to being more modular. Not saying it's not worth including an example like that here, just pointing it out.

@Nikoleta-v3
Copy link
Member Author

I would be happy to work on something like that ! But maybe @drvinceknight is right, is not to technical for the specific section. It could go to http://axelrod-tournament.readthedocs.io/en/latest/, as an "Research Example - something" ?.

@drvinceknight
Copy link
Member

But maybe @drvinceknight is right, is not to technical for the specific section. It could go to http://axelrod-tournament.readthedocs.io/en/latest/, as an "Research Example - something" ?.

I think I would prefer the tournament repo to stay as it is. I also think the docs should not try and do too much (as they did previously) but perhaps there is an interesting topolgy that could be shown.

Perhaps run two tournaments: one complete graph (remarking that this corresponds to the round robin), and then another that perhaps isolates Defector a bit (perhaps it only plays TitForTat which serves as a bridge/separator to the other strategies that continue to all play each other)? And then that would show how the cooperators do better?


self.edges = edges
super(SpatialMatches, self).__init__(players, turns, game, repetitions)
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the doc string up to just under the class SpatialMatches line. Can we clean up the language a bit? I'll put suggestions inline below.

@drvinceknight
Copy link
Member

"Research Example - something" ?.

It could certainly be a great notebook to add to https://github.com/Axelrod-Python/Axelrod-notebooks

as a 2D square lattice. We want to create a class that will not take as
an argument only a 2D lattice but any given graph.

After considering various python packages for graphs, we ended up using
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this paragraph?

@marcharper
Copy link
Member

This is a nice contribution overall!

I put in lots of little comments above. It would be nice to have a more complex example somewhere in the docs or notebooks. It might also be interesting to augment the tournament repository with some new tournaments, say on a big cycle, a grid like in the literature, or some other interesting case.

Also two ideas for the future:

  • probabilistic ending + spatial games, and
  • Moran Process on directed graphs (I'll tackle this one)

@Nikoleta-v3
Copy link
Member Author

Thank you @marcharper ! I will go through the comments and make the corrections. Also as suggested I will create a few notebooks.

We were considering evolution in general but suggested that could be left for another time. I do believe from October I will spend a lot of time with Spatial tournaments so I appreciate the ideas !

@drvinceknight
Copy link
Member

It might also be interesting to augment the tournament repository with some new tournaments, say on a big cycle, a grid like in the literature, or some other interesting case.

Sure: my main question would be how to pick the particular graph for the tournament repo (if a cycle: how do we order it?). Perhaps a discussion for another issue: have opened Axelrod-Python/tournament#36

probabilistic ending + spatial games, and

Yes. Maybe you could look in to that at some point @Nikoleta-v3 (not necessarily this Summer: there's a lot to do based on our chat this am although it would be pretty straightforward to implement).

I'll throw an issue together for it :)

Moran Process on directed graphs (I'll tackle this one)

Yes :) 👍

@Nikoleta-v3
Copy link
Member Author

@marcharper I believe I have addressed all of your comments ! But I am still working on some notebooks for the documentation and for my dissertation as well.

@meatballs meatballs merged commit 1422925 into Axelrod-Python:master Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants