Skip to content

ML strategies #803

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

Merged
merged 29 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7b49994
Retrain EvolvedANN, move data to subdirectory
marcharper Dec 23, 2016
fe9c174
Fix data file inclusion in setup.py
marcharper Dec 23, 2016
658d0c6
Newly trained ML strategies
marcharper Dec 25, 2016
bf41394
Add Evolved ANN for the Moran process
marcharper Dec 25, 2016
4cee37b
New LookerUps
marcharper Mar 19, 2016
acb7349
Alias EvolvedLookerUp
marcharper Mar 26, 2016
32c7823
Generalize LookerUp to m1 plays, m2 opponent plays, and n initial opp…
marcharper Mar 27, 2016
5b4137b
Additional strategies, Fix lookerup table check
marcharper Mar 27, 2016
129e20c
Updated LookerUp tables
marcharper Mar 28, 2016
4cfb912
Added Winner12 and Winner21
marcharper Dec 25, 2016
8e3114f
Fix several tests
marcharper Dec 25, 2016
6f15d48
Remove some tables from the global player list
marcharper Dec 25, 2016
d234bc8
Improve data loading for ML strategies
marcharper Dec 25, 2016
bf7e16b
Update several tests and refactor EvolvedLookerUp player creation
marcharper Dec 25, 2016
963c62d
Various updates to ML strategies
marcharper Dec 26, 2016
82193fb
Refactor data loading
marcharper Dec 27, 2016
79813aa
Use more efficient cooperations counts in ANN
marcharper Dec 27, 2016
b1f27bf
Update Gambler names and tests
marcharper Dec 28, 2016
b1e81ec
Evolved Finite State Machines
marcharper Dec 28, 2016
bad6abf
Refactor ML strategies
marcharper Dec 30, 2016
0039073
Add lookerup initial actions as parameters to __init__
marcharper Dec 30, 2016
f50107b
Add initial sequence to lookerup data loading
marcharper Dec 30, 2016
e6a974d
Hidden Markov Model Player
marcharper Dec 31, 2016
dd94bfd
Updates to ML strategies and training data.
marcharper Jan 1, 2017
1cec7f4
Remove untested Moran-trained strategies for now.
marcharper Jan 1, 2017
4379123
Fix tests
marcharper Jan 1, 2017
81a643f
Fixes from first pass review and more tests
marcharper Jan 2, 2017
17abaaf
Second pass on review: docs and tests
marcharper Jan 5, 2017
0ae1dc0
Merge branch 'master' into ml_strategies
meatballs Jan 5, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include *.txt
recursive-include docs *.rst
recursive-include axelrod/data *.csv
9 changes: 6 additions & 3 deletions axelrod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@

# The order of imports matters!
from .version import __version__
from .load_data_ import load_lookerup_tables, load_pso_tables, load_weights
from . import graph
from .actions import Actions, flip_action
from .random_ import random_choice, seed
from .plot import Plot
from .game import DefaultGame, Game
from .player import get_state_distribution_from_history, init_args, is_basic, \
obey_axelrod, update_history, update_state_distribution, Player
from .player import (
get_state_distribution_from_history, init_args, is_basic, obey_axelrod,
update_history, update_state_distribution, Player)
from .mock_player import MockPlayer, simulate_play
from .match import Match
from .moran import MoranProcess, MoranProcessGraph
from .strategies import *
from .deterministic_cache import DeterministicCache
from .match_generator import *
from .tournament import Tournament, ProbEndTournament, SpatialTournament, ProbEndSpatialTournament
from .tournament import (
Tournament, ProbEndTournament, SpatialTournament, ProbEndSpatialTournament)
from .result_set import ResultSet, ResultSetFromFile
from .ecosystem import Ecosystem
from .fingerprint import AshlockFingerprint
5 changes: 5 additions & 0 deletions axelrod/data/ann_weights.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# name, features, hidden_layer_size, weights...
Copy link
Member

Choose a reason for hiding this comment

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

