Latest / Talk Python To Me / #104: Game Theory in Python
Transcript
- 0:00Game theory is the study of competing interests, be it individual actors within an economy or healthy versus cancer cells within a body.
- 0:08Our 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.
- 0:19This is Talk Python To Me, episode 104, recorded March 8th, 2017.
- 0:25Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem,
- 0:55and the personalities.
- 0:56This is your host, Michael Kennedy.
- 0:58Follow me on Twitter where I'm @mkennedy.
- 1:00Keep up with the show and listen to past episodes at talkpython.fm and follow the show on Twitter via at Talk Python.
- 1:07This episode is brought to you interruption free by Talk Python Training.
- 1:12That's right, I'm talking about my courses.
- 1:14Whether you want to get started learning Python with the Jumpstart course, learn over 50 Pythonic coding techniques, or consume a bunch of HTTP services,
- 1:22I've got a course for you.
- 1:23If you're not already subscribed, be sure to be a friend of the show at talkpython.fm/friends.
- 1:29I 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.
- 1:36And finally, if you work for a company with 200 developers or more, we should talk.
- 1:42I have a very special first-time offer for enterprises.
- 1:46All right, now let's get on to learning how we can minimize our prison sentence by studying the prisoner's dilemma.
- 1:52Oh, and Vincent, Mark, welcome to Talk Python.
- 1:56Thanks for having us.
- 1:57Thanks for having us.
- 1:57Yeah, pleasure to be here.
- 1:58Yeah, 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.
- 2:07It's going to be so much fun.
- 2:08But 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.
- 2:16Vincent, how did you get into programming in Python?
- 2:18I'm a mathematician, and so I used various bits of commercial software during my PhD, so Mathematica, the main one.
- 2:25And then I started looking for a free alternative, and that's how I stumbled on SageMath.
- 2:31And from SageMath kind of fell into Python and slowly, slowly grew from there, and now I teach Python.
- 2:39That's really awesome.
- 2:40And so it's great that you started with SageMath.
- 2:43I've had William Stein on the show, and I think SageMath is quite the cool project.
- 2:47It's really generated a lot of neat things like Cython that people are doing totally different stuff with today.
- 2:55Do you teach classes with SageMath, or do you just teach Python?
- 2:58We used to.
- 2:59I 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.
- 3:08So the Python Simpy library kind of does a lot of what our first years need to do and the various things about the installation.
- 3:14That's getting better, especially with Cloud.SageMath, but we've just moved to just teaching Python now.
- 3:19Sure.
- 3:19Okay, great.
- 3:20Owen, how about you?
- 3:21What's your story?
- 3:22Well, I'm a ZX81 generation, so I was bought one of those things as a small child, and I've never really looked back.
- 3:31Once I realized that people were prepared to pay me to do this stuff, that was the career for me.
- 3:36Like, you know, I could play with this toy every day and I get paid for it?
- 3:39Oh my gosh, I'm in.
- 3:41Count me in.
- 3:41Exactly.
- 3:42I 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.
- 3:51Nice, nice.
- 3:52I'm relatively new to Python.
- 3:54I actually started.
- 3:55My 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.
- 4:05And I thought, right, well, we'll get a head start on, I'd better learn this stuff so that I can teach him.
- 4:10And 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.
- 4:21Now 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?
- 4:29If you go into almost any kind of university with programming skills of some sort, you're at such an advantage, I think.
- 4:38Well, I'm sure he'll think so too now that he hears you saying it on this podcast.
- 4:42I've seen it work out well for a lot of people.
- 4:47All right, Mark, how about you?
- 4:49Sure, I'm a data scientist.
- 4:50I currently work at Google.
- 4:53Before that, I was an academic in bioinformatics, which we used a lot of Python in.
- 4:57And I started with Python before that when I was a graduate student in mathematics.
- 5:03I started writing C++ way back in high school, and that was okay for a while.
- 5:08But then I looked for languages that were maybe more efficient with my time and less efficient with the machine's time.
- 5:14So I had a very brief stint with Perl before I found Python, and then I never looked back.
- 5:20Oh, that's awesome.
- 5:21And you're using Python day-to-day at Google?
- 5:23Among other languages, yes.
- 5:24Yeah.
- 5:25Okay, cool.
- 5:26Yeah, you said you started with C++.
- 5:28I remember when I was at university, they told me I had to start with Fortran, and I pleaded to let me do C++ instead.
- 5:35I'm like, this will be so much more useful.
- 5:37I'm sure.
- 5:37No, no.
- 5:38Fortran is the most important language you'll ever learn.
- 5:41I'm not sure I still agree with them.
- 5:43I was told it was a high-level language.
- 5:45Yeah, there was a two-year period where C++ was the language of the future before they decided that that was Java.
- 5:52You guys all worked together on this project.
- 5:55How did you come to meet each other?
- 5:57One, I think, the university connection there.
- 6:00But how did you end up working on this project together?
- 6:02I 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.
- 6:10But, yeah, the link between Owen and I was through Owen's son.
- 6:13I think I found your GitHub page because it was shared on an EGT blog on Google+.
- 6:19Ah, yeah, yeah, yeah.
- 6:21And then I went over and I poked around a little bit and realized I could add a couple strategies right away.
- 6:26And I did that.
- 6:27And then I came back a couple months later and started working more on it.
- 6:30Yeah.
- 6:31And it just kind of snowballed from there.
- 6:32Okay.
- 6:32Yeah, really interesting.
- 6:34I think GitHub has – their slogan is like social coding or something like that.
- 6:39But I really do think it's connected people in some pretty powerful ways.
- 6:42It's amazing.
- 6:43For 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.
- 6:56And so everything I've learned is from coding with these two guys, really.
- 6:59It's just kind of skyrocketed my own knowledge of writing code.
- 7:03So, yeah.
- 7:04And that's thanks to GitHub, in a way.
- 7:06Yeah, absolutely.
- 7:06Thanks to GitHub.
- 7:07Very cool.
- 7:07So let's start with what is game theory.
- 7:11So 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.
- 7:20But let's start at a high level.
- 7:20What's game theory?
- 7:21Okay.
- 7:22So it's loosely – loosely, it's kind of the study of interactions between different individuals or agents in some shape or form.
- 7:33And so it's kind of the study of how strategic interactions form.
- 7:38You know, like if I know what you know, what should I do at a very loose level?
- 7:43And hard to say when it really began.
- 7:46There's kind of different – people tell you different things about when it started.
- 7:50But the famous game theorist is John Nash.
- 7:53And he kind of found a particular solution concept to game theory.
- 7:58So, yeah.
- 7:59John Nash won the Nobel Prize for his work in economics.
- 8:02Right.
- 8:03That's right.
- 8:03I originally thought it was a Fields Medal.
- 8:04You guys said, no, no, no, no, no, no.
- 8:06Very cool.
- 8:07And he's also the subject of that movie, A Beautiful Mind, which was a great movie.
- 8:13So maybe tell us, like, what example was he working with?
- 8:16Do you remember what his work was on?
- 8:18Yeah.
- 8:18So he worked on Nash Equilibria, which is kind of a solution concept for in a strategic situation.
- 8:25There'll be a set of actions that all the players can take from which no one has a reason to do anything different.
- 8:33So there'll be a point at which we can't really improve.
- 8:36And his work was to show using a really clever proof that that point always exists.
- 8:43So it was an existence proof.
- 8:44And that's kind of snowballed as a solution concept for these strategic interactions.
- 8:49And so, yeah, in the movie, he has this kind of moment in the bar where he sees everything.
- 8:55And 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.
- 9:06Right.
- 9:06Economics as well.
- 9:07And we can get into these local minima, right, where, like, nobody is benefiting from what is happening as much as they could be.
- 9:14But somebody has to move first.
- 9:16And so game theory kind of explores that space and finds these minimas.
- 9:22So if you consider these strategies or those strategies, you'll end up in this situation.
- 9:27And it's interesting in economics.
- 9:29It's interesting in public policy.
- 9:31And it's, you know, all sorts of places.
- 9:33Right.
- 9:33Mark, did you want to add something to the game theory thing?
- 9:36I think it's a good summary.
- 9:37The paper that Nash wrote is really famous because it's only one page long.
- 9:40And it has a huge number of citations.
- 9:44So it's kind of a story goes pretty deep.
- 9:47But, 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.
- 9:55One which is really bad for everyone and one is really good for everyone.
- 9:59And whether or not those positions are stable or not is another big part of it.
- 10:04It's one thing to be at that equilibrium.
- 10:05It's another thing if you can be kind of easily nudged off of it.
- 10:08And that's the class.
- 10:09Yeah.
- 10:09Yeah.
- 10:10How hard is it and how seated are people in their ways?
- 10:13You know, you can see that looking at society sometimes.
- 10:15You're like, well, why are things structured this way?
- 10:17And you just, if people just did this, right?
- 10:20And so I think this is really interesting to explore that.
- 10:23Like one of the classical problems in this space and what is the focus of your library.
- 10:28So remind me, what's the exact name of your library?
- 10:30Axelrod?
- 10:31The Axelrod Library.
- 10:32Just Axelrod.
- 10:33Okay.
- 10:34I wasn't sure if there was like a dash or something.
- 10:36So the Axelrod Library.
- 10:37Let's start out with, what's the origin of that name?
- 10:40Axelrod is the name of a researcher who did an influential tournament several decades ago
- 10:46around the iterated Prisoner's Dilemma where some of the classic strategies like...
- 10:51So what's the Prisoner's Dilemma?
- 10:53Well, so it's named after Robert Axelrod.
- 10:55That's his full name.
- 10:56And the Prisoner's Dilemma is a particular situation in game theory where...
- 11:01A lot of academics run into this problem, right?
- 11:02They find themselves...
- 11:04Just kidding.
- 11:05Right, right.
- 11:05So the story behind the Prisoner's Dilemma is you've got two prisoners and I guess you've
- 11:10arrested both of them and they both have to decide whether they're going to rat on the other guy.
- 11:15Right.
- 11:15Some kind of co-conspirator, co-criminal sort of thing, right?
- 11:19Right.
- 11:20And if you both just...
- 11:21A gang.
- 11:21Right.
- 11:22And if you both just don't say anything, then they have some evidence and they can maybe
- 11:27get you with a low-level crime.
- 11:29But if one of you rats out on the other one, then they'll use that confession against them.
- 11:32So it's in the prosecution or the police's best interest to get you both to confess.
- 11:37And it's in both of your own individual best interest to say nothing.
- 11:41But they provide you with a big incentive to confess on the other person.
- 11:45They say, well, we'll let you go without any penalty if you'll just confess to the other
- 11:49person.
- 11:50So it's in your rational...
- 11:52It's in your own personal interest now to confess on the other person.
- 11:55But the problem is it's in their best interest to confess, to testify against you as well.
- 12:00And if you both confess, then it's bad for both of you, right?
- 12:02This is like one of the local minimums that you can get stuck in that's really bad.
- 12:06Right.
- 12:07Exactly.
- 12:07You both go into jail because you both don't want each other, yeah?
- 12:09Okay.
- 12:10And so the actual Rod library or the actual Rod project was around modeling the prisoner's
- 12:16dilemma, correct?
- 12:17Yeah.
- 12:17So one of the things is how do people end up cooperating?
- 12:20If we're all incentivized not to cooperate with each other, yet we look around, we see all
- 12:24these situations where people are cooperating.
- 12:27So can we devise strategies that when we play this game repeatedly that coerce or convince
- 12:34our partners that they're better off cooperating with us than defecting against us?
- 12:37Yeah.
- 12:37Okay.
- 12:38So let's think about some of the things that you can do with this library.
- 12:42So the actual Rod competition was held, you said, in the 80s.
- 12:45And you said the algorithms were lost or the strategies were lost to time.
- 12:49Is that true?
- 12:50There's some that can still be found.
- 12:52But I actually exchanged a very brief, when we started this library, I exchanged a very
- 12:55brief email conversation with Robert Axelrod saying, I don't suppose you happen to have
- 12:59any of these strategies kicking about.
- 13:01And from his very first tournament, he simply said, no, they're not around.
- 13:05And some of the others are written in, what, in Fortran, I believe?
- 13:08Yes.
- 13:09And they're not very well documented or anything like that.
- 13:11So they're quite difficult to follow.
- 13:13So some have published descriptions in various books and papers.
- 13:19But again, they're not usually sufficiently detailed to allow you to completely reproduce
- 13:24the strategy.
- 13:25Yeah.
- 13:25It's not.
- 13:26It's one thing to describe the concept.
- 13:28It's another to implement it, right?
- 13:29Yeah.
- 13:30Exactly.
- 13:30We had one poor individual at the PyCon UK Sprint last year who came to the
- 13:35work on the project and spent the entire day wading through the Fortran code for some
- 13:40strategy that he was trying to reimplement.
- 13:42I don't think he was expecting to spend the day working on Fortran at a PyCon.
- 13:47Well, how was your PyCon experience?
- 13:50Well, people were nice, but all I did was Fortran.
- 13:53It was dreadful.
- 13:54Let's talk a little bit about what this library does.
- 13:58It's like, so you can set up these things called strategies, right?
- 14:01And you can have players and tournaments.
- 14:05Maybe give us a sense for what the whole thing does.
- 14:07Well, in the end, each player that's participating has a very simple choice to make, which is either
- 14:13to cooperate with their fellow prisoner or to rat on them.
- 14:17So a simple choice between two options.
- 14:20And so what we do in the library is to say all of the different strategies that we know
- 14:28about, we play them against one another.
- 14:31And first of all, we do that in pairs.
- 14:32So we'll put a pair of players against one another and they'll play the game repeatedly over and
- 14:38over and over again.
- 14:39And then we'll just match up all the different combinations of pairs for however many players
- 14:45we're interested in.
- 14:46And we'll tot up all the scores and see who comes out on top.
- 14:50Okay, excellent.
- 14:51So give us a sense for some of the, you have some clever names for the different strategies
- 14:55or players, right?
- 14:56Strategy and player, it's kind of the same thing.
- 14:58So you've got like the basic ones, the cooperator and the defector.
- 15:02But what else?
- 15:03Well, probably the most famous one is the tit for tat strategy, because in Axelrod's
- 15:09original tournament, one of the interesting results that came out of his work was that
- 15:13this strategy was one of the most successful.
- 15:16I'm sure the other two will correct me, but possibly even the most successful of the lot.
- 15:20Yep.
- 15:20In his tournaments.
- 15:21Yep.
- 15:21Yep.
- 15:21All right.
- 15:21So what's tit for tat?
- 15:22If you rat on me next time, I'm ratting on you.
- 15:27I'm going to rat on you.
- 15:27Yeah.
- 15:27Yeah.
- 15:28And if you're nice to me, I'll be nice to you.
- 15:30So it simply, it looks at what its opponent did the last time they played and simply plays
- 15:38exactly the same choice that they made when it comes around to the next turn.
- 15:41So of course, if the opponent is being cooperative with it, then it will cooperate.
- 15:47So it is quite a cooperative strategy and it did very well in Axelrod's original tournament.
- 15:53Interesting.
- 15:53And then you've got the grudger, which if you ever turn on the grudger, you're going to regret
- 15:59it, right?
- 16:00Well, what else?
- 16:00There was a few other interesting ones.
- 16:03Yeah.
- 16:03There's a lot of variants of strategies where if you cross them once, they'll never cooperate
- 16:08with you again.
- 16:09Or maybe if you cross them, they'll forgive you once.
- 16:11But if you cross them twice, then they're like, okay.
- 16:13Interesting.
- 16:14And so implementing these strategies is actually pretty straightforward, right?
- 16:17It's like you could reasonably write a strategy in like five lines of Python.
- 16:20Yeah.
- 16:21Absolutely.
- 16:21And that's been one of the aims of the library is to make that as simple and straightforward
- 16:27as we possibly can.
- 16:29Because it's a great way for somebody who's new to programming or new to Python or new
- 16:35to making contributions to open source projects to get involved with something and to see an
- 16:41effect very quickly.
- 16:42You can invent a strategy that's not been thought of before very easily.
- 16:47You can code it up in a few lines and you can get it into the library and get it participating
- 16:51in the tournament.
- 16:51And it has been a first contribution for many, many people to open source.
- 16:55I gave a class on repeated games one morning and that afternoon, one of my students had written
- 17:01their first open source contribution with a little bit of help, but not much.
- 17:05So, yeah.
- 17:06I think that's really great.
- 17:07You know, a lot of people are super interested in contributing to open source, but I think it
- 17:12feels super daunting because they see all the things they're like, oh, Django, I'd love
- 17:16to.
- 17:16Oh my gosh, this is a big project.
- 17:18And if I break it, oh boy, Pinterest will be mad at me or whatever, right?
- 17:23Whereas here, really at its core, to submit, to contribute a strategy, all you're doing
- 17:28is writing a relatively simple, well, it can be simple or complicated, class method.
- 17:33Just one method is kind of all you need to do.
- 17:35Yeah.
- 17:35So, you know, if people are there listening and they're like, hey, I'd love to get started
- 17:38on this.
- 17:38You've got some interesting game theory.
- 17:40Definitely check this out.
- 17:41I'll be linking to the GitHub repo in the show notes.
- 17:44That'll be awesome.
- 17:44Cool.
- 17:45And we'd love to have them.
- 17:46We look forward to seeing them.
- 17:47That's awesome.
- 17:48You guys are going to be busy with pull requests, I think.
- 17:51Thanks.
- 17:52Fantastic.
- 17:52How many strategies do you have?
- 17:54Yeah.
- 17:54How many strategies do you have so far?
- 17:55In the current release, which is 2.6, we got 184 strategies.
- 18:00Wow.
- 18:01But a lot of those are parametrized.
- 18:03So, you know, you can, for example, a random strategy, we have a strategy that acts completely
- 18:08randomly.
- 18:08You can also pass a parameter of making it random where they select to cooperate with a
- 18:13given probability.
- 18:14So, in a way, we have pretty much an infinite number of strategies.
- 18:18So, you have like a two-thirds cooperator, one-third defector-like?
- 18:22Yeah.
- 18:22And much more complicated ones as well.
- 18:24Of course.
- 18:25So, what are some of the more, not convoluted, but involved ones, I guess?
- 18:30That's a good question.
- 18:31There's several that we've implemented from the literature that try to break deadlocking
- 18:36situations.
- 18:37So, one of the weaknesses of tit-for-tat is it can get in these confect, or these cooperate-defect
- 18:43cycles with an opponent that accidentally defects, or if the tournament is noisy or something
- 18:47like that.
- 18:48And so, if you can give it a small probability that it will forgive a defection, they can
- 18:53get back to cooperating again.
- 18:54So, there's a lot of strategies that implement little things like that, that attempt to get
- 18:59the players back on track.
- 19:01I see.
- 19:02Just kind of break, because if you just go really clearly down the cooperate-defect,
- 19:06grudge, you end up in these equilibrium really quickly, right?
- 19:10And so, as you make concessions over time or take more of it into account, it can probably
- 19:15be more interesting, huh?
- 19:16I was going to say, Mark, if you want to talk about even some of the more complex ones where
- 19:20we're using neural networks and we're training these strategies using genetic algorithms and
- 19:24things like that.
- 19:25Now, that is cool.
- 19:25Sure.
- 19:26You're probably best placed to talk about those.
- 19:28Sure.
- 19:28Yeah.
- 19:29So, one of the great things about the library is that we have so many strategies already,
- 19:32and you can use these to train new strategies using typical machine learning methods.
- 19:36So, we had a couple of really interesting contributions, I guess, almost a year ago from
- 19:42Martin Jones, who's, I guess, somewhat well-known in the Python community.
- 19:47And he submitted a strategy that used a lookup table that he had trained to find the optimal
- 19:53response against all the other strategies in the library.
- 19:55And he also submitted the first one that used the neural network.
- 19:58So, we've extended that method of taking a strategy based on some kind of machine learning
- 20:03algorithm, training it against the other strategies, and then adding it back to the tournament to
- 20:09see how it does.
- 20:09And right now, those are amongst the best players in the library in terms of performance.
- 20:13Oh, wow.
- 20:13Okay.
- 20:14How interesting.
- 20:14And is it adaptive?
- 20:16Or does it somehow identify?
- 20:18Like, okay, I think that thing I'm playing against, that's a grudger.
- 20:21So, I'm going to do a grudging thing.
- 20:23That's a great question.
- 20:24So, some of the strategies that try to adapt on the fly don't always do so well.
- 20:29But what you'll see is the trained strategies typically learn things.
- 20:32Like, if you defect too many times in a row, then they'll just decide that they're going
- 20:37to give up on you.
- 20:38That you're one of these strategies that is never going to cooperate with them.
- 20:40So, they'll just defect with you for the rest of the time.
- 20:43And we've got some population dynamics based ones as well, which we can talk about a little
- 20:48more.
- 20:48But they have to learn to play against themselves and the other players.
- 20:51And they end up evolving like a handshake so they can recognize other variants of themselves,
- 20:58but exclude opponents that aren't like them.
- 21:00Really?
- 21:01Wow.
- 21:02That is so interesting.
- 21:03What's really cool is that that kind of comes out of the training.
- 21:06So, we just train them.
- 21:07And so, we're not kind of designing that handshake, but we're seeing that handshake evolve, which
- 21:13is kind of cool.
- 21:13For sure.
- 21:14Okay.
- 21:14Yeah.
- 21:14That's incredible.
- 21:15I didn't really expect that.
- 21:16Like, you know, at Google last year, they came up with those two neural networks that would
- 21:24exchange encrypted data.
- 21:26And a third one that was trying to break it, the Adam Eve, the Alice Bob and Eve one, that
- 21:31one, that basically invented a way to talk to each other to do encryption.
- 21:37And it sounds like this is kind of like that a little bit in the sense that they like know
- 21:42how to play against each other.
- 21:43I mean, I'm not saying it's necessarily the same thing, but.
- 21:45I think it's in the similar vein.
- 21:47Yeah.
- 21:47It's a result of the same kinds of reinforcement training strategies.
- 21:51Okay.
- 21:51Interesting.
- 21:52But each of our matches is typically only 200 turns long.
- 21:55So, they've only got 200 bits of information to do this.
- 21:58So, not quite in the same league as what Google are doing.
- 22:01That's right.
- 22:03And the worst thing that'll happen is they'll win a tournament.
- 22:06We're not letting them just get the computers to talk to each other without us knowing what's
- 22:09going on.
- 22:10So, we're okay.
- 22:10Yeah.
- 22:11The singularity probably won't come from these strategies.
- 22:14Who knows?
- 22:16I mean, maybe.
- 22:17But if it's ever found on GitHub by one of these other AIs, it's going to bring it back
- 22:24in and it's going to be trouble.
- 22:25I don't know.
- 22:27If we can just get society into this local minimum, we have them.
- 22:31All right.
- 22:32So, the idea is you have these strategies, which are really interesting.
- 22:35And then you kind of do like a survival technique, right?
- 22:39You have them compete against each other over and over and over, 200 times, you say?
- 22:42And then you can draw really interesting conclusions like, well, we had this even distribution at
- 22:49the beginning of each type.
- 22:50But at the end, we had way more grudgers or whatever.
- 22:53Maybe talk about that a little bit.
- 22:55Yeah.
- 22:55There are a couple of variations of tournaments that you can play.
- 22:59And some of them play these population dynamics.
- 23:02So, in various different ways, at the end of each round, your score determines the size
- 23:09of your population going into the following round.
- 23:11And at the end of it, we look to see, well, who's died out, who survived through to the
- 23:17end?
- 23:18Has one strategy dominated the final population?
- 23:21Or have we ended up in an equilibrium of three equal populations with three different strategies?
- 23:27And that's actually, if you've seen the logo for the library, that sort of multicolored
- 23:32plot, that's a plot that comes out of one of these population dynamic tournaments.
- 23:38And it's showing one or two of those strategies are surviving very nicely through to the end
- 23:43and dominating.
- 23:44And a couple of them have died out and don't have very much population left at all.
- 23:48Yeah.
- 23:49And you have really nice visualizations of the results.
- 23:51I really like those.
- 23:53So, some of the tournaments you have, you say, round robin.
- 23:55You have spatial ones and probabilistic endings.
- 23:58What are those?
- 24:00Well, as I said earlier, the first thing that we do is to pitch two players against one another
- 24:05and then they compete for a certain number of rounds.
- 24:08Well, in most of the tournaments, that number of rounds is fixed and it's the same for each
- 24:14pair that plays.
- 24:16But in the probabilistic ending, you set a probability so that in any given round, there's a probability
- 24:22that that might be the last one in this match.
- 24:25So, the length of matches between different pairs varies.
- 24:30Whereas in all the other tournaments, they're all playing for exactly the same number of rounds.
- 24:35Okay, cool.
- 24:35Have you guys ever done anything like trying to study career criminals?
- 24:39So, ones that go back to jail and back.
- 24:41So, if you lose a round, you have to like sit out a round or something.
- 24:45Only the ones that win or they somehow get released back into the population based on how long they
- 24:51were sent to jail for.
- 24:52I think you need to put a PR through.
- 24:54I was going to say, yeah.
- 24:55PR is very welcome.
- 24:57Yeah.
- 24:58We don't have that.
- 24:59But actually, the library would allow for that to be implemented because we have these structures
- 25:05for how the tournaments are in these different tournaments.
- 25:07And so, you could theoretically build a tournament that has some sort of dropping out phase or things
- 25:14like that.
- 25:15Yeah, you could do that.
- 25:16Oh, yeah.
- 25:16Sounds interesting.
- 25:17Yeah.
- 25:17And there's lots of variants of the game that have been studied in the literature where other
- 25:20than corroborate and defect, you can also like intentionally punish your opponent by taking some
- 25:25of their points away or some of their money away.
- 25:26And these are, you know, usually done with small studies of undergraduate students to see if it
- 25:31improves the equilibrium.
- 25:32And we haven't gone down that.
- 25:34It was something we've talked about before.
- 25:36And like Ben said, it would be relatively easy to add to the library.
- 25:38But I think we've had so much fun with just the regular prisoner's dilemma that we haven't
- 25:43messed with that part of it.
- 25:44Yeah, you haven't had to go out there because it's still interesting to study.
- 25:46I do have access to students.
- 25:48That's true.
- 25:49We also have a whole set of strategies that we sort of collectively refer to as the cheaters.
- 25:58They don't conform to the rules of the tournament that Axelrod originally did.
- 26:03They do all sorts of things within the code.
- 26:05So they'll try to manipulate their opponent's code.
- 26:08They'll try to manipulate the history of the scores.
- 26:12And so we allow those strategies in.
- 26:14And so there's quite an interesting little tournament that just plays them.
- 26:19And sees, well, which is the best cheating strategy?
- 26:22So who's best at writing strategies that manipulate the internals of Python and mess about with
- 26:28their opponent's class methods?
- 26:30Yeah.
- 26:30So that's really interesting.
- 26:31The normal ones, they're provided.
- 26:34I mean, everybody's provided.
- 26:35But the normal ones look at like, what did my player, my opponent do last time?
- 26:40Did they defect?
- 26:41Or did they cooperate?
- 26:42And I'll do something.
- 26:43But the sneaky ones, the insider trading ones, if you will, they say, you know what?
- 26:50I actually have a self pointer.
- 26:51And my self pointer has the opponent.
- 26:53My opponent has a method that's called like respond.
- 26:58And you can just overwrite that method to say, return C.
- 27:02Exactly.
- 27:03Exactly.
- 27:05And it was a bit of a headache at one point, because as the library matured and became quite
- 27:12a good research tool, well, a very good research tool.
- 27:14We had these cheater strategies that were kind of all good fun and games at the start.
- 27:19But I think we made a good decision earlier on to bring in this classification of strategies.
- 27:25So you can't stumble on the cheaters by accident.
- 27:27But if you want to go get them, you can.
- 27:29And at the same time, there's loads of other things that we can classify strategies on.
- 27:33So for example, how long is their memory?
- 27:36Do they only look at what they did in the previous round?
- 27:39Or do they look all the way back to the beginning of the game?
- 27:40And you can kind of go and get strategies based on that.
- 27:42Oh, interesting.
- 27:43So basically, they provided a list of opponent responses.
- 27:47And you could say, like, always, you know, trim that list to like 10 or 5 or 1 types of
- 27:52responses, right?
- 27:53Only consider strategies that only look at, you know, that much memory, so to speak.
- 27:57Okay.
- 27:58Because that's another interesting thing.
- 27:59Talking about these sophisticated strategies that make use of neural nets and stuff.
- 28:02There's a lot of talk in the literature, in the research literature, about whether or not
- 28:06memory matters, you know?
- 28:07And so this particular paper that made a lot of noise recently, well, in 2012, was it?
- 28:12But they were like, actually, you know, any strategy can be beaten by a strategy that only
- 28:16has very little memory.
- 28:17And we're kind of seeing with the vast amount of strategies we've got that we can train strategies
- 28:22that can adapt and can learn and can be very powerful and very sophisticated.
- 28:27I see.
- 28:28So maybe like if you're going to write a strategy yourself where it's procedural and you write
- 28:33the code, like maybe it doesn't make sense to remember 200 steps and try to like, how
- 28:37do I fit that in?
- 28:38But if you give it to a deep learning neural network and go, here, this is what they did.
- 28:42What does that mean?
- 28:43Maybe it can actually find within that the patterns that we don't see.
- 28:47That's right.
- 28:48Mark wrote a paper on that with the coolest title ever.
- 28:50It's called The Art of War.
- 28:51So you could...
- 28:52That's awesome.
- 28:54We came up with a strategy that used a lot of memory that was very effective.
- 28:58So I think there's this, there's been this kind of longstanding folk idea in the game
- 29:02theory community that complicated strategies are more trouble than they're worth.
- 29:06And that's because in the beginning, Tit for Tat was winning all these tournaments.
- 29:09And it's a really simple strategy that only looks at their previous round.
- 29:12And people tried to do all these complicated heuristics and stuff like that.
- 29:15And it just didn't work because the other strategies were like, I don't know what this
- 29:17other guy's doing, but it's complicated.
- 29:20So I'm just going to defect against him and call it good.
- 29:22I was just a human.
- 29:24Come on.
- 29:25I can't, I can't be.
- 29:26Right.
- 29:26Right.
- 29:27But yeah, we've definitely seen some success with these longer, these strategies that can
- 29:31be trained to do something sophisticated.
- 29:33Yeah.
- 29:33And how, how intense are the AIs that, that you're putting in?
- 29:37Like, is this deep learning?
- 29:38Is this just a neural network?
- 29:40Does it involve things like TensorFlow and like GPUs or is it, is it pretty simple as far
- 29:46as those go?
- 29:46So the way we train all of them right now, I did play with using TensorFlow, but some of
- 29:51the other strategies, the only way we can really do it is with an evolutionary algorithm.
- 29:54Just mutate and see if it's good.
- 29:56And so all the strategies we train now use that method, even the neural network and the
- 30:01neural networks we use are pretty simple.
- 30:03They're, they're basically one layer deep.
- 30:05Can you give them access to, or have you given them access to previous tournaments and the
- 30:09whole outcome and letting them look at that or like letting them see more than the tournament
- 30:14that they're in?
- 30:15I haven't currently trained one.
- 30:16So I did train a neural network that tries to predict the next move.
- 30:19And I let it look at a lot of games for that, but then I had trouble turning that into a
- 30:23real strategy.
- 30:23And it turns out it was better just to take a neural network and directly evolve the parameters
- 30:30that do well on a tournament.
- 30:31And in that case, it doesn't actually look at the outcomes of third party games.
- 30:36I see.
- 30:36All right.
- 30:37You guys talk about a thing called Moran processes for population dynamics.
- 30:41What's the, what's the story there?
- 30:43What's that about?
- 30:44I'm not familiar with that.
- 30:45Sure.
- 30:45So this is a, I got the classic example of a population dynamic.
- 30:49You basically have a population of, in our case, in different strategies.
- 30:52But if you were thinking like animals, it would be the, you'd have a bunch of animals that
- 30:57have their different sizes, or they have some different characteristic, different eye color
- 31:01or something like that.
- 31:01And then they all interact with each other and they accrue fitness points.
- 31:06In this case, they're playing the prisoner's dilemma and whatever their score is, is their
- 31:10fitness.
- 31:10And then you select one of them to reproduce proportional to its fitness or score.
- 31:16And you randomly select one to, to die of natural causes, let's say.
- 31:20And so one step at a time, the population evolves as one strategy does better than the other
- 31:28ones.
- 31:28I mean, it depends on the intrinsics of the strategies themselves and also the makeup of
- 31:33their opponents.
- 31:33So if they play well with certain opponents, then they're better off and a population has
- 31:36a lot of those kinds of opponents.
- 31:38I see.
- 31:38So it's underlying dynamics that actually decide how the population of one type of thing,
- 31:43like the grudgers or whatever, grow or shrink over time.
- 31:45Yeah, exactly.
- 31:46And so the questions around that are, is a population stable to invasion by a mutant
- 31:50type, a different type?
- 31:51Or is a strategy good at taking over a population of another type?
- 31:55Oh, interesting.
- 31:55Okay.
- 31:56So yeah, something that sounds like it could be a cool variation on tournaments, maybe you've
- 32:00done this, is what if you introduce like an invasive species type?
- 32:07Like you run the tournament for like three fourths of the way through, and then you introduce
- 32:10some other strategy that wasn't initially there after like others have been killed off.
- 32:15Have you tried this?
- 32:15Oh, there's your second PR, I think.
- 32:17We're doing well here.
- 32:19Yeah.
- 32:20Yeah.
- 32:20Yeah.
- 32:20I think it would be cool because, because a lot of them, like if you look at the graphs,
- 32:24it's super hard to talk about pictures on the audio.
- 32:26But if you look at some of the diagrams, and I'll link to your presentation at PyCon, you'll
- 32:32see that in the beginning, there'll be all these different types, and some of them will
- 32:35die out after a while.
- 32:37And maybe the strategies that won when they were around are not the same strategies that
- 32:41win if some new type comes, right?
- 32:42Yeah.
- 32:42Okay.
- 32:43Like if you throw a cooperator into a room full of defectors, it won't do very well, because
- 32:49they'll rip it apart, basically.
- 32:51Exactly.
- 32:53Exactly.
- 32:54Okay.
- 32:55Quite interesting.
- 32:56Yeah.
- 32:57All right.
- 32:57So what did you use to visualize those results?
- 33:00Those graphs are really nice.
- 33:01Is that Matplotlib or something else?
- 33:03That's all Matplotlib.
- 33:04Matplotlib.
- 33:04Yeah, yeah.
- 33:04That was at the start, we made it so that you could easily get various outputs of the
- 33:09library.
- 33:10It's all just done in Matplotlib.
- 33:11Okay.
- 33:11Yeah.
- 33:12And there's two sub-libraries in the repository, one that does something called fingerprinting,
- 33:16which is this idea from the literature that gives you an image that corresponds to a strategy,
- 33:21which those are kind of neat to look at.
- 33:23And then there's another one that's been around for a while that looks at how often each strategy
- 33:29cooperates against each different given opponent.
- 33:31So we have a lot of other visualizations and they're mostly with Matplotlib as well, with
- 33:35the occasional Seaborn, I think, here and there.
- 33:37Okay.
- 33:37At the start, out of the three of us, I think it's fair to say I was the keenest to keep
- 33:42the library very light on dependencies.
- 33:45And so I was kind of a roadblock for quite a while with Mark and Owen more sensibly saying,
- 33:51no, let's use all these awesome libraries to make the code better.
- 33:54And I was like, no, no, no.
- 33:55Let's pure Python, pure Python.
- 33:57And so Matplotlib was introduced, but it had this really nasty little fix so that you could
- 34:03still install the library without it.
- 34:04And then eventually I understood what was the way to do things.
- 34:09And so a lot of code got a lot neater when we started making use of all the great libraries.
- 34:13That's nice.
- 34:14The fingerprinting is another good little story.
- 34:17I put an issue on the library.
- 34:20It must be about 12 months back now.
- 34:22One of the early ones, yeah.
- 34:24Just a bright little idea, I thought, which was that we were starting to get people contributing
- 34:30strategies other than the three of us.
- 34:32And I was starting to find it tricky to work out, is this strategy the same as one that we've
- 34:39already got?
- 34:40And this is back in the days when I think we only had about 30 or 40 strategies.
- 34:44And I was starting to find it tricky then because, of course, it's not enough simply to look
- 34:50at the code because the same decisions can be coded in all sorts of different ways.
- 34:57So it struck me that we could do with a better way of trying to decide whether a given strategy
- 35:05was at least similar to one that we'd already seen.
- 35:09And I naively typed that up into an issue on the repository and said something like, maybe
- 35:15we should just find a handful of strategies that we play them against and we can do something
- 35:20clever mathematically to work out how similar they look, thinking that my friends, the mathematicians
- 35:26would go, yeah, that's a great idea.
- 35:27I'll do that this afternoon.
- 35:30Oh, no, they say this is a significant mathematical challenge.
- 35:34And 12 months later, here we are with some poor student of Vince's doing it as his final
- 35:40year project.
- 35:40The interesting thing is that that poor student is actually Owen's son.
- 35:46He's now doing his final year project with me.
- 35:49And so he's implemented this graphical approach from the literature, which has its strengths
- 35:54and weaknesses.
- 35:55But actually, I think this might be news to both Mark and Owen, as well as all the listeners,
- 35:59is he's just been working on a cleverer way of doing it, building a statistical model that
- 36:05will spit out if two strategies are different or not.
- 36:07So yeah, hopefully we'll be able to talk about that a bit more at some point.
- 36:10Well, I think that's really funny that you just throw that out there.
- 36:13Like, ah, you guys could just like compare strings or something and see.
- 36:16No, no, this is actually a lot of work.
- 36:19But on the other hand, it's super cool that something constructive as a project is coming
- 36:25out of it, right?
- 36:25Like, that's interesting.
- 36:27And things have worked the other way, too, where I've gone like, oh, we got to do this
- 36:31thing.
- 36:32It's probably going to be really, really hard.
- 36:33And then Owen and Mark are going, oh, you just need to use a class, something, something,
- 36:38something.
- 36:38And like, it's two lines of Python.
- 36:39I'm like, oh, okay, cool.
- 36:40I can actually do that in a less comprehension.
- 36:42We're good.
- 36:44Have you thought of involving like deep learning and the classification of similarities?
- 36:49Like, that would be interesting.
- 36:50I did write a blog post a couple of years ago where I derived a bunch of features of the
- 36:54strategies and the tournaments and did a little bit with it.
- 36:57But that was back right when we had just about 100 strategies and we weren't calculating as
- 37:01many things.
- 37:01So that's definitely worth a revisit, see if we can do more.
- 37:04That's actually kind of, that was the plan with this poor final year student.
- 37:08But actually, we've kind of got some really promising results using rather naive statistical
- 37:14models.
- 37:14So we need to look into that a bit more, but it doesn't look like we need to be too
- 37:18sophisticated.
- 37:19Again, because of the way the tournament is now and the, sorry, the way the library is
- 37:23now, it can just create so much data for us, which is a real strength.
- 37:27Oh, that's excellent.
- 37:28I think this is a real service, not just for Owen's son and your student in this particular
- 37:33case, but I think that it's, this kind of stuff is really valuable to students who are
- 37:39coming out of school and they want to get a job, right?
- 37:42If they come in and say, well, what do you know about programming?
- 37:44Would you like to see my project on GitHub and maybe the paper that was published built
- 37:49off of it?
- 37:50And here's my optimizations I've done.
- 37:52And like, if you can provide that to students, then they're in such a better place when they
- 37:56go out and say, Hey, I want a job.
- 37:58We actually had a student turn up today or yesterday.
- 38:00I forget.
- 38:01And she, you asked, didn't you, Owen?
- 38:04Like, how did everyone find this library?
- 38:05Because we've had quite a few people now.
- 38:06And she said, Oh, actually, as part of my course, I have to contribute to an open source project.
- 38:12And, you know, she'd found the actual project and seen the documentation and the community.
- 38:16And she's decided to choose us, which is great.
- 38:18Oh, wow.
- 38:19That's really cool.
- 38:19Think of how the world is going to be after 10 years of this kind of stuff.
- 38:23Like all the students have to contribute to open source and they have to somehow be really
- 38:26aware of this.
- 38:27And they're totally familiar with, that's your pull request.
- 38:29They know what that means.
- 38:30Like that's just, you know, it's already got so much momentum, but I could see a world
- 38:35where it's like, we'd look back at these as quaint days when open source was small.
- 38:40Another good kind of side to this project is in terms of academic research.
- 38:44So going back to the fact that Axelrod's original tournaments can't really be reproduced and there's
- 38:48loads of papers that can't be reproduced.
- 38:49That's like a problem in modern research where so much software is needed and written, but
- 38:55it's not necessarily written in a sustainable way.
- 38:58And so the Axelrod project is a really good example of maybe I'm a bit biased, obviously,
- 39:02but I'd say best practice in terms of, you know, our code isn't only written and documented
- 39:06well, but it's extremely well tested and it's constantly being refactored and improved.
- 39:11And it's all, you know, a wonderful example of how you should be doing research.
- 39:14Yeah.
- 39:14You guys have a nice read the docs and all sorts of stuff, right?
- 39:17But just to go into Owen's point, it's pretty rare for academic code to be even sufficiently
- 39:21documented to use it again, let alone enhance it or anything like that.
- 39:25It's just because the journals don't require it a lot of times when you publish it.
- 39:29And two, I think the way we have our test suite, we really try to test every stated behavior of
- 39:35every strategy so that we know that it is as close to the real deal as we can get it.
- 39:40That is really awesome.
- 39:41And I think it's great.
- 39:42And you have sort of the case study in this example of the way not to do it and the way
- 39:47to do it all wrapped into one, right?
- 39:50With the actual rod original tournaments and people are like, we don't even know if we
- 39:53can reproduce these strategies.
- 39:54And yet there's, there are papers and stuff written on it, right?
- 39:57Absolutely.
- 39:57And so you're like, well, how do you validate that science, right?
- 40:00That's been a real eye opener to me as somebody that's, that's got no academic background whatsoever
- 40:05since the day I graduated and vowed never to sit an exam again in my life.
- 40:10To come back into it, albeit on the fringes, however many years later, and find that there
- 40:19are papers and papers and papers written on the back of software that isn't accessible.
- 40:24And I look at that and say, well, how is that reproducible?
- 40:27How is that scientific?
- 40:28And it's been, it's been a real shock to me to find that we in this little project have
- 40:35so much of a struggle to try and reproduce other people's results.
- 40:38Yeah.
- 40:38But I think what you guys are doing, I mean, obviously it's open source.
- 40:41It's got version control all the way through.
- 40:43So somebody can go back, well, this paper was written on this version.
- 40:46It's not just, I still have the library, but I have exactly the same code.
- 40:50I think that's interesting.
- 40:51You know, I was talking to Kyle Cranmer from the Large Hadron Collider, and he was talking
- 40:56about how this is the problem in particle physics as well, just like reproducible science in general.
- 41:01And they do interesting things like have kind of an escrow service to hold the code tied to
- 41:06the paper and stuff like that.
- 41:08So I think, I think there's people trying different things from different angles, but yeah, very nice
- 41:13work.
- 41:13So what's the computational story here?
- 41:17You have 183 strategies, 200 rounds.
- 41:21They all fight with each other in certain ways.
- 41:23Like how long does it take to run a typical tournament?
- 41:26Is it pretty quick or is this like, you got to go have lunch?
- 41:30Well, the full tournament on all the strategies takes about an hour on a typical machine.
- 41:35So does that fit with that?
- 41:37Vince has some nice 16 core machines that can really chew through it.
- 41:40Yeah.
- 41:40So on that, it's still just under an hour for the full noisy tournament, which is the
- 41:45one that takes the longest amount of time.
- 41:46Because that's another thing that's inbuilt in the library.
- 41:48It's completely paralyzed.
- 41:50So you can play all these matches in parallel and the library takes care of that for you.
- 41:53So you can use up as many cores as you can get.
- 41:55Okay.
- 41:55That's cool.
- 41:56And some of the classifications, if the strategies are deterministic, then we don't have to
- 42:00repeat those matches.
- 42:00But if the tournament's noisy or the strategies are stochastic, then we have to repeat those
- 42:06more times.
- 42:06So depending on exactly what strategies you choose, it can be extremely fast if they're
- 42:10all deterministic or it can take a lot more time if it's like a noisy tournament.
- 42:15Okay.
- 42:15So have you guys tried to do any fancy tricks to make it faster or something like that?
- 42:20You talked about figuring out if it's deterministic and then going, okay, it already knows
- 42:26the answer to this.
- 42:26I would want to very cautiously say that I think we're already doing a fair few of these
- 42:32tricks, you know, like the parallelization, like vectorizing things where we can.
- 42:36But again, if anyone wants to take a look and make it faster.
- 42:39Writing the multiprocessing is several days of my life I'll never get back and I don't
- 42:43wish to repeat.
- 42:44Yeah.
- 42:45And as someone else who worked on that part of it, wow, yes.
- 42:49Yeah.
- 42:50I think we all kind of broke our knuckles on that for a bit.
- 42:53Yeah, that was...
- 42:53Yeah, that sounds really cool.
- 42:55Of course you want it to go as fast as possible, right?
- 42:57Like, you know, maybe somehow bringing some NumPy scipy into it.
- 43:01I don't really know or who knows.
- 43:04But it seems like an interesting computational challenge in its own right.
- 43:07Yeah.
- 43:08And you guys have battled it some, it sounds like.
- 43:10Yeah.
- 43:10And part of it is memory overhead as well.
- 43:13If you're batching out the matches, you can do them in parallel.
- 43:16But if you do too many of them, then you exhaust your memory, you hit swap, and then you're
- 43:21done for, you know?
- 43:22Yeah.
- 43:23That was a big bit of work when all of a sudden we realized that like we were using more than
- 43:2716 gigs of RAM and we kind of did it all.
- 43:29So now it's basically got no memory fingerprint anymore.
- 43:32But we do it all to file.
- 43:34But I'd forgotten about that.
- 43:35Yeah.
- 43:35Yeah.
- 43:36Yeah.
- 43:38It sounds just like an interesting algorithmic problem.
- 43:41And then, you know, you've got the known structure to deal with and stuff.
- 43:46But then people are throwing these strategies at you that you have no idea on how they're
- 43:49going to behave.
- 43:50And so that's like an interesting twist.
- 43:51It just, it sounds like a fun problem to me.
- 43:53Yeah.
- 43:53We do label the strategies too if they have a long run time.
- 43:55So some of them take 10 times, 100 times longer in whatever computations they do than
- 44:00say tit for tat.
- 44:01So that's another thing that we've studied, optimizing specific strategies.
- 44:05There's a couple of really cool strategies in the library.
- 44:07They're called meta strategies.
- 44:08And they basically take a large group of the other strategies in the library, maybe all
- 44:14of them, and then take the consensus vote or something like that.
- 44:17So they, by definition, are 100 times slower than the other ones.
- 44:21Yeah.
- 44:22Because they just keep rerunning.
- 44:23That's a pretty interesting idea.
- 44:24It's almost like the politician thing.
- 44:27You see what people are asking or what they want and just like, I'm just going to do that.
- 44:31Well, however the wind is blowing, that's how we're going to cooperate here or whatever.
- 44:36Yeah.
- 44:37So are there interesting combinations that work well?
- 44:40Have you tried that?
- 44:41Instead of running all of them, go like, I think this set of them or that set, like this
- 44:46mixture of like, I'll ask these 10 and see what I get.
- 44:50I have played with it a lot.
- 44:52So that was one of the best strategies in the early days, these meta strategies.
- 44:55And of course, you know, if you give them like the top five other strategies in the library,
- 44:59then it does well.
- 45:00But one change we made recently is rather than take the best performer of all the strategies
- 45:06in its set, if you randomly take one of the top 10 performers, it actually works better.
- 45:11And if you always go after that top one, which is sort of a weird quirk of like an ensemble
- 45:15machine learning method.
- 45:16Yeah.
- 45:16Yeah.
- 45:16Very interesting.
- 45:17You can study a lot of cool stuff with us.
- 45:20It sounds like.
- 45:20So maybe give us some stories like where this has been used.
- 45:25Like, obviously, if any of us or any two of us, I should say, get like captured by the police
- 45:32and charged with a crime, we'll know what to do.
- 45:35We'll have a more informed view on what to do.
- 45:38But, you know, it's not just for prisoners, right?
- 45:40It applies to other things as well.
- 45:42Yeah.
- 45:42And Owen added a pretty interesting strategy not that long ago where you can play as a
- 45:46human.
- 45:47So you can pick the strategy you want to play against and you can submit C or D and practice
- 45:51your one-on-one skills versus these strategies.
- 45:53Nice.
- 45:55That could have been an Atari game when it first came out.
- 45:58One of the kind of applications of this study is to understand the evolution of social norms.
- 46:06So, you know, like as Mark said at the beginning, you know, why when you look around, are we cooperative?
- 46:11And then that kind of steps onto other fields of evolutionary game theory that are then applied
- 46:18in like mathematical oncology and things like that.
- 46:21So these ideas are all interconnected and have wide-ranging applications.
- 46:25Yeah.
- 46:26Okay.
- 46:26Cool.
- 46:26You said that there's some applications in mathematical oncology for cancer.
- 46:31Yeah.
- 46:32What's that?
- 46:33That's kind of not immediately looking at the prison's dilemma, but the same ideas kind
- 46:38of transpire that you can see the spread of a tumor inside a health body in the same way
- 46:46that you can think of introducing a particular strategy into another population.
- 46:51And so things like Moran processes and evolutionary dynamics and population dynamics have been used
- 46:57to understand, yeah, the spread of cancer.
- 46:59And so mathematical oncology.
- 47:00Yeah.
- 47:01You can kind of think of cancer as a cooperator that has switched strategies to a defector
- 47:06and is now trying to take over.
- 47:08And so can it invade that population or not?
- 47:11Oh, wow.
- 47:12Okay.
- 47:12It's really interesting when these things make connections to somewhere where they're totally
- 47:17unexpected, right?
- 47:18Yeah.
- 47:19Like people working, you know, I'm sure Nash wasn't thinking about cancer when he worked on
- 47:22his game theory ideas.
- 47:24Nash got his Nobel Prize in economics, right?
- 47:26And the ideas that he was thinking about when he first wrote his paper and his thesis, they
- 47:32kind of just rolled really.
- 47:34And he didn't really see it coming.
- 47:35Well, I'll say that.
- 47:36I don't know that for sure.
- 47:38But it certainly wasn't what he was thinking of when he was doing the work.
- 47:40Yeah.
- 47:40Yeah.
- 47:41Yeah.
- 47:41Very interesting.
- 47:42Yeah.
- 47:42And it's still using economics now.
- 47:43So there's this idea, this like first approximation that everyone does what's best for them.
- 47:48Like they take all the available information and they say, it's best for me to invest in
- 47:51this thing.
- 47:52And that's not what most people do.
- 47:53Most people just copy someone else's strategy or someone else's advice.
- 47:57So it's more of an evolutionary process than rational process that we would think of it.
- 48:01Sure.
- 48:02Does it appear in politics or is politics too slow of a process, right?
- 48:07Like every four years, every six years, like is that enough for people to see these strategies
- 48:13and evolve?
- 48:13Or what do you think?
- 48:14Well, I know there's papers that are written in political science that use this kind of stuff,
- 48:17but I don't know how well applied to the real world they are.
- 48:20They might just be theoretical.
- 48:21I know there were lots of blog posts written about game theory and Brexit.
- 48:26So some combination.
- 48:28Yeah.
- 48:29I was just saying, well, I was thinking of Brexit.
- 48:30I was thinking of the US presidential election.
- 48:32Like both of these are unexpected.
- 48:35And I'm wondering if game theory has interesting things to say about them.
- 48:38Don't blame us.
- 48:39I'm not blaming you guys.
- 48:40I was actually in London when the Brexit vote happened.
- 48:43And it was very interesting to walk the streets of London the day after.
- 48:46It's quite something.
- 48:47A really, really neat project.
- 48:49And I love how it applies to all these different things.
- 48:52And I don't know if Mark and Vince have noticed, but whilst we've been chatting on our Gitter
- 48:57channel, we've now had somebody new come on saying,
- 49:00that they're a student.
- 49:01They're on a course where they're required to contribute to an OSS project.
- 49:05And they like the look of our project and they'd like to know how to get involved.
- 49:10So that's awesome.
- 49:11I could tell you what to say.
- 49:12I didn't think this was a live broadcast, but now I'm beginning to.
- 49:17Gosh, yeah.
- 49:18Talk Python works fast.
- 49:19Yeah.
- 49:20Well, maybe it's just someone's hacked into my computer.
- 49:22So what you need to tell them.
- 49:26I think that's as much as it's on the one side of where the library is gone.
- 49:30And it's a really sophisticated, rich research tool that has various applications and things.
- 49:36But one of the other things that we've kind of really been careful to is sometimes at the
- 49:40cost of efficiency, we have prioritized readability and entry of newcomers, not only to Python,
- 49:47but the programming.
- 49:48And I think that's something that we're all pretty proud of, that the library is a good place for newcomers.
- 49:53In fact, at one point, the winning strategy, it's no longer the case, but at one point,
- 49:59the winning strategy was written by a particular high schooler in the UK, which is actually Owen's other son.
- 50:06So cool.
- 50:08There's a lot of connections to Owen's children here.
- 50:11How interesting.
- 50:12They get you into all sorts of trouble.
- 50:13So, Owen, here's what you need to tell that person and get her.
- 50:17There's this simple problem about fingerprinting, and they should be able to knock that out right away to get started.
- 50:22All right.
- 50:25I think maybe we're kind of getting low on time here for talking about the project.
- 50:29There's one other thing I wanted to ask you guys about here.
- 50:33And you said that in the notes, you'd put down something for a thing called ugly fruitcake.
- 50:38What is ugly fruitcake?
- 50:40That's my son's username on Twitter.
- 50:44Awesome.
- 50:47Well done, Mr. Ugly Fruitcake.
- 50:50No, that's awesome.
- 50:52Excellent.
- 50:54Excellent.
- 50:55Okay.
- 50:55So I guess we'll kind of have to leave it there.
- 50:58We're getting low on time before we're talking about it.
- 51:00But it's been really, really fun to talk about.
- 51:02Let's talk two things really quick before we drop this, I suppose.
- 51:06I still want to ask you.
- 51:06One, what's the Python 3 versus Python 2 story?
- 51:09Like, what support is there for each version?
- 51:12So for a long time, we were supporting both.
- 51:14And 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:21Was that on the 1st of December last year?
- 51:23I seem to remember.
- 51:23And that's just allowed us to clean up our code base so much and pull people away from legacy Python.
- 51:31So yeah, we're using...
- 51:33That's awesome.
- 51:33I think that's a really great move.
- 51:34And also, you were talking about the readability and the simplicity.
- 51:37Like, as a newcomer to Python, you're often, like, hit in the face with this dichotomy.
- 51:42And if you can avoid that, that's really nice.
- 51:44And even as not a newcomer, it was still challenging sometimes.
- 51:47We've gotten into weird cases where iterators and generators were interacting across the different versions.
- 51:53Right, right.
- 51:54Yeah.
- 51:54Or just mistakes because of division.
- 51:59Yeah, absolutely.
- 51:59And then also, Jaxelrod, am I saying that correctly?
- 52:03Yeah.
- 52:03What is Jaxelrod?
- 52:04Oh, Django Axelrod.
- 52:05That's a longer-term attempt, really, to build a web app on top of this library.
- 52:12So instead of installing it yourself and trying to set up tournaments on your own machine,
- 52:19the 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:26and put a web front end on it, and in that front end, you could define the tournaments that you want,
- 52:31submit them to the server, it would run them, and then spew the results back at you
- 52:36for you to get out and do some analysis with.
- 52:38That's a project that we've kicked off, and the reason for the name purely is because we're using Django
- 52:44and the Django REST framework to try to do it at the moment.
- 52:46But it's in fairly early stages at the moment.
- 52:49So again, if anybody listening fancies getting involved, it would be an excellent area to get into.
- 52:54All right. You want to do some web work and turn interested in game theory?
- 52:57Here's your chance, right?
- 52:58Yeah, absolutely.
- 52:59It's very cool.
- 52:59Okay, nice. Is that publicly available or just something you guys have?
- 53:03No, no, no. It's another one of the repositories on GitHub under the actual Python organization.
- 53:08All right. Awesome.
- 53:09The organization GitHub profile has not only the library, but it has lots of really interesting collection of notebooks,
- 53:15collection of visualizations, the fingerprints, lots of interesting repositories there,
- 53:19as well as Jack Solrod and this rest of the way.
- 53:21Okay, excellent. Yeah, I'll definitely link to those as well. That's great.
- 53:24All right, guys, it's been super interesting. I really enjoyed our conversation.
- 53:28But before I let you go, quick round of questions.
- 53:31Owen, if you're going to write some Python code, where do you open up?
- 53:34I'm a sublime text man.
- 53:36And you said that you like the Anaconda plug-in, right?
- 53:38I do. It sits there and tells me where I've gone wrong. Shows me all my mistakes, yeah.
- 53:44You like people to yell at you, huh?
- 53:45As long as it does it quietly so I can ignore it when I feel like it, that's fine.
- 53:51Yeah, no, I think things like that that really give you that extra insight are super, super valuable.
- 53:56So, cool. Mark, how about yourself?
- 53:58So, I usually use PyCharm lately. I started using it about a year ago, and I really liked it.
- 54:02Before that, I just used kind of a bare-bones text editor for the most part.
- 54:07Okay, nice. And you probably use a lot of Jupyter, like, notebooks and stuff as well at work.
- 54:11Yeah, in general. I also teach a data science class that's based on Jupyter notebooks, so I'm really comfortable.
- 54:17Yeah, I like Jupyter a lot, actually.
- 54:19Yeah, it's pretty neat. It's definitely got a lot of momentum.
- 54:21Vince?
- 54:22I also use Jupyter a bunch, but my editor's done.
- 54:25Okay, awesome.
- 54:25And PyPI package, we just passed over 100,000 PyPI packages, which I think is...
- 54:32Yay!
- 54:32That's awesome.
- 54:33Yeah, that's so cool.
- 54:36So, how about, like, the favorite ones? Like, same order. Owen, how about you?
- 54:40I think my favorite at the moment has got to be Conch, the shell, the Python shell.
- 54:45So, 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:54It's a thing of beauty.
- 54:55That is beautiful. And that's X-O-N-S-H, Conch.
- 54:59It is.
- 54:59It's very cool, yeah. Mark?
- 55:00I think Request is my favorite. It's so easy if you're doing any kind of, like, web scraping or anything like that.
- 55:06I like a lot of the different ones on there. And, of course, Axelrod has got to be my favorite one.
- 55:11Yeah, why not throw that out there? For sure, for sure. And Vince?
- 55:16I 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:22It's a library for simulating queuing processes, but I think my favorite has to be TQDM.
- 55:28It'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:37Oh, that is cool.
- 55:38Yeah, 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:45I'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:50This is going to take a couple of years. I've got to change something.
- 55:52Exactly. Fabulous.
- 55:54Okay, great recommendations, guys. Thanks. And final call to action, people should get started with Axelrod?
- 56:00Yeah, come on over. Come check us out in our Gitter room and just say hi and submit a strategy or anything else.
- 56:06But yeah, we really welcome contributors.
- 56:08Yeah, I can say look at the code. It looks definitely easy to jump into, especially if you want to do the strategies.
- 56:13And 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:21For sure. Absolutely.
- 56:23All right, guys. Well, this has been a great chatting with you. Thanks for being on the show.
- 56:26Thank you so much.
- 56:27Thanks for having us. Thank you.
- 56:28Yeah, it's been a pleasure. Thank you.
- 56:29Yes, it has. Bye.
- 56:33This has been another episode of Talk Python To Me.
- 56:35Today's guests have been Vince Knight, Mark Harper, and Owen Campbell.
- 56:40And this episode has been sponsored by Talk Python Training.
- 56:44Check out all the courses at training.talkpython.fm.
- 56:47Be sure to subscribe to the show.
- 56:49Open your favorite podcatcher and search for Python.
- 56:51We should be right at the top.
- 56:53You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 57:02Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 57:07Corey just recently started selling his tracks on iTunes, so I recommend you check it out at talkpython.fm/music.
- 57:14You can browse his tracks he has for sale on iTunes and listen to the full-length version of the theme song.
- 57:19This is your host, Michael Kennedy.
- 57:21Thanks so much for listening.
- 57:23I really appreciate it.
- 57:24Smix, let's get out of here.
- 57:44We'll see you next time.
- 57:48Thank you.