Learn Python with Talk Python's 270 hours of courses

#104: Game Theory in Python Transcript

Recorded on Wednesday, Mar 8, 2017.

00:00 Game theory is the study of competing interests, be it individual actors within an economy or healthy versus cancer cells within a body.

00:08 Our guests this week, Vince Knight, Mark Harper, and Owen Campbell, are here to discuss their Python project built to study and simulate one of the central problems in game theory, the prisoner's dilemma.

00:19 This is Talk Python to Me, episode 104, recorded March 8th, 2017.

00:25 Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the ecosystem,

00:55 and the personalities.

00:56 This is your host, Michael Kennedy.

00:58 Follow me on Twitter where I'm @mkennedy.

01:00 Keep up with the show and listen to past episodes at talkpython.fm and follow the show on Twitter via at Talk Python.

01:07 This episode is brought to you interruption free by Talk Python Training.

01:12 That's right, I'm talking about my courses.

01:14 Whether you want to get started learning Python with the Jumpstart course, learn over 50 Pythonic coding techniques, or consume a bunch of HTTP services,

01:22 I've got a course for you.

01:23 If you're not already subscribed, be sure to be a friend of the show at talkpython.fm/friends.

01:29 I have two new courses I'll be announcing in just the next couple of weeks, as well as a major feature, so you probably don't want to miss out on that.

01:36 And finally, if you work for a company with 200 developers or more, we should talk.

01:42 I have a very special first-time offer for enterprises.

01:46 All right, now let's get on to learning how we can minimize our prison sentence by studying the prisoner's dilemma.

01:52 Oh, and Vincent, Mark, welcome to Talk Python.

01:56 Thanks for having us.

01:57 Thanks for having us.

01:57 Yeah, pleasure to be here.

01:58 Yeah, it's great to make your acquaintance, and I'm really excited to talk about game theory and trade-offs and solving all these sort of standoff problems.

02:07 It's going to be so much fun.

02:08 But before we actually get into what is game theory, the library that you guys are working on, and things like that, let's start with your story.

02:16 Vincent, how did you get into programming in Python?

02:18 I'm a mathematician, and so I used various bits of commercial software during my PhD, so Mathematica, the main one.

02:25 And then I started looking for a free alternative, and that's how I stumbled on SageMath.

02:31 And from SageMath kind of fell into Python and slowly, slowly grew from there, and now I teach Python.

02:39 That's really awesome.

02:40 And so it's great that you started with SageMath.

02:43 I've had William Stein on the show, and I think SageMath is quite the cool project.

02:47 It's really generated a lot of neat things like Cython that people are doing totally different stuff with today.

02:55 Do you teach classes with SageMath, or do you just teach Python?

02:58 We used to.

02:59 I used to teach all our first years a combination of Python and SageMath, but actually for a number of reasons, I changed that over to just teaching with Python now.

03:08 So the Python Simpy library kind of does a lot of what our first years need to do and the various things about the installation.

03:14 That's getting better, especially with Cloud.SageMath, but we've just moved to just teaching Python now.

03:19 Sure.

03:19 Okay, great.

03:20 Owen, how about you?

03:21 What's your story?

03:22 Well, I'm a ZX81 generation, so I was bought one of those things as a small child, and I've never really looked back.

03:31 Once I realized that people were prepared to pay me to do this stuff, that was the career for me.

03:36 Like, you know, I could play with this toy every day and I get paid for it?

03:39 Oh my gosh, I'm in.

03:41 Count me in.

03:41 Exactly.

03:42 I don't think I've ever quite reached the level of joy of the day I made it draw a space invader, but, you know, once or twice I get close, and one day I hope to get there.

03:51 Nice, nice.

03:52 I'm relatively new to Python.

03:54 I actually started.

03:55 My eldest son is one of Vince's students, and when he started at Cardiff and said, hey, it's Python they're teaching us here, he's got a younger brother.

04:05 And I thought, right, well, we'll get a head start on, I'd better learn this stuff so that I can teach him.

04:10 And so I've only been, I must have used every language under the sun until then, but it's only in the last three, four years or so that I've done any Python work.

04:21 Now that's a really cool coincidence, and I think that's a great, it's a great service you're doing for your son to sort of like get him ready for all those things, right?

04:29 If you go into almost any kind of university with programming skills of some sort, you're at such an advantage, I think.

04:38 Well, I'm sure he'll think so too now that he hears you saying it on this podcast.

04:42 I've seen it work out well for a lot of people.

04:47 All right, Mark, how about you?

04:49 Sure, I'm a data scientist.

04:50 I currently work at Google.

04:53 Before that, I was an academic in bioinformatics, which we used a lot of Python in.

04:57 And I started with Python before that when I was a graduate student in mathematics.

05:03 I started writing C++ way back in high school, and that was okay for a while.

05:08 But then I looked for languages that were maybe more efficient with my time and less efficient with the machine's time.

05:14 So I had a very brief stint with Perl before I found Python, and then I never looked back.

05:20 Oh, that's awesome.

05:21 And you're using Python day-to-day at Google?

05:23 Among other languages, yes.

05:24 Yeah.

05:25 Okay, cool.

05:26 Yeah, you said you started with C++.

05:28 I remember when I was at university, they told me I had to start with Fortran, and I pleaded to let me do C++ instead.

05:35 I'm like, this will be so much more useful.

05:37 I'm sure.

05:37 No, no.

05:38 Fortran is the most important language you'll ever learn.

05:41 I'm not sure I still agree with them.

05:43 I was told it was a high-level language.

05:45 Yeah, there was a two-year period where C++ was the language of the future before they decided that that was Java.

05:52 You guys all worked together on this project.

05:55 How did you come to meet each other?

05:57 One, I think, the university connection there.

06:00 But how did you end up working on this project together?

06:02 I don't know if it's worth Mark starting, because I think the link was – I can't actually remember exactly how Mark kind of got started with it.

06:10 But, yeah, the link between Owen and I was through Owen's son.

06:13 I think I found your GitHub page because it was shared on an EGT blog on Google+.

06:19 Ah, yeah, yeah, yeah.

06:21 And then I went over and I poked around a little bit and realized I could add a couple strategies right away.

06:26 And I did that.

06:27 And then I came back a couple months later and started working more on it.

06:30 Yeah.

06:31 And it just kind of snowballed from there.

06:32 Okay.

06:32 Yeah, really interesting.

06:34 I think GitHub has – their slogan is like social coding or something like that.

06:39 But I really do think it's connected people in some pretty powerful ways.

06:42 It's amazing.

06:43 For me, it's just been – this whole product has just been such an amazing learning experience because, as you can tell from Mark and Owen, they've got a far greater experience and knowledge of software engineering and coding and things like that.

06:56 And so everything I've learned is from coding with these two guys, really.

06:59 It's just kind of skyrocketed my own knowledge of writing code.

07:03 So, yeah.

07:04 And that's thanks to GitHub, in a way.

07:06 Yeah, absolutely.

07:06 Thanks to GitHub.

07:07 Very cool.

07:07 So let's start with what is game theory.

07:11 So the thing that we're going to talk about is your library that solves or simulates, I guess, is really the way to think of it, a certain problem in game theory.

07:20 But let's start at a high level.

07:20 What's game theory?

07:21 Okay.

07:22 So it's loosely – loosely, it's kind of the study of interactions between different individuals or agents in some shape or form.

07:33 And so it's kind of the study of how strategic interactions form.

07:38 You know, like if I know what you know, what should I do at a very loose level?

07:43 And hard to say when it really began.

07:46 There's kind of different – people tell you different things about when it started.

07:50 But the famous game theorist is John Nash.

07:53 And he kind of found a particular solution concept to game theory.

07:58 So, yeah.