Small suggestion: remove the # and list full header (potentially useful for other analysis?). I expect this would need to be done on the axelrod-evolver repo and not for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should cross this bridge later. The number of columns isn't constant so there isn't really a proper header.

Copy link
Member

Choose a reason for hiding this comment

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

Fine to leave for later, you could have the max number of columns with headers and have NANs in the other ones? (Not suggesting that for now).

Evolved ANN, 17, 10, -0.003576751877069098, -0.009116435789084176, -1.6226750298069816, -0.16936583840464212, -0.24767811424335412, 2.917597689195209, -0.4660835078234858, 2.6077233900451704, 0.007654525451496821, 0.24926329904868214, 0.21300509813065255, -0.0008610492369117186, 11.910547784868735, 2.450594158758787, 0.438355335722304, 0.006477151246808702, 0.5741536766363411, 0.02462418508554424, -0.0012988442322510215, 0.0007818404074661314, -0.002036906591412471, 0.016377924735041065, 0.04992731920552376, 0.0012509393723994738, 0.6973411226261182, 0.0006254912910491841, 0.00047099174257766177, -0.002120731786945985, 1.1254335327814609, -10.370786178893706, -0.00012469149030800645, 0.14436761320287467, 0.05611140973019576, -0.0016366743010876627, 0.00017168216291285577, -0.03946773816864551, -0.027087785966378175, -0.0007127387952544514, -0.004271912479467591, 0.5150421588241055, -0.22941179431864933, -0.0095554420516546, 0.11309512942058234, 0.02928026671350157, -0.004271549294336798, -0.0003315179614494489, 2.211285732697422, -0.11740200028568301, 0.0009962379719110528, -0.01111880489200713, 0.38552547023537326, 0.6318823670906345, -0.0004549864001234058, -2.556634055201679e-05, 0.052307029094913166, 0.8482608143343549, -0.7883518269801311, 0.032301738665859676, -0.0014778900364928135, -0.34455529892325604, 0.008125911048136848, 0.014152066117414049, -0.0019236013490204697, -0.003920029943239384, 0.029085767655998903, -0.0008784550881728423, 0.3435901596510554, 0.24771915413070683, 0.002312235900247917, -0.0003165849275334269, 0.0005596038341596242, -0.0024919150553704052, 0.05815458270598197, -0.1937018502492227, -1.8250738932528443, 4.157186180134131e-05, 2.943061662102853, 0.010778535125806234, -0.032512597224797754, -0.0003246595897432385, -0.0002458206802779675, 0.1541076435270061, 0.0037925444350366067, -0.6188869890845022, -0.22716430588908995, -0.01181908469964059, 1.5038480327390307, -0.14416872049137233, 0.0005042076266357683, -0.017810077795893765, 0.03526366076440114, 0.011060422025572895, -0.021332183741068406, 0.002780275496938823, -0.026230933918782513, -0.0008086310525332234, 0.17064687599674258, 0.2726954877308398, 0.06579094358724917, -0.1520859776087798, -0.003111942863901281, -0.0006907666533775145, 0.3541898175141693, 0.0009279324771965426, -1.02678577891704, 0.14334521747927695, -0.004071610961189254, -0.001207893735478954, -0.011071821668055959, 0.000339516787811465, -0.012354976869052762, -0.017792122689835564, 0.04000839684019883, 0.0007450282331100439, 1.7663136890716324, -2.8277851231760667, -0.013925796175438333, -0.7759116432724652, 0.9526400227212101, 1.3224921501299892e-05, -0.0472823771149402, -0.32139561926038845, -0.16281957543641462, -0.4544552413988827, 8.104457695593522e-07, 0.0012604615893040117, -0.2708836008719851, -0.015954274981653523, -0.18085568354803125, 9.719261607120993e-05, 0.008911006689136518, 0.6283406438091257, -0.020845703085579134, -8.2991081457223e-06, 0.1680487638909446, 0.12338311971516569, 0.6374359553174332, 0.0068708780599514305, 7.161994834226168, 0.037717458897906064, -0.08166498393224347, -0.0003866864661065885, -0.035928030476597095, -0.5306343046712498, -0.03731815115135128, 0.1601186601162489, 0.061793412985435066, -0.008245437643649127, -0.1329836372733803, -1.0593300674284343e-05, 0.006000911165890601, -0.024349113092127842, -0.038064952345485834, -0.6717215031589087, -0.25600136304175464, -0.00013788514988313308, 0.10903737627345898, -0.04109950353425148, 0.0011818144689657514, 0.4612177668674218, 0.017157983078021726, -0.0002922370212791781, -0.07461385101326228, -0.03691138985965549, 0.0002672500155187832, -0.4629422134737055, -0.03204962494694291, -0.0398035296303568, -0.0019614192106946335, 0.07062072632793034, -0.3807648841924845, -0.4077410732754568, 0.6351755873193442, -0.0012896440044397849, 5.964694012083687, 0.02153817770055385, 1.4528610065395318, 0.015807271234472182, 0.061063626330635286, 0.0022982937511943397, 0.00036535725718584393, -1.2067515566616847, 0.7988787224726943, 0.0003472294024470962, 1.7209686798616755, -0.11950387113947813, 4.59513750232414, 0.020556451924523336, 0.004404012690064921, 0.4359433744065976
Evolved ANN 5, 17, 5, 8.375423053834833, 0.1261030984458249, 0.6229687391287315, 1.0555619366240612, -1.9827656871308919, -0.30176066062316664, 6.1600656056537675, -0.32706569135615116, 0.17754613107044848, -5.1210074171192765, 0.8979654555091046, -5.775137721839209, 0.7370167100617766, -0.40766774847049836, -0.6871675824007146, -0.8851561068477862, -0.9380236569734701, -0.1061808689087742, -28.80056165348774, 0.34099380260727474, -0.9296496325235885, -0.29951155013186037, 0.29452753742059645, -2.647358318342513, 2.8665522715028073, -15.53334649858335, 0.7458724656392226, -0.46189164035783054, -45.86292727785617, -0.497764265530173, -2.7548363861243095, -0.05026908852575242, -2.347984197105825, -0.7036132052075461, -0.2849544137414548, 0.44648317127627624, -1.8113293861070814, 0.6606796392423389, 0.4306779425473901, 29.255936983349343, 0.6292845850187647, 5.06082751852397, -217.23797221991887, 7.01016283354761, 8.272946939494153, -0.002750158149020354, -4.936706563050966, -0.00040809727294092074, 3.293211441510604, -0.6859683357257031, -5.651191144070032, 3.6461265120866924, 7.356445034460227, -0.22995023247988478, 2.3442255604221587, 0.39246521035761583, -0.2968903517444873, -0.9616537001818733, -1.6956961159311899, 2.3905634050127715, -4.77893872195609, 0.9288780448229095, 3.5762554351730933, 0.5350328980460679, -1.5702444440191612, 0.4752602404076749, -3.9372948763422646, -0.528493807036809, 1.1247837165608066, -0.9593501671395235, -0.5303714820063201, 5.906832815840155, 0.572385895065991, 0.3226387472904857, 0.9290757921455962, 24.31294609099736, -1.0011403399292698, 6.745168904740927, -3.90212207698002, -0.8800864567120545, -0.7341660866134236, -192.0075807720621, -0.49958332808652584, -0.8512291478997993, -1.706530475715973, 1.9988262858968837, -4.665904353363123, 0.5053151191945213, 0.7049630921679941, -9.96377368732609, 0.8824473820630665, 0.23343212093733712, 0.2142209846364116, -0.9862047147870845, -0.17219465582984883
Evolved ANN 5 Noise 05, 17, 10, 29.021994753071542, 219.61101763155014, 1063.1637806214826, 1.5402562950828715, -77.95303186313585, 267.89223675325087, -49.5387828788577, -2.6011267194406376, 7.9674134543620765, 0.36744774780513845, 5.705857800529822, 74.5118260372338, 3.7815106388865365, 21.61749723216825, 2.615374769007371, -4.956048693418373, 16.265812089010854, -0.5971830913092495, 2.713007610795036, -15.988422780527246, 41.18700942536512, -211.6875277650788, -31.37916591033693, -3.18731153755138, 18.832459315193752, 2.182876315654387, 41.05501370495859, 21.037499124712344, -57.26580763667314, -20.73478679472237, 740.6044026693244, -646.6449426951316, 0.44262545614783516, 494.2330468894694, 30.556660213698716, 343.9523623015607, 6.258536671356227, 1.0331025110993781, 62.81670440214398, 2.050717650327349, -55.29911348831866, 0.12013585846685129, -3.525491825550343, 0.8521619825666777, 3.4021706792885125, 65.68959431318048, 59.034749752903124, 1.3960644749995557, 2.123080169102119, 2.0050790443493076, 18.01173172947066, -1.9594306080033703, 3.7143617968441305, 22.876875520928664, 127.1242771884875, 0.0814516747526633, 0.4188117166094544, -22.619347347805416, -1.350231296139859, 4.609695056493578, 14.813685333260361, 1.8151813422230947, -0.6152760521682589, 56.3968593809663, 0.5291526645626778, 45.623429663362224, 1.4083765751129795, -1.7979107689200213, -133.3907099906686, 332.9190743029093, -16.69584638750235, 0.7547746912890307, -0.16129548581544273, 32.07685387989524, -4.777007155188058, -584.0074143353936, -14.203844806356123, -0.7125043485338549, -0.2532414942567335, 0.2424235301321644, -2.7332162070444226, -11.048512432203255, -0.5750784745602715, -6.583495964988355, 0.8021313004801964, -4.136750110674422, 3.422252093595686, 0.5684967669851626, 4.9238081210747495, 14.503412467481546, 54.52845388844175, 0.7444572732509133, -191.72509441846645, 0.5480848987938383, 42.27959932760183, 48.881469586945215, 148.71234309798186, 6.259832845972374, -12.448568209113635, 0.4971964655854716, -3.9250934452151536, -5.509873014504808, -5.003451989805698, -14.764803995567945, 1.144289717030508, 11.1813993197904, -799.551976894276, -2.305546912955449, 1.623001769439963, 0.5380907491532528, 18.55850746229286, 7.3791435483587025, -1.3058220461101604, 8.538692132116461, -23.492426814231088, -0.1708304730775915, -40.11536974172577, -0.6325828249226341, 4.789534096125168, 1659.0961224963328, -7.709921822391348, 63.8942026144617, -74.3383220727353, 181.95602166741998, 1.9335192305687423, -2.2129663303887166, 37.381636630086135, -7.92393426028687, -5.3688053802259885, -7.58836742659798, 37.30667400514841, -289.09892489977165, -1.5147645904541234, 4.638068109618868, -404.80728791680815, 0.11727199345822248, -5.17258526833061, -0.88453949499092, 96.84857624186293, -0.6791965529867956, 3.1287918300191686, -16.961433290851506, 1.5339548611779197, -14.60241354508969, -102.09154806457092, 5.308359098845199, -1.3772386624093653, -232.4068932110028, -3.8957064753975845, -10.860809364864776, -72.69782329332983, -7.643980828800534, 29.900464193825652, 22.47046574607309, -38.204496819495844, -68.60271311500388, 0.2709521700788272, 99.82801908436845, -1.7001896396141027, -10.954337249511207, 48.09909863189684, -636.7156136663931, -45.30678925814974, 39.42329107604124, -33.87400944809508, -0.888696202396916, -8.30775287285587, 7.665066358799107, 8.77078230492006, -3.063228922635141, 5.418347424137075, -2.971743552900797, -0.6578858172171116, 0.05427922276379916, 1.9754929185067431, 186.95414732845305, 2.1375699883739276, 0.6836442570880665, -0.49780743275065514, 77.77706670862442, -3.2403854872213094, -3.3470142285219864, -53.72381101228183, -9.92185859389291, -2.275977293585001, 91.88617110386592, -18.507806840374368, 1.5759533799870984, -0.6476960553307466, 3.897754577067307

