-
Notifications
You must be signed in to change notification settings - Fork 268
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
Conversation
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 |
There was a problem hiding this comment.
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.
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.) |
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. |
Here: https://github.com/Axelrod-Python/Axelrod/pull/654/files#diff-74e02134acd0ef3b29c84d6643837201R593 (line 593):
|
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. |
It could be better to just rename it to just 'complete graph'?
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. |
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" ?. |
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 |
|
||
self.edges = edges | ||
super(SpatialMatches, self).__init__(players, turns, game, repetitions) | ||
""" |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this paragraph?
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:
|
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 ! |
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
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 :)
Yes :) 👍 |
Which is for the TestResultSet_SpatialStructure is the test_resultset file.
@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. |
Closes #635.
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()
createschunks where players - nodes only play players that are connected to with an edge. A tournament
class
SpatialTournament
was also implemented to pass theedges
argument andSpatialMatches
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 anelif
.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 !