07:59 John Nash won the Nobel Prize for his work in economics.

08:02 Right.

08:03 That's right.

08:03 I originally thought it was a Fields Medal.

08:04 You guys said, no, no, no, no, no, no.

08:06 Very cool.

08:07 And he's also the subject of that movie, A Beautiful Mind, which was a great movie.

08:13 So maybe tell us, like, what example was he working with?

08:16 Do you remember what his work was on?

08:18 Yeah.

08:18 So he worked on Nash Equilibria, which is kind of a solution concept for in a strategic situation.

08:25 There'll be a set of actions that all the players can take from which no one has a reason to do anything different.

08:33 So there'll be a point at which we can't really improve.

08:36 And his work was to show using a really clever proof that that point always exists.

08:43 So it was an existence proof.

08:44 And that's kind of snowballed as a solution concept for these strategic interactions.

08:49 And so, yeah, in the movie, he has this kind of moment in the bar where he sees everything.

08:55 And that's kind of the notion that if we all do what's best for ourselves, we'll actually not necessarily do what's best for everyone, which is a big theme in game theory.

09:06 Right.

09:06 Economics as well.

09:07 And we can get into these local minima, right, where, like, nobody is benefiting from what is happening as much as they could be.

09:14 But somebody has to move first.

09:16 And so game theory kind of explores that space and finds these minimas.

09:22 So if you consider these strategies or those strategies, you'll end up in this situation.

09:27 And it's interesting in economics.

09:29 It's interesting in public policy.

09:31 And it's, you know, all sorts of places.

09:33 Right.

09:33 Mark, did you want to add something to the game theory thing?

09:36 I think it's a good summary.

09:37 The paper that Nash wrote is really famous because it's only one page long.

09:40 And it has a huge number of citations.

09:44 So it's kind of a story goes pretty deep.

09:47 But, yeah, I think just adding on what you guys said, it's really fascinating to me that there can be two stable equilibria in a game.

09:55 One which is really bad for everyone and one is really good for everyone.

09:59 And whether or not those positions are stable or not is another big part of it.

10:04 It's one thing to be at that equilibrium.

10:05 It's another thing if you can be kind of easily nudged off of it.

10:08 And that's the class.

10:09 Yeah.

10:09 Yeah.

10:10 How hard is it and how seated are people in their ways?

10:13 You know, you can see that looking at society sometimes.

10:15 You're like, well, why are things structured this way?

10:17 And you just, if people just did this, right?

10:20 And so I think this is really interesting to explore that.

10:23 Like one of the classical problems in this space and what is the focus of your library.

10:28 So remind me, what's the exact name of your library?

10:30 Axelrod?

10:31 The Axelrod Library.

10:32 Just Axelrod.

10:33 Okay.

10:34 I wasn't sure if there was like a dash or something.

10:36 So the Axelrod Library.

10:37 Let's start out with, what's the origin of that name?

10:40 Axelrod is the name of a researcher who did an influential tournament several decades ago

10:46 around the iterated Prisoner's Dilemma where some of the classic strategies like...

10:51 So what's the Prisoner's Dilemma?

10:53 Well, so it's named after Robert Axelrod.

10:55 That's his full name.

10:56 And the Prisoner's Dilemma is a particular situation in game theory where...

11:01 A lot of academics run into this problem, right?

11:02 They find themselves...

11:04 Just kidding.

11:05 Right, right.

11:05 So the story behind the Prisoner's Dilemma is you've got two prisoners and I guess you've

11:10 arrested both of them and they both have to decide whether they're going to rat on the other guy.

11:15 Right.

11:15 Some kind of co-conspirator, co-criminal sort of thing, right?

11:19 Right.

11:20 And if you both just...

11:21 A gang.

11:21 Right.

11:22 And if you both just don't say anything, then they have some evidence and they can maybe

11:27 get you with a low-level crime.

11:29 But if one of you rats out on the other one, then they'll use that confession against them.

11:32 So it's in the prosecution or the police's best interest to get you both to confess.

11:37 And it's in both of your own individual best interest to say nothing.

11:41 But they provide you with a big incentive to confess on the other person.

11:45 They say, well, we'll let you go without any penalty if you'll just confess to the other

11:49 person.

11:50 So it's in your rational...

11:52 It's in your own personal interest now to confess on the other person.

11:55 But the problem is it's in their best interest to confess, to testify against you as well.

12:00 And if you both confess, then it's bad for both of you, right?

12:02 This is like one of the local minimums that you can get stuck in that's really bad.

12:06 Right.

12:07 Exactly.

12:07 You both go into jail because you both don't want each other, yeah?

12:09 Okay.

12:10 And so the actual Rod library or the actual Rod project was around modeling the prisoner's

12:16 dilemma, correct?

12:17 Yeah.

12:17 So one of the things is how do people end up cooperating?

12:20 If we're all incentivized not to cooperate with each other, yet we look around, we see all

12:24 these situations where people are cooperating.

12:27 So can we devise strategies that when we play this game repeatedly that coerce or convince

12:34 our partners that they're better off cooperating with us than defecting against us?

12:37 Yeah.

12:37 Okay.

12:38 So let's think about some of the things that you can do with this library.

12:42 So the actual Rod competition was held, you said, in the 80s.

12:45 And you said the algorithms were lost or the strategies were lost to time.

12:49 Is that true?

12:50 There's some that can still be found.

12:52 But I actually exchanged a very brief, when we started this library, I exchanged a very

12:55 brief email conversation with Robert Axelrod saying, I don't suppose you happen to have

12:59 any of these strategies kicking about.

13:01 And from his very first tournament, he simply said, no, they're not around.

13:05 And some of the others are written in, what, in Fortran, I believe?

13:08 Yes.

13:09 And they're not very well documented or anything like that.

13:11 So they're quite difficult to follow.

13:13 So some have published descriptions in various books and papers.

13:19 But again, they're not usually sufficiently detailed to allow you to completely reproduce

13:24 the strategy.

13:25 Yeah.

13:25 It's not.

13:26 It's one thing to describe the concept.

13:28 It's another to implement it, right?

13:29 Yeah.

13:30 Exactly.

13:30 We had one poor individual at the PyCon UK Sprint last year who came to the

13:35 work on the project and spent the entire day wading through the Fortran code for some

13:40 strategy that he was trying to reimplement.

13:42 I don't think he was expecting to spend the day working on Fortran at a PyCon.

13:47 Well, how was your PyCon experience?

13:50 Well, people were nice, but all I did was Fortran.

13:53 It was dreadful.

13:54 Let's talk a little bit about what this library does.

13:58 It's like, so you can set up these things called strategies, right?

14:01 And you can have players and tournaments.

14:05 Maybe give us a sense for what the whole thing does.

14:07 Well, in the end, each player that's participating has a very simple choice to make, which is either

14:13 to cooperate with their fellow prisoner or to rat on them.

14:17 So a simple choice between two options.

14:20 And so what we do in the library is to say all of the different strategies that we know

14:28 about, we play them against one another.

14:31 And first of all, we do that in pairs.

14:32 So we'll put a pair of players against one another and they'll play the game repeatedly over and

14:38 over and over again.

14:39 And then we'll just match up all the different combinations of pairs for however many players

14:45 we're interested in.

14:46 And we'll tot up all the scores and see who comes out on top.

14:50 Okay, excellent.

14:51 So give us a sense for some of the, you have some clever names for the different strategies

14:55 or players, right?

14:56 Strategy and player, it's kind of the same thing.

14:58 So you've got like the basic ones, the cooperator and the defector.

15:02 But what else?

15:03 Well, probably the most famous one is the tit for tat strategy, because in Axelrod's

15:09 original tournament, one of the interesting results that came out of his work was that

15:13 this strategy was one of the most successful.