19 changes: 19 additions & 0 deletions axelrod/data/lookup_tables.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Name (string), plays (int), opp_plays(int), starting_plays(int), pattern (str)
, 0, 0, 1, C, CD
, 0, 0, 2, CC, CDCD
, 0, 0, 3, CCC, CDDDCDDD
, 1, 1, 0, C, CDDD
, 1, 1, 1, C, CDDDDDCD
, 1, 1, 2, CC, CDDDDDDDDCCDCDDD
, 1, 1, 3, CCC, CDDDDDDDDDDDCDDDDCCDCDDDDCDDDDDD
, 1, 1, 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DCCDDDDDDCDCCCCCDDCDCCDCDDDDDCDDDDDDCDDDDDDDCDCDDDDDCCDDCCCCDDDDDDDDDDDDDDDD
6 changes: 6 additions & 0 deletions axelrod/data/pso_gambler.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name (string), plays (int), opp_plays(int), starting_plays(int), weights (floats)
PSO Gambler Mem1, 1, 1, 0, 1.0, 0.52173487, 0.0, 0.12050939
PSO Gambler 1_1_1, 1, 1, 1, 1.0, 0.12304797, 0.0, 0.13581423, 1.0, 0.57740178, 0.0, 0.11886807
# , 2, 2, 2, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.93, 0.0, 1.0, 0.67, 0.42, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.48, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.19, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.36, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
PSO Gambler 2_2_2, 2, 2, 2, 1.0, 1.0, 0.0, 0.02126434, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.95280465, 0.80897541, 0.0, 0.0, 0.0, 0.0, 0.65147565, 0.15412392, 0.24922166, 0.0, 0.0, 0.0, 0.0, 0.0, 0.24523149, 1.0, 0.0, 0.0, 0.43278586, 1.0, 0.0, 0.23563137, 1.0, 1.0, 1.0, 0.00227615, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.15140743, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.77344942, 0.0
PSO Gambler 2_2_2 Noise 05, 2, 2, 2, 1.0, 0.0, 1.0, 0.63548102, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.13863175, 1.0, 0.7724137, 0.0, 1.0, 0.0, 0.07127653, 0.0, 1.0, 0.28124022, 0.0, 0.0, 0.98603825, 0.0, 0.0, 1.0, 0.06434619, 1.0, 1.0, 1.0, 0.50999729, 0.00524508, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.16240799, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.87463905, 0.0, 0.0, 1.0, 0.0, 0.0
47 changes: 47 additions & 0 deletions axelrod/load_data_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pkg_resources
Copy link
Member

Choose a reason for hiding this comment

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

Could we have unit tests for these please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how to better test these than simply loading the data and testing the strategies. I added a few integrity checks in ANN and LookerUp to make sure the data is of the expected length.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that we could have a tests/unit/test_load_data.py file that just checks that these functions run and that the data is of the expected format separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure that we'd be testing anything further in that case -- if the format or data types are wrong the strategies will fail when constructed or played.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this wouldn't test anything further, it just consolidates things: for example in the future these ml strategies could be changed to no longer read the data (hypothetically), their tests adjusted and an error creeping in to these reader functions. That's a weird case but I think my point holds?

Copy link
Member Author

Choose a reason for hiding this comment

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

But if the players no longer read the data then the data and these functions are unnecessary (and their coverage will disappear). So wouldn't we just delete the data and these functions in that case, unless something else is using them? And if something else is using them then a bad change will still break those things.

Copy link
Member

Choose a reason for hiding this comment

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

Very good point, I'd still say too many tests is better than too phew but I won't insist. :) 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe type annotations are a good check here so when start annotating we'll get a little extra coverage.



def load_file(filename, directory):
Copy link
Member

Choose a reason for hiding this comment

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

Docstring for completeness. Also numpy style for this and the rest?

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't these be better as a set of pandas dataframes? There would be far less code and it would be quicker too.

I know it's another dependency, but we're already dependent on numpy, so the precedent has been set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I prefer using pandas actually if the extra dependency is ok with @drvinceknight .

Copy link
Member

Choose a reason for hiding this comment

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

I'm not averse to the extra dependency. 👍

Could change the output of the results_set.summarize to be a data frame too (not for this PR, another issue :)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool. I think anyone that uses anaconda or can pip install numpy should have access to rest of the scientific stack (for sure at least scipy and pandas).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm punting on this one since the number of columns isn't constant in all cases.

Copy link
Member

Choose a reason for hiding this comment

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

Fine by me.

I'm not entirely sure use dfs would make things simpler in this case, the data as is would need to be pivoted for the df to be advantageous or the data could be stored with rows corresponding to "genes" and columns to different strategies... Perhaps not a bad idea (but I don't think necessary for this PR).

"""Loads a data file stored in the Axelrod library's data subdirectory,
likely for parameters for a strategy."""
path = '/'.join((directory, filename))
data = pkg_resources.resource_string(__name__, path)
data = data.decode('UTF-8', 'replace')
rows = []
for line in data.split('\n'):
if line.startswith('#') or len(line) == 0:
continue
s = line.split(', ')
rows.append(s)
return rows

def load_weights(filename="ann_weights.csv", directory="data"):
"""Load Neural Network Weights."""
rows = load_file(filename, directory)
d = dict()
for row in rows:
name = str(row[0])
num_features = int(row[1])
num_hidden = int(row[2])
weights = list(map(float, row[3:]))
d[name] = (num_features, num_hidden, weights)
return d

def load_lookerup_tables(filename="lookup_tables.csv", directory="data"):
"""Load lookup tables."""
rows = load_file(filename, directory)
d = dict()
for row in rows:
name, a, b, c, initial, pattern = row
d[(name, int(a), int(b), int(c))] = (initial, pattern)
return d

def load_pso_tables(filename="pso_gambler.csv", directory="data"):
"""Load lookup tables."""
rows = load_file(filename, directory)
d = dict()
for row in rows:
name, a, b, c, = str(row[0]), int(row[1]), int(row[2]), int(row[3])
values = list(map(float, row[4:]))
d[(name, int(a), int(b), int(c))] = values
return d
6 changes: 3 additions & 3 deletions axelrod/moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, players, turns=100, noise=0, deterministic_cache=None,

If the mutation_rate is 0, the population will eventually fixate on
exactly one player type. In this case a StopIteration exception is
raised and the play stops. If mutation_rate is not zero, then the
raised and the play stops. If the mutation_rate is not zero, then the
process will iterate indefinitely, so mp.play() will never exit, and
you should use the class as an iterator instead.

Expand Down Expand Up @@ -89,8 +89,8 @@ def __init__(self, players, turns=100, noise=0, deterministic_cache=None,
# Build the set of mutation targets
# Determine the number of unique types (players)
keys = set([str(p) for p in players])
# Create a dictionary mapping each type to a set of representatives of
# the other types
# Create a dictionary mapping each type to a set of representatives
# of the other types
d = dict()
for p in players:
d[str(p)] = p
Expand Down
1 change: 1 addition & 0 deletions axelrod/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def save_all_plots(self, prefix="axelrod", title_prefix="axelrod",
f = getattr(self, method)(title="{} - {}".format(title_prefix,
name))
f.savefig("{}_{}.{}".format(prefix, method, filetype))
plt.close(f)
Copy link
Member

Choose a reason for hiding this comment

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

THANK YOU! (This error message has been like a really annoying pebble in a shoe on a long walk...)


if progress_bar:
pbar.update()
Loading