15:16 I'm sure the other two will correct me, but possibly even the most successful of the lot.

15:20 Yep.

15:20 In his tournaments.

15:21 Yep.

15:21 Yep.

15:21 All right.

15:21 So what's tit for tat?

15:22 If you rat on me next time, I'm ratting on you.

15:27 I'm going to rat on you.

15:27 Yeah.

15:27 Yeah.

15:28 And if you're nice to me, I'll be nice to you.

15:30 So it simply, it looks at what its opponent did the last time they played and simply plays

15:38 exactly the same choice that they made when it comes around to the next turn.

15:41 So of course, if the opponent is being cooperative with it, then it will cooperate.

15:47 So it is quite a cooperative strategy and it did very well in Axelrod's original tournament.

15:53 Interesting.

15:53 And then you've got the grudger, which if you ever turn on the grudger, you're going to regret

15:59 it, right?

16:00 Well, what else?

16:00 There was a few other interesting ones.

16:03 Yeah.

16:03 There's a lot of variants of strategies where if you cross them once, they'll never cooperate

16:08 with you again.

16:09 Or maybe if you cross them, they'll forgive you once.

16:11 But if you cross them twice, then they're like, okay.

16:13 Interesting.

16:14 And so implementing these strategies is actually pretty straightforward, right?

16:17 It's like you could reasonably write a strategy in like five lines of Python.

16:20 Yeah.

16:21 Absolutely.

16:21 And that's been one of the aims of the library is to make that as simple and straightforward

16:27 as we possibly can.

16:29 Because it's a great way for somebody who's new to programming or new to Python or new

16:35 to making contributions to open source projects to get involved with something and to see an

16:41 effect very quickly.

16:42 You can invent a strategy that's not been thought of before very easily.

16:47 You can code it up in a few lines and you can get it into the library and get it participating

16:51 in the tournament.

16:51 And it has been a first contribution for many, many people to open source.

16:55 I gave a class on repeated games one morning and that afternoon, one of my students had written

17:01 their first open source contribution with a little bit of help, but not much.

17:05 So, yeah.

17:06 I think that's really great.

17:07 You know, a lot of people are super interested in contributing to open source, but I think it

17:12 feels super daunting because they see all the things they're like, oh, Django, I'd love

17:16 to.

17:16 Oh my gosh, this is a big project.

17:18 And if I break it, oh boy, Pinterest will be mad at me or whatever, right?

17:23 Whereas here, really at its core, to submit, to contribute a strategy, all you're doing

17:28 is writing a relatively simple, well, it can be simple or complicated, class method.

17:33 Just one method is kind of all you need to do.

17:35 Yeah.

17:35 So, you know, if people are there listening and they're like, hey, I'd love to get started

17:38 on this.

17:38 You've got some interesting game theory.

17:40 Definitely check this out.

17:41 I'll be linking to the GitHub repo in the show notes.

17:44 That'll be awesome.

17:44 Cool.

17:45 And we'd love to have them.

17:46 We look forward to seeing them.

17:47 That's awesome.

17:48 You guys are going to be busy with pull requests, I think.

17:51 Thanks.

17:52 Fantastic.

17:52 How many strategies do you have?

17:54 Yeah.

17:54 How many strategies do you have so far?

17:55 In the current release, which is 2.6, we got 184 strategies.

18:00 Wow.

18:01 But a lot of those are parametrized.

18:03 So, you know, you can, for example, a random strategy, we have a strategy that acts completely

18:08 randomly.

18:08 You can also pass a parameter of making it random where they select to cooperate with a

18:13 given probability.

18:14 So, in a way, we have pretty much an infinite number of strategies.

18:18 So, you have like a two-thirds cooperator, one-third defector-like?

18:22 Yeah.

18:22 And much more complicated ones as well.

18:24 Of course.

18:25 So, what are some of the more, not convoluted, but involved ones, I guess?

18:30 That's a good question.

18:31 There's several that we've implemented from the literature that try to break deadlocking

18:36 situations.

18:37 So, one of the weaknesses of tit-for-tat is it can get in these confect, or these cooperate-defect

18:43 cycles with an opponent that accidentally defects, or if the tournament is noisy or something

18:47 like that.

18:48 And so, if you can give it a small probability that it will forgive a defection, they can

18:53 get back to cooperating again.

18:54 So, there's a lot of strategies that implement little things like that, that attempt to get

18:59 the players back on track.

19:01 I see.

19:02 Just kind of break, because if you just go really clearly down the cooperate-defect,

19:06 grudge, you end up in these equilibrium really quickly, right?

19:10 And so, as you make concessions over time or take more of it into account, it can probably

19:15 be more interesting, huh?

19:16 I was going to say, Mark, if you want to talk about even some of the more complex ones where

19:20 we're using neural networks and we're training these strategies using genetic algorithms and

19:24 things like that.

19:25 Now, that is cool.

19:25 Sure.

19:26 You're probably best placed to talk about those.

19:28 Sure.

19:28 Yeah.

19:29 So, one of the great things about the library is that we have so many strategies already,

19:32 and you can use these to train new strategies using typical machine learning methods.

19:36 So, we had a couple of really interesting contributions, I guess, almost a year ago from

19:42 Martin Jones, who's, I guess, somewhat well-known in the Python community.

19:47 And he submitted a strategy that used a lookup table that he had trained to find the optimal

19:53 response against all the other strategies in the library.

19:55 And he also submitted the first one that used the neural network.

19:58 So, we've extended that method of taking a strategy based on some kind of machine learning

20:03 algorithm, training it against the other strategies, and then adding it back to the tournament to

20:09 see how it does.

20:09 And right now, those are amongst the best players in the library in terms of performance.

20:13 Oh, wow.

20:13 Okay.

20:14 How interesting.

20:14 And is it adaptive?

20:16 Or does it somehow identify?

20:18 Like, okay, I think that thing I'm playing against, that's a grudger.

20:21 So, I'm going to do a grudging thing.

20:23 That's a great question.

20:24 So, some of the strategies that try to adapt on the fly don't always do so well.

20:29 But what you'll see is the trained strategies typically learn things.

20:32 Like, if you defect too many times in a row, then they'll just decide that they're going

20:37 to give up on you.

20:38 That you're one of these strategies that is never going to cooperate with them.

20:40 So, they'll just defect with you for the rest of the time.

20:43 And we've got some population dynamics based ones as well, which we can talk about a little

20:48 more.

20:48 But they have to learn to play against themselves and the other players.

20:51 And they end up evolving like a handshake so they can recognize other variants of themselves,

20:58 but exclude opponents that aren't like them.

21:00 Really?

21:01 Wow.

21:02 That is so interesting.

21:03 What's really cool is that that kind of comes out of the training.

21:06 So, we just train them.

21:07 And so, we're not kind of designing that handshake, but we're seeing that handshake evolve, which

21:13 is kind of cool.

21:13 For sure.

21:14 Okay.

21:14 Yeah.

21:14 That's incredible.

21:15 I didn't really expect that.

21:16 Like, you know, at Google last year, they came up with those two neural networks that would

21:24 exchange encrypted data.

21:26 And a third one that was trying to break it, the Adam Eve, the Alice Bob and Eve one, that

21:31 one, that basically invented a way to talk to each other to do encryption.

21:37 And it sounds like this is kind of like that a little bit in the sense that they like know

21:42 how to play against each other.

21:43 I mean, I'm not saying it's necessarily the same thing, but.

21:45 I think it's in the similar vein.

21:47 Yeah.

21:47 It's a result of the same kinds of reinforcement training strategies.

21:51 Okay.

21:51 Interesting.

21:52 But each of our matches is typically only 200 turns long.

21:55 So, they've only got 200 bits of information to do this.

21:58 So, not quite in the same league as what Google are doing.

22:01 That's right.

22:03 And the worst thing that'll happen is they'll win a tournament.

22:06 We're not letting them just get the computers to talk to each other without us knowing what's

22:09 going on.

22:10 So, we're okay.

22:10 Yeah.

22:11 The singularity probably won't come from these strategies.

22:14 Who knows?

22:16 I mean, maybe.

22:17 But if it's ever found on GitHub by one of these other AIs, it's going to bring it back

22:24 in and it's going to be trouble.

22:25 I don't know.

22:27 If we can just get society into this local minimum, we have them.

22:31 All right.

22:32 So, the idea is you have these strategies, which are really interesting.

22:35 And then you kind of do like a survival technique, right?

22:39 You have them compete against each other over and over and over, 200 times, you say?

22:42 And then you can draw really interesting conclusions like, well, we had this even distribution at

22:49 the beginning of each type.

22:50 But at the end, we had way more grudgers or whatever.

22:53 Maybe talk about that a little bit.

22:55 Yeah.

22:55 There are a couple of variations of tournaments that you can play.

22:59 And some of them play these population dynamics.

23:02 So, in various different ways, at the end of each round, your score determines the size

23:09 of your population going into the following round.

23:11 And at the end of it, we look to see, well, who's died out, who survived through to the

23:17 end?

23:18 Has one strategy dominated the final population?

23:21 Or have we ended up in an equilibrium of three equal populations with three different strategies?

23:27 And that's actually, if you've seen the logo for the library, that sort of multicolored

23:32 plot, that's a plot that comes out of one of these population dynamic tournaments.

23:38 And it's showing one or two of those strategies are surviving very nicely through to the end

23:43 and dominating.

23:44 And a couple of them have died out and don't have very much population left at all.

23:48 Yeah.

23:49 And you have really nice visualizations of the results.

23:51 I really like those.

23:53 So, some of the tournaments you have, you say, round robin.

23:55 You have spatial ones and probabilistic endings.

23:58 What are those?

24:00 Well, as I said earlier, the first thing that we do is to pitch two players against one another

24:05 and then they compete for a certain number of rounds.

24:08 Well, in most of the tournaments, that number of rounds is fixed and it's the same for each

24:14 pair that plays.

24:16 But in the probabilistic ending, you set a probability so that in any given round, there's a probability

24:22 that that might be the last one in this match.

24:25 So, the length of matches between different pairs varies.

24:30 Whereas in all the other tournaments, they're all playing for exactly the same number of rounds.

24:35 Okay, cool.

24:35 Have you guys ever done anything like trying to study career criminals?

24:39 So, ones that go back to jail and back.

24:41 So, if you lose a round, you have to like sit out a round or something.

24:45 Only the ones that win or they somehow get released back into the population based on how long they

24:51 were sent to jail for.

24:52 I think you need to put a PR through.

24:54 I was going to say, yeah.

24:55 PR is very welcome.

24:57 Yeah.

24:58 We don't have that.

24:59 But actually, the library would allow for that to be implemented because we have these structures

25:05 for how the tournaments are in these different tournaments.

25:07 And so, you could theoretically build a tournament that has some sort of dropping out phase or things

25:14 like that.

25:15 Yeah, you could do that.

25:16 Oh, yeah.

25:16 Sounds interesting.

25:17 Yeah.

25:17 And there's lots of variants of the game that have been studied in the literature where other

25:20 than corroborate and defect, you can also like intentionally punish your opponent by taking some

25:25 of their points away or some of their money away.

25:26 And these are, you know, usually done with small studies of undergraduate students to see if it

25:31 improves the equilibrium.

25:32 And we haven't gone down that.

25:34 It was something we've talked about before.

25:36 And like Ben said, it would be relatively easy to add to the library.

25:38 But I think we've had so much fun with just the regular prisoner's dilemma that we haven't

25:43 messed with that part of it.

25:44 Yeah, you haven't had to go out there because it's still interesting to study.

25:46 I do have access to students.

25:48 That's true.

25:49 We also have a whole set of strategies that we sort of collectively refer to as the cheaters.

25:58 They don't conform to the rules of the tournament that Axelrod originally did.

26:03 They do all sorts of things within the code.

26:05 So they'll try to manipulate their opponent's code.

26:08 They'll try to manipulate the history of the scores.

26:12 And so we allow those strategies in.

26:14 And so there's quite an interesting little tournament that just plays them.

26:19 And sees, well, which is the best cheating strategy?

26:22 So who's best at writing strategies that manipulate the internals of Python and mess about with

26:28 their opponent's class methods?

26:30 Yeah.

26:30 So that's really interesting.

26:31 The normal ones, they're provided.

26:34 I mean, everybody's provided.

26:35 But the normal ones look at like, what did my player, my opponent do last time?

26:40 Did they defect?

26:41 Or did they cooperate?

26:42 And I'll do something.

26:43 But the sneaky ones, the insider trading ones, if you will, they say, you know what?

26:50 I actually have a self pointer.

26:51 And my self pointer has the opponent.

26:53 My opponent has a method that's called like respond.

26:58 And you can just overwrite that method to say, return C.

27:02 Exactly.

27:03 Exactly.

27:05 And it was a bit of a headache at one point, because as the library matured and became quite

27:12 a good research tool, well, a very good research tool.

27:14 We had these cheater strategies that were kind of all good fun and games at the start.

27:19 But I think we made a good decision earlier on to bring in this classification of strategies.

27:25 So you can't stumble on the cheaters by accident.

27:27 But if you want to go get them, you can.

27:29 And at the same time, there's loads of other things that we can classify strategies on.

27:33 So for example, how long is their memory?

27:36 Do they only look at what they did in the previous round?

27:39 Or do they look all the way back to the beginning of the game?

27:40 And you can kind of go and get strategies based on that.

27:42 Oh, interesting.

27:43 So basically, they provided a list of opponent responses.

27:47 And you could say, like, always, you know, trim that list to like 10 or 5 or 1 types of

27:52 responses, right?

27:53 Only consider strategies that only look at, you know, that much memory, so to speak.

27:57 Okay.

27:58 Because that's another interesting thing.

27:59 Talking about these sophisticated strategies that make use of neural nets and stuff.

28:02 There's a lot of talk in the literature, in the research literature, about whether or not

28:06 memory matters, you know?

28:07 And so this particular paper that made a lot of noise recently, well, in 2012, was it?

28:12 But they were like, actually, you know, any strategy can be beaten by a strategy that only

28:16 has very little memory.

28:17 And we're kind of seeing with the vast amount of strategies we've got that we can train strategies

28:22 that can adapt and can learn and can be very powerful and very sophisticated.

28:27 I see.

28:28 So maybe like if you're going to write a strategy yourself where it's procedural and you write

28:33 the code, like maybe it doesn't make sense to remember 200 steps and try to like, how

28:37 do I fit that in?

28:38 But if you give it to a deep learning neural network and go, here, this is what they did.

28:42 What does that mean?

28:43 Maybe it can actually find within that the patterns that we don't see.

28:47 That's right.

28:48 Mark wrote a paper on that with the coolest title ever.

28:50 It's called The Art of War.

28:51 So you could...

28:52 That's awesome.

28:54 We came up with a strategy that used a lot of memory that was very effective.

28:58 So I think there's this, there's been this kind of longstanding folk idea in the game

29:02 theory community that complicated strategies are more trouble than they're worth.

29:06 And that's because in the beginning, Tit for Tat was winning all these tournaments.

29:09 And it's a really simple strategy that only looks at their previous round.

29:12 And people tried to do all these complicated heuristics and stuff like that.

29:15 And it just didn't work because the other strategies were like, I don't know what this

29:17 other guy's doing, but it's complicated.

29:20 So I'm just going to defect against him and call it good.

29:22 I was just a human.

29:24 Come on.

29:25 I can't, I can't be.

29:26 Right.

29:26 Right.

29:27 But yeah, we've definitely seen some success with these longer, these strategies that can

29:31 be trained to do something sophisticated.

29:33 Yeah.

29:33 And how, how intense are the AIs that, that you're putting in?

29:37 Like, is this deep learning?

29:38 Is this just a neural network?

29:40 Does it involve things like TensorFlow and like GPUs or is it, is it pretty simple as far

29:46 as those go?

29:46 So the way we train all of them right now, I did play with using TensorFlow, but some of

29:51 the other strategies, the only way we can really do it is with an evolutionary algorithm.

29:54 Just mutate and see if it's good.

29:56 And so all the strategies we train now use that method, even the neural network and the

30:01 neural networks we use are pretty simple.

30:03 They're, they're basically one layer deep.

30:05 Can you give them access to, or have you given them access to previous tournaments and the

30:09 whole outcome and letting them look at that or like letting them see more than the tournament

30:14 that they're in?

30:15 I haven't currently trained one.

30:16 So I did train a neural network that tries to predict the next move.

30:19 And I let it look at a lot of games for that, but then I had trouble turning that into a

30:23 real strategy.

30:23 And it turns out it was better just to take a neural network and directly evolve the parameters

30:30 that do well on a tournament.

30:31 And in that case, it doesn't actually look at the outcomes of third party games.

30:36 I see.

30:36 All right.

30:37 You guys talk about a thing called Moran processes for population dynamics.

30:41 What's the, what's the story there?

30:43 What's that about?

30:44 I'm not familiar with that.

30:45 Sure.

30:45 So this is a, I got the classic example of a population dynamic.

30:49 You basically have a population of, in our case, in different strategies.

30:52 But if you were thinking like animals, it would be the, you'd have a bunch of animals that

30:57 have their different sizes, or they have some different characteristic, different eye color

31:01 or something like that.

31:01 And then they all interact with each other and they accrue fitness points.

31:06 In this case, they're playing the prisoner's dilemma and whatever their score is, is their

31:10 fitness.

31:10 And then you select one of them to reproduce proportional to its fitness or score.

31:16 And you randomly select one to, to die of natural causes, let's say.

31:20 And so one step at a time, the population evolves as one strategy does better than the other

31:28 ones.

31:28 I mean, it depends on the intrinsics of the strategies themselves and also the makeup of

31:33 their opponents.

31:33 So if they play well with certain opponents, then they're better off and a population has

31:36 a lot of those kinds of opponents.

31:38 I see.

31:38 So it's underlying dynamics that actually decide how the population of one type of thing,

31:43 like the grudgers or whatever, grow or shrink over time.

31:45 Yeah, exactly.

31:46 And so the questions around that are, is a population stable to invasion by a mutant

31:50 type, a different type?

31:51 Or is a strategy good at taking over a population of another type?

31:55 Oh, interesting.

31:55 Okay.

31:56 So yeah, something that sounds like it could be a cool variation on tournaments, maybe you've

32:00 done this, is what if you introduce like an invasive species type?

32:07 Like you run the tournament for like three fourths of the way through, and then you introduce

32:10 some other strategy that wasn't initially there after like others have been killed off.

32:15 Have you tried this?

32:15 Oh, there's your second PR, I think.

32:17 We're doing well here.

32:19 Yeah.

32:20 Yeah.

32:20 Yeah.

32:20 I think it would be cool because, because a lot of them, like if you look at the graphs,

32:24 it's super hard to talk about pictures on the audio.

32:26 But if you look at some of the diagrams, and I'll link to your presentation at PyCon, you'll

32:32 see that in the beginning, there'll be all these different types, and some of them will

32:35 die out after a while.

32:37 And maybe the strategies that won when they were around are not the same strategies that

32:41 win if some new type comes, right?

32:42 Yeah.

32:42 Okay.

32:43 Like if you throw a cooperator into a room full of defectors, it won't do very well, because

32:49 they'll rip it apart, basically.

32:51 Exactly.

32:53 Exactly.

32:54 Okay.

32:55 Quite interesting.

32:56 Yeah.

32:57 All right.

32:57 So what did you use to visualize those results?

33:00 Those graphs are really nice.

33:01 Is that Matplotlib or something else?

33:03 That's all Matplotlib.

33:04 Matplotlib.

33:04 Yeah, yeah.

33:04 That was at the start, we made it so that you could easily get various outputs of the

33:09 library.

33:10 It's all just done in Matplotlib.

33:11 Okay.

33:11 Yeah.

33:12 And there's two sub-libraries in the repository, one that does something called fingerprinting,

33:16 which is this idea from the literature that gives you an image that corresponds to a strategy,

33:21 which those are kind of neat to look at.

33:23 And then there's another one that's been around for a while that looks at how often each strategy

33:29 cooperates against each different given opponent.

33:31 So we have a lot of other visualizations and they're mostly with Matplotlib as well, with

33:35 the occasional Seaborn, I think, here and there.

33:37 Okay.

33:37 At the start, out of the three of us, I think it's fair to say I was the keenest to keep

33:42 the library very light on dependencies.

33:45 And so I was kind of a roadblock for quite a while with Mark and Owen more sensibly saying,

33:51 no, let's use all these awesome libraries to make the code better.

33:54 And I was like, no, no, no.

33:55 Let's pure Python, pure Python.

33:57 And so Matplotlib was introduced, but it had this really nasty little fix so that you could

34:03 still install the library without it.

34:04 And then eventually I understood what was the way to do things.

34:09 And so a lot of code got a lot neater when we started making use of all the great libraries.

34:13 That's nice.

34:14 The fingerprinting is another good little story.

34:17 I put an issue on the library.

34:20 It must be about 12 months back now.

34:22 One of the early ones, yeah.

34:24 Just a bright little idea, I thought, which was that we were starting to get people contributing

34:30 strategies other than the three of us.

34:32 And I was starting to find it tricky to work out, is this strategy the same as one that we've

34:39 already got?

34:40 And this is back in the days when I think we only had about 30 or 40 strategies.

34:44 And I was starting to find it tricky then because, of course, it's not enough simply to look

34:50 at the code because the same decisions can be coded in all sorts of different ways.

34:57 So it struck me that we could do with a better way of trying to decide whether a given strategy

35:05 was at least similar to one that we'd already seen.

35:09 And I naively typed that up into an issue on the repository and said something like, maybe

35:15 we should just find a handful of strategies that we play them against and we can do something

35:20 clever mathematically to work out how similar they look, thinking that my friends, the mathematicians

35:26 would go, yeah, that's a great idea.

35:27 I'll do that this afternoon.

35:30 Oh, no, they say this is a significant mathematical challenge.

35:34 And 12 months later, here we are with some poor student of Vince's doing it as his final

35:40 year project.

35:40 The interesting thing is that that poor student is actually Owen's son.

35:46 He's now doing his final year project with me.

35:49 And so he's implemented this graphical approach from the literature, which has its strengths

35:54 and weaknesses.

35:55 But actually, I think this might be news to both Mark and Owen, as well as all the listeners,

35:59 is he's just been working on a cleverer way of doing it, building a statistical model that

36:05 will spit out if two strategies are different or not.

36:07 So yeah, hopefully we'll be able to talk about that a bit more at some point.

36:10 Well, I think that's really funny that you just throw that out there.

36:13 Like, ah, you guys could just like compare strings or something and see.

36:16 No, no, this is actually a lot of work.

36:19 But on the other hand, it's super cool that something constructive as a project is coming

36:25 out of it, right?

36:25 Like, that's interesting.

36:27 And things have worked the other way, too, where I've gone like, oh, we got to do this

36:31 thing.

36:32 It's probably going to be really, really hard.

36:33 And then Owen and Mark are going, oh, you just need to use a class, something, something,

36:38 something.

36:38 And like, it's two lines of Python.

36:39 I'm like, oh, okay, cool.

36:40 I can actually do that in a less comprehension.

36:42 We're good.

36:44 Have you thought of involving like deep learning and the classification of similarities?

36:49 Like, that would be interesting.

36:50 I did write a blog post a couple of years ago where I derived a bunch of features of the

36:54 strategies and the tournaments and did a little bit with it.

36:57 But that was back right when we had just about 100 strategies and we weren't calculating as

37:01 many things.

37:01 So that's definitely worth a revisit, see if we can do more.

37:04 That's actually kind of, that was the plan with this poor final year student.

37:08 But actually, we've kind of got some really promising results using rather naive statistical

37:14 models.

37:14 So we need to look into that a bit more, but it doesn't look like we need to be too

37:18 sophisticated.

37:19 Again, because of the way the tournament is now and the, sorry, the way the library is

37:23 now, it can just create so much data for us, which is a real strength.

37:27 Oh, that's excellent.

37:28 I think this is a real service, not just for Owen's son and your student in this particular

37:33 case, but I think that it's, this kind of stuff is really valuable to students who are

37:39 coming out of school and they want to get a job, right?

37:42 If they come in and say, well, what do you know about programming?

37:44 Would you like to see my project on GitHub and maybe the paper that was published built

37:49 off of it?

37:50 And here's my optimizations I've done.

37:52 And like, if you can provide that to students, then they're in such a better place when they

37:56 go out and say, Hey, I want a job.

37:58 We actually had a student turn up today or yesterday.

38:00 I forget.

38:01 And she, you asked, didn't you, Owen?

38:04 Like, how did everyone find this library?

38:05 Because we've had quite a few people now.

38:06 And she said, Oh, actually, as part of my course, I have to contribute to an open source project.

38:12 And, you know, she'd found the actual project and seen the documentation and the community.

38:16 And she's decided to choose us, which is great.

38:18 Oh, wow.

38:19 That's really cool.

38:19 Think of how the world is going to be after 10 years of this kind of stuff.

38:23 Like all the students have to contribute to open source and they have to somehow be really

38:26 aware of this.

38:27 And they're totally familiar with, that's your pull request.

38:29 They know what that means.

38:30 Like that's just, you know, it's already got so much momentum, but I could see a world

38:35 where it's like, we'd look back at these as quaint days when open source was small.

38:40 Another good kind of side to this project is in terms of academic research.

38:44 So going back to the fact that Axelrod's original tournaments can't really be reproduced and there's

38:48 loads of papers that can't be reproduced.

38:49 That's like a problem in modern research where so much software is needed and written, but

38:55 it's not necessarily written in a sustainable way.

38:58 And so the Axelrod project is a really good example of maybe I'm a bit biased, obviously,

39:02 but I'd say best practice in terms of, you know, our code isn't only written and documented

39:06 well, but it's extremely well tested and it's constantly being refactored and improved.

39:11 And it's all, you know, a wonderful example of how you should be doing research.

39:14 Yeah.

39:14 You guys have a nice read the docs and all sorts of stuff, right?

39:17 But just to go into Owen's point, it's pretty rare for academic code to be even sufficiently

39:21 documented to use it again, let alone enhance it or anything like that.

39:25 It's just because the journals don't require it a lot of times when you publish it.

39:29 And two, I think the way we have our test suite, we really try to test every stated behavior of

39:35 every strategy so that we know that it is as close to the real deal as we can get it.

39:40 That is really awesome.

39:41 And I think it's great.

39:42 And you have sort of the case study in this example of the way not to do it and the way

39:47 to do it all wrapped into one, right?

39:50 With the actual rod original tournaments and people are like, we don't even know if we

39:53 can reproduce these strategies.

39:54 And yet there's, there are papers and stuff written on it, right?

39:57 Absolutely.

39:57 And so you're like, well, how do you validate that science, right?

40:00 That's been a real eye opener to me as somebody that's, that's got no academic background whatsoever

40:05 since the day I graduated and vowed never to sit an exam again in my life.

40:10 To come back into it, albeit on the fringes, however many years later, and find that there

40:19 are papers and papers and papers written on the back of software that isn't accessible.

40:24 And I look at that and say, well, how is that reproducible?

40:27 How is that scientific?

40:28 And it's been, it's been a real shock to me to find that we in this little project have

40:35 so much of a struggle to try and reproduce other people's results.

40:38 Yeah.

40:38 But I think what you guys are doing, I mean, obviously it's open source.

40:41 It's got version control all the way through.

40:43 So somebody can go back, well, this paper was written on this version.

40:46 It's not just, I still have the library, but I have exactly the same code.

40:50 I think that's interesting.

40:51 You know, I was talking to Kyle Cranmer from the Large Hadron Collider, and he was talking

40:56 about how this is the problem in particle physics as well, just like reproducible science in general.

41:01 And they do interesting things like have kind of an escrow service to hold the code tied to

41:06 the paper and stuff like that.

41:08 So I think, I think there's people trying different things from different angles, but yeah, very nice

41:13 work.

41:13 So what's the computational story here?

41:17 You have 183 strategies, 200 rounds.

41:21 They all fight with each other in certain ways.

41:23 Like how long does it take to run a typical tournament?

41:26 Is it pretty quick or is this like, you got to go have lunch?

41:30 Well, the full tournament on all the strategies takes about an hour on a typical machine.

41:35 So does that fit with that?

41:37 Vince has some nice 16 core machines that can really chew through it.

41:40 Yeah.

41:40 So on that, it's still just under an hour for the full noisy tournament, which is the

41:45 one that takes the longest amount of time.

41:46 Because that's another thing that's inbuilt in the library.

41:48 It's completely paralyzed.

41:50 So you can play all these matches in parallel and the library takes care of that for you.

41:53 So you can use up as many cores as you can get.

41:55 Okay.

41:55 That's cool.

41:56 And some of the classifications, if the strategies are deterministic, then we don't have to

42:00 repeat those matches.

42:00 But if the tournament's noisy or the strategies are stochastic, then we have to repeat those

42:06 more times.

42:06 So depending on exactly what strategies you choose, it can be extremely fast if they're

42:10 all deterministic or it can take a lot more time if it's like a noisy tournament.

42:15 Okay.

42:15 So have you guys tried to do any fancy tricks to make it faster or something like that?

42:20 You talked about figuring out if it's deterministic and then going, okay, it already knows

42:26 the answer to this.

42:26 I would want to very cautiously say that I think we're already doing a fair few of these

42:32 tricks, you know, like the parallelization, like vectorizing things where we can.

42:36 But again, if anyone wants to take a look and make it faster.

42:39 Writing the multiprocessing is several days of my life I'll never get back and I don't

42:43 wish to repeat.

42:44 Yeah.

42:45 And as someone else who worked on that part of it, wow, yes.

42:49 Yeah.

42:50 I think we all kind of broke our knuckles on that for a bit.

42:53 Yeah, that was...

42:53 Yeah, that sounds really cool.

42:55 Of course you want it to go as fast as possible, right?

42:57 Like, you know, maybe somehow bringing some NumPy scipy into it.

43:01 I don't really know or who knows.

43:04 But it seems like an interesting computational challenge in its own right.

43:07 Yeah.

43:08 And you guys have battled it some, it sounds like.

43:10 Yeah.

43:10 And part of it is memory overhead as well.

43:13 If you're batching out the matches, you can do them in parallel.

43:16 But if you do too many of them, then you exhaust your memory, you hit swap, and then you're

43:21 done for, you know?

43:22 Yeah.

43:23 That was a big bit of work when all of a sudden we realized that like we were using more than

43:27 16 gigs of RAM and we kind of did it all.

43:29 So now it's basically got no memory fingerprint anymore.

43:32 But we do it all to file.

43:34 But I'd forgotten about that.

43:35 Yeah.

43:35 Yeah.

43:36 Yeah.

43:38 It sounds just like an interesting algorithmic problem.

43:41 And then, you know, you've got the known structure to deal with and stuff.

43:46 But then people are throwing these strategies at you that you have no idea on how they're

43:49 going to behave.

43:50 And so that's like an interesting twist.

43:51 It just, it sounds like a fun problem to me.

43:53 Yeah.

43:53 We do label the strategies too if they have a long run time.

43:55 So some of them take 10 times, 100 times longer in whatever computations they do than

44:00 say tit for tat.

44:01 So that's another thing that we've studied, optimizing specific strategies.

44:05 There's a couple of really cool strategies in the library.

44:07 They're called meta strategies.

44:08 And they basically take a large group of the other strategies in the library, maybe all

44:14 of them, and then take the consensus vote or something like that.

44:17 So they, by definition, are 100 times slower than the other ones.

44:21 Yeah.

44:22 Because they just keep rerunning.

44:23 That's a pretty interesting idea.

44:24 It's almost like the politician thing.

44:27 You see what people are asking or what they want and just like, I'm just going to do that.

44:31 Well, however the wind is blowing, that's how we're going to cooperate here or whatever.

44:36 Yeah.

44:37 So are there interesting combinations that work well?

44:40 Have you tried that?

44:41 Instead of running all of them, go like, I think this set of them or that set, like this

44:46 mixture of like, I'll ask these 10 and see what I get.

44:50 I have played with it a lot.

44:52 So that was one of the best strategies in the early days, these meta strategies.

44:55 And of course, you know, if you give them like the top five other strategies in the library,

44:59 then it does well.

45:00 But one change we made recently is rather than take the best performer of all the strategies

45:06 in its set, if you randomly take one of the top 10 performers, it actually works better.

45:11 And if you always go after that top one, which is sort of a weird quirk of like an ensemble

45:15 machine learning method.

45:16 Yeah.

45:16 Yeah.

45:16 Very interesting.

45:17 You can study a lot of cool stuff with us.

45:20 It sounds like.

45:20 So maybe give us some stories like where this has been used.

45:25 Like, obviously, if any of us or any two of us, I should say, get like captured by the police

45:32 and charged with a crime, we'll know what to do.

45:35 We'll have a more informed view on what to do.

45:38 But, you know, it's not just for prisoners, right?

45:40 It applies to other things as well.

45:42 Yeah.

45:42 And Owen added a pretty interesting strategy not that long ago where you can play as a

45:46 human.

45:47 So you can pick the strategy you want to play against and you can submit C or D and practice

45:51 your one-on-one skills versus these strategies.

45:53 Nice.

45:55 That could have been an Atari game when it first came out.

45:58 One of the kind of applications of this study is to understand the evolution of social norms.

46:06 So, you know, like as Mark said at the beginning, you know, why when you look around, are we cooperative?

46:11 And then that kind of steps onto other fields of evolutionary game theory that are then applied

46:18 in like mathematical oncology and things like that.

46:21 So these ideas are all interconnected and have wide-ranging applications.

46:25 Yeah.

46:26 Okay.

46:26 Cool.

46:26 You said that there's some applications in mathematical oncology for cancer.

46:31 Yeah.

46:32 What's that?

46:33 That's kind of not immediately looking at the prison's dilemma, but the same ideas kind

46:38 of transpire that you can see the spread of a tumor inside a health body in the same way

46:46 that you can think of introducing a particular strategy into another population.

46:51 And so things like Moran processes and evolutionary dynamics and population dynamics have been used

46:57 to understand, yeah, the spread of cancer.

46:59 And so mathematical oncology.

47:00 Yeah.

47:01 You can kind of think of cancer as a cooperator that has switched strategies to a defector

47:06 and is now trying to take over.

47:08 And so can it invade that population or not?

47:11 Oh, wow.

47:12 Okay.

47:12 It's really interesting when these things make connections to somewhere where they're totally

47:17 unexpected, right?

47:18 Yeah.

47:19 Like people working, you know, I'm sure Nash wasn't thinking about cancer when he worked on

47:22 his game theory ideas.

47:24 Nash got his Nobel Prize in economics, right?

47:26 And the ideas that he was thinking about when he first wrote his paper and his thesis, they

47:32 kind of just rolled really.

47:34 And he didn't really see it coming.

47:35 Well, I'll say that.

47:36 I don't know that for sure.

47:38 But it certainly wasn't what he was thinking of when he was doing the work.

47:40 Yeah.

47:40 Yeah.

47:41 Yeah.

47:41 Very interesting.

47:42 Yeah.

47:42 And it's still using economics now.

47:43 So there's this idea, this like first approximation that everyone does what's best for them.

47:48 Like they take all the available information and they say, it's best for me to invest in

47:51 this thing.

47:52 And that's not what most people do.

47:53 Most people just copy someone else's strategy or someone else's advice.

47:57 So it's more of an evolutionary process than rational process that we would think of it.

48:01 Sure.

48:02 Does it appear in politics or is politics too slow of a process, right?

48:07 Like every four years, every six years, like is that enough for people to see these strategies

48:13 and evolve?

48:13 Or what do you think?

48:14 Well, I know there's papers that are written in political science that use this kind of stuff,

48:17 but I don't know how well applied to the real world they are.

48:20 They might just be theoretical.

48:21 I know there were lots of blog posts written about game theory and Brexit.

48:26 So some combination.

48:28 Yeah.

48:29 I was just saying, well, I was thinking of Brexit.

48:30 I was thinking of the US presidential election.

48:32 Like both of these are unexpected.

48:35 And I'm wondering if game theory has interesting things to say about them.

48:38 Don't blame us.

48:39 I'm not blaming you guys.

48:40 I was actually in London when the Brexit vote happened.

48:43 And it was very interesting to walk the streets of London the day after.

48:46 It's quite something.

48:47 A really, really neat project.

48:49 And I love how it applies to all these different things.

48:52 And I don't know if Mark and Vince have noticed, but whilst we've been chatting on our Gitter

48:57 channel, we've now had somebody new come on saying, that they're a student.

49:01 They're on a course where they're required to contribute to an OSS project.

49:05 And they like the look of our project and they'd like to know how to get involved.

49:10 So that's awesome.

49:11 I could tell you what to say.

49:12 I didn't think this was a live broadcast, but now I'm beginning to.

49:17 Gosh, yeah.

49:18 Talk Python works fast.

49:19 Yeah.

49:20 Well, maybe it's just someone's hacked into my computer.

49:22 So what you need to tell them.

49:26 I think that's as much as it's on the one side of where the library is gone.

49:30 And it's a really sophisticated, rich research tool that has various applications and things.

49:36 But one of the other things that we've kind of really been careful to is sometimes at the

49:40 cost of efficiency, we have prioritized readability and entry of newcomers, not only to Python,

49:47 but the programming.

49:48 And I think that's something that we're all pretty proud of, that the library is a good place for newcomers.

49:53 In fact, at one point, the winning strategy, it's no longer the case, but at one point,

49:59 the winning strategy was written by a particular high schooler in the UK, which is actually Owen's other son.

50:06 So cool.

50:08 There's a lot of connections to Owen's children here.

50:11 How interesting.

50:12 They get you into all sorts of trouble.

50:13 So, Owen, here's what you need to tell that person and get her.

50:17 There's this simple problem about fingerprinting, and they should be able to knock that out right away to get started.

50:22 All right.

50:25 I think maybe we're kind of getting low on time here for talking about the project.

50:29 There's one other thing I wanted to ask you guys about here.

50:33 And you said that in the notes, you'd put down something for a thing called ugly fruitcake.

50:38 What is ugly fruitcake?

50:40 That's my son's username on Twitter.

50:44 Awesome.

50:47 Well done, Mr. Ugly Fruitcake.

50:50 No, that's awesome.

50:52 Excellent.

50:54 Excellent.

50:55 Okay.

50:55 So I guess we'll kind of have to leave it there.

50:58 We're getting low on time before we're talking about it.

51:00 But it's been really, really fun to talk about.

51:02 Let's talk two things really quick before we drop this, I suppose.

51:06 I still want to ask you.

51:06 One, what's the Python 3 versus Python 2 story?

51:09 Like, what support is there for each version?

51:12 So for a long time, we were supporting both.

51:14 And eventually, we kind of made what I think is one of the best decisions we've made so far is we dropped Python 2.

51:21 Was that on the 1st of December last year?

51:23 I seem to remember.

51:23 And that's just allowed us to clean up our code base so much and pull people away from legacy Python.

51:31 So yeah, we're using...

51:33 That's awesome.

51:33 I think that's a really great move.

51:34 And also, you were talking about the readability and the simplicity.

51:37 Like, as a newcomer to Python, you're often, like, hit in the face with this dichotomy.

51:42 And if you can avoid that, that's really nice.

51:44 And even as not a newcomer, it was still challenging sometimes.

51:47 We've gotten into weird cases where iterators and generators were interacting across the different versions.

51:53 Right, right.

51:54 Yeah.

51:54 Or just mistakes because of division.

51:59 Yeah, absolutely.

51:59 And then also, Jaxelrod, am I saying that correctly?

52:03 Yeah.

52:03 What is Jaxelrod?

52:04 Oh, Django Axelrod.

52:05 That's a longer-term attempt, really, to build a web app on top of this library.

52:12 So instead of installing it yourself and trying to set up tournaments on your own machine,

52:19 the idea here is to say, well, it would be good to be able to tuck this library away somewhere on a much bigger machine

52:26 and put a web front end on it, and in that front end, you could define the tournaments that you want,

52:31 submit them to the server, it would run them, and then spew the results back at you

52:36 for you to get out and do some analysis with.

52:38 That's a project that we've kicked off, and the reason for the name purely is because we're using Django

52:44 and the Django REST framework to try to do it at the moment.

52:46 But it's in fairly early stages at the moment.

52:49 So again, if anybody listening fancies getting involved, it would be an excellent area to get into.

52:54 All right. You want to do some web work and turn interested in game theory?

52:57 Here's your chance, right?

52:58 Yeah, absolutely.

52:59 It's very cool.

52:59 Okay, nice. Is that publicly available or just something you guys have?

53:03 No, no, no. It's another one of the repositories on GitHub under the actual Python organization.

53:08 All right. Awesome.

53:09 The organization GitHub profile has not only the library, but it has lots of really interesting collection of notebooks,

53:15 collection of visualizations, the fingerprints, lots of interesting repositories there,

53:19 as well as Jack Solrod and this rest of the way.

53:21 Okay, excellent. Yeah, I'll definitely link to those as well. That's great.

53:24 All right, guys, it's been super interesting. I really enjoyed our conversation.

53:28 But before I let you go, quick round of questions.

53:31 Owen, if you're going to write some Python code, where do you open up?

53:34 I'm a sublime text man.

53:36 And you said that you like the Anaconda plug-in, right?

53:38 I do. It sits there and tells me where I've gone wrong. Shows me all my mistakes, yeah.

53:44 You like people to yell at you, huh?

53:45 As long as it does it quietly so I can ignore it when I feel like it, that's fine.

53:51 Yeah, no, I think things like that that really give you that extra insight are super, super valuable.

53:56 So, cool. Mark, how about yourself?

53:58 So, I usually use PyCharm lately. I started using it about a year ago, and I really liked it.

54:02 Before that, I just used kind of a bare-bones text editor for the most part.

54:07 Okay, nice. And you probably use a lot of Jupyter, like, notebooks and stuff as well at work.

54:11 Yeah, in general. I also teach a data science class that's based on Jupyter notebooks, so I'm really comfortable.

54:17 Yeah, I like Jupyter a lot, actually.

54:19 Yeah, it's pretty neat. It's definitely got a lot of momentum.

54:21 Vince?

54:22 I also use Jupyter a bunch, but my editor's done.

54:25 Okay, awesome.

54:25 And PyPI package, we just passed over 100,000 PyPI packages, which I think is...

54:32 Yay!

54:32 That's awesome.

54:33 Yeah, that's so cool.

54:36 So, how about, like, the favorite ones? Like, same order. Owen, how about you?

54:40 I think my favorite at the moment has got to be Conch, the shell, the Python shell.

54:45 So, I've finally got to the point now where it doesn't matter what operating system I'm on, I've got exactly the same shell, and its config files are written in Python.

54:54 It's a thing of beauty.

54:55 That is beautiful. And that's X-O-N-S-H, Conch.

54:59 It is.

54:59 It's very cool, yeah. Mark?

55:00 I think Request is my favorite. It's so easy if you're doing any kind of, like, web scraping or anything like that.

55:06 I like a lot of the different ones on there. And, of course, Axelrod has got to be my favorite one.

55:11 Yeah, why not throw that out there? For sure, for sure. And Vince?

55:16 I have to mention QCiW. That's written by a PhD student of mine, so I just want to test that he actually listened to the end.

55:22 It's a library for simulating queuing processes, but I think my favorite has to be TQDM.

55:28 It's a brilliant little library that you can use to wrap any iterator, and it'll generate a progress bar for you for free.

55:37 Oh, that is cool.

55:38 Yeah, it's really, really cool, because you don't have to do anything. You just get these progress bars, which sometimes when I'm doing something, that might take a little bit of time.

55:45 I'm not sure how long. I can just quickly import TQDM, and straight away I get an idea of, oh, no, this isn't going to take an hour.

55:50 This is going to take a couple of years. I've got to change something.

55:52 Exactly. Fabulous.

55:54 Okay, great recommendations, guys. Thanks. And final call to action, people should get started with Axelrod?

56:00 Yeah, come on over. Come check us out in our Gitter room and just say hi and submit a strategy or anything else.

56:06 But yeah, we really welcome contributors.

56:08 Yeah, I can say look at the code. It looks definitely easy to jump into, especially if you want to do the strategies.

56:13 And I feel like there's a chance to plug in more interesting, intriguing things that people are not expecting and probably get some cool results.

56:21 For sure. Absolutely.

56:23 All right, guys. Well, this has been a great chatting with you. Thanks for being on the show.

56:26 Thank you so much.

56:27 Thanks for having us. Thank you.

56:28 Yeah, it's been a pleasure. Thank you.

56:29 Yes, it has. Bye.

56:33 This has been another episode of Talk Python to Me.

56:35 Today's guests have been Vince Knight, Mark Harper, and Owen Campbell.

56:40 And this episode has been sponsored by Talk Python Training.

56:44 Check out all the courses at training.talkpython.fm.

56:47 Be sure to subscribe to the show.

56:49 Open your favorite podcatcher and search for Python.

56:51 We should be right at the top.

56:53 You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.

57:02 Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.

57:07 Corey just recently started selling his tracks on iTunes, so I recommend you check it out at talkpython.fm/music.

57:14 You can browse his tracks he has for sale on iTunes and listen to the full-length version of the theme song.

57:19 This is your host, Michael Kennedy.

57:21 Thanks so much for listening.

57:23 I really appreciate it.

57:24 Smix, let's get out of here.

57:44 We'll see you next time.

57:48 Thank you.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon