WEBVTT 00:00:00.000 --> 00:00:04.160 - Everyone out there on YouTube, hello, Vince. 00:00:04.160 --> 00:00:05.000 Hey, Garant. 00:00:05.000 --> 00:00:06.880 - Hi. 00:00:06.880 --> 00:00:08.240 - Hi. 00:00:08.240 --> 00:00:10.360 - It's good to have you here on YouTube 00:00:10.360 --> 00:00:12.680 and the podcast in just a moment. 00:00:12.680 --> 00:00:14.360 Make sure you're patient as we're getting started. 00:00:14.360 --> 00:00:16.240 I know some of you were waiting for the live stream to start 00:00:16.240 --> 00:00:19.480 so very nice to have you here. 00:00:19.480 --> 00:00:23.280 Now, let's kick this off, guys. 00:00:23.280 --> 00:00:25.400 - Thanks to anyone who's here. 00:00:25.400 --> 00:00:26.240 - Yeah, thanks for being here 00:00:26.240 --> 00:00:28.160 and if you have any thoughts or questions, 00:00:28.160 --> 00:00:29.440 please put them in the live chat 00:00:29.440 --> 00:00:31.560 if you're here watching live. 00:00:31.560 --> 00:00:33.840 Vince Garant, welcome to Talk Python to Me. 00:00:33.840 --> 00:00:35.520 - Thanks, Michael. 00:00:35.520 --> 00:00:36.440 Thank you very much for having us. 00:00:36.440 --> 00:00:37.280 Thank you. 00:00:37.280 --> 00:00:38.100 - Yeah, thanks. 00:00:38.100 --> 00:00:38.940 Nice to be here. 00:00:38.940 --> 00:00:40.520 - Yeah, it's great to have you. 00:00:40.520 --> 00:00:43.200 Vince, I guess it's welcome back for you, right? 00:00:43.200 --> 00:00:46.280 - Yeah, I was on the show a while ago 00:00:46.280 --> 00:00:49.960 and I'm a big listener, love the show. 00:00:49.960 --> 00:00:51.660 Yeah, I came here a long time ago 00:00:51.660 --> 00:00:55.600 to discuss one of the game theoretic libraries I work on. 00:00:55.600 --> 00:00:58.120 So yeah, thanks for having me again. 00:00:58.120 --> 00:00:58.960 - Yeah, you bet. 00:00:58.960 --> 00:01:00.440 I love game theory, it's amazing. 00:01:00.440 --> 00:01:02.640 We'll touch on that a little bit. 00:01:02.640 --> 00:01:05.680 We're gonna do kind of a survey 00:01:05.680 --> 00:01:09.400 of a bunch of different areas of applied math 00:01:09.400 --> 00:01:12.080 and how Python and compare that 00:01:12.080 --> 00:01:14.320 with how R might solve those problems. 00:01:14.320 --> 00:01:15.720 Some of the libraries involved, 00:01:15.720 --> 00:01:17.120 some of the techniques involved. 00:01:17.120 --> 00:01:19.480 So lots of fun things. 00:01:19.480 --> 00:01:22.560 I'm looking forward to diving into them with you. 00:01:22.560 --> 00:01:23.720 - Awesome, awesome. 00:01:23.720 --> 00:01:26.880 - But before we do, 00:01:26.880 --> 00:01:28.680 maybe we'll kick it off with Garen. 00:01:28.680 --> 00:01:31.280 You're new, tell people quickly about how you got 00:01:31.280 --> 00:01:34.160 into programming, Python, math. 00:01:34.160 --> 00:01:35.920 How'd you end up here on this show? 00:01:35.920 --> 00:01:40.360 - So I'm a lecturer at Cardiff University 00:01:40.360 --> 00:01:42.360 in the School of Mathematics. 00:01:42.360 --> 00:01:45.900 So I learned to program while I was doing my PhD. 00:01:45.900 --> 00:01:49.640 And Vince here was actually my PhD supervisor. 00:01:49.640 --> 00:01:52.240 So I essentially learned programming 00:01:52.240 --> 00:01:54.240 from Vince during that time. 00:01:54.240 --> 00:01:55.080 - Nice. 00:01:56.200 --> 00:02:01.200 Yeah, and I think during my PhD, I sort of realized 00:02:01.200 --> 00:02:06.660 or I learned that everything that we'd been able to learn 00:02:06.660 --> 00:02:09.540 during my like masters and stuff, 00:02:09.540 --> 00:02:14.220 it was all completely doable in open source software. 00:02:14.220 --> 00:02:18.140 And that's kind of where I focused my PhD on then. 00:02:18.140 --> 00:02:22.020 I sort of, one of my main projects during my PhD 00:02:22.020 --> 00:02:25.620 was building a library to be able to do some of this stuff. 00:02:25.620 --> 00:02:28.780 And then, yeah, I passed. 00:02:28.780 --> 00:02:33.780 - That's what general area was your PhD in? 00:02:33.780 --> 00:02:36.580 I know math, but what specifically? 00:02:36.580 --> 00:02:40.140 - Discrete event simulation was where I specialized 00:02:40.140 --> 00:02:44.220 in my PhD, but like in conjunction with some 00:02:44.220 --> 00:02:47.740 of the other techniques, stuff like Markov chains 00:02:47.740 --> 00:02:50.620 and queueing theory, which all sort of are different ways 00:02:50.620 --> 00:02:53.100 of solving the same sort of problem. 00:02:53.100 --> 00:02:55.180 And that's where I sort of specialized in. 00:02:55.180 --> 00:02:57.820 - Fun, very, very cool. 00:02:57.820 --> 00:03:00.660 - We have a running joke with Garrent 00:03:00.660 --> 00:03:03.860 that one of his sub topics in his PhD 00:03:03.860 --> 00:03:07.700 that he became hyper specialized in as PhDs go is deadlock. 00:03:07.700 --> 00:03:11.300 And so there's a tweet came up about a question 00:03:11.300 --> 00:03:13.860 about deadlock and all these jokes that come up. 00:03:13.860 --> 00:03:14.700 We got very excited. 00:03:14.700 --> 00:03:15.540 Well, I got very excited. 00:03:15.540 --> 00:03:18.220 Like, "Garrent, someone's joking about your work." 00:03:18.220 --> 00:03:20.560 - That's fantastic. 00:03:20.560 --> 00:03:22.740 Vince, you've already told your story. 00:03:22.740 --> 00:03:23.980 Maybe just a quick update. 00:03:23.980 --> 00:03:26.080 What have you been up to in the last couple of years? 00:03:26.080 --> 00:03:27.880 - Yes, in the last couple of years, 00:03:27.880 --> 00:03:32.100 having the pleasure of working with Geraint now, 00:03:32.100 --> 00:03:34.280 now that he's a colleague of mine, 00:03:34.280 --> 00:03:38.420 but otherwise continuing my work on the Axtra library, 00:03:38.420 --> 00:03:41.760 which is the library we were chatting about just now. 00:03:41.760 --> 00:03:44.840 And yeah, I'm still a mathematician at Cardiff, 00:03:44.840 --> 00:03:49.560 where the best part of my job is getting to teach people 00:03:49.560 --> 00:03:51.920 how to program. 00:03:51.920 --> 00:03:55.480 And that's, I think mathematics is such a cool subject, 00:03:55.480 --> 00:03:59.840 but in a way you're only ever a theoretical mathematician 00:03:59.840 --> 00:04:02.020 until you can program the stuff you're doing. 00:04:02.020 --> 00:04:04.200 Even the applied stuff is quite theoretic. 00:04:04.200 --> 00:04:07.840 And then it's once you can code these things 00:04:07.840 --> 00:04:09.760 that are so powerful, 00:04:09.760 --> 00:04:12.280 it really kind of releases the magic of mathematics 00:04:12.280 --> 00:04:15.320 for want of a less cringy type of way of saying it. 00:04:15.320 --> 00:04:17.560 So that's kind of what I really enjoy doing 00:04:17.560 --> 00:04:19.880 and what I keep doing. 00:04:19.880 --> 00:04:21.840 Kind of what we're going to be talking about today. 00:04:21.840 --> 00:04:24.520 - Yeah, absolutely, we're gonna touch on a bunch 00:04:24.520 --> 00:04:26.820 of different manifestations of that basically. 00:04:26.820 --> 00:04:31.120 Cool, I wanna put out a quick disclaimer. 00:04:31.120 --> 00:04:32.800 So we're gonna be talking about math things, 00:04:32.800 --> 00:04:36.740 obviously Python things as well on the Python show here. 00:04:36.740 --> 00:04:42.060 The disclaimer is, I have some degrees in math, 00:04:42.060 --> 00:04:44.680 but I have not done anything with them for 20 years. 00:04:44.680 --> 00:04:48.640 And therefore, I know just enough to ask bad questions 00:04:48.640 --> 00:04:49.880 and make poor assumptions. 00:04:49.880 --> 00:04:52.320 So you all are gonna have to keep me on track 00:04:52.320 --> 00:04:54.200 and just tell me, no, no, no, Michael, 00:04:54.200 --> 00:04:55.840 you are totally misremembering that 00:04:55.840 --> 00:04:58.640 from your courses 20 years ago. 00:04:58.640 --> 00:05:00.440 - The real problem is we might just be 00:05:00.440 --> 00:05:02.920 on just the other side of that boundary 00:05:02.920 --> 00:05:05.320 where we could confidently give you bad answers. 00:05:05.320 --> 00:05:06.160 That's the-- 00:05:06.160 --> 00:05:07.800 (laughing) 00:05:07.800 --> 00:05:09.880 - Look, if you say it confidently, I'm sure-- 00:05:09.880 --> 00:05:12.200 - Yeah, exactly, confidently giving bad answers 00:05:12.200 --> 00:05:13.040 is the problem. 00:05:13.040 --> 00:05:15.900 - Yeah, sure, all right, cool. 00:05:15.900 --> 00:05:20.900 - Well, let's kick this off by just talking about 00:05:20.900 --> 00:05:23.740 what is applied mathematics. 00:05:23.740 --> 00:05:28.500 Because one of the final courses I took, 00:05:28.500 --> 00:05:31.020 it very much confused me, 00:05:31.020 --> 00:05:34.220 both in the content and just purely in its title. 00:05:34.220 --> 00:05:37.260 This was a course at UCSD in the PhD program there. 00:05:37.260 --> 00:05:42.200 The course was titled Applied Abstract Algebra. 00:05:42.200 --> 00:05:43.980 - Right. 00:05:43.980 --> 00:05:44.800 (laughing) 00:05:44.800 --> 00:05:45.640 - I'm distracted. 00:05:45.640 --> 00:05:46.460 (laughing) 00:05:46.460 --> 00:05:47.300 - Why is it applied? 00:05:47.300 --> 00:05:51.920 Because I really don't, I just, so let's just start out. 00:05:51.920 --> 00:05:54.560 We're gonna be talking about solving applied math problems. 00:05:54.560 --> 00:05:57.400 Like what the heck is applied math versus like, 00:05:57.400 --> 00:05:59.320 what am I doing, a calculus class 00:05:59.320 --> 00:06:02.540 where I'm solving a bunch of like formulaic type of problems 00:06:02.540 --> 00:06:05.800 versus real analysis where I'm chaining theories 00:06:05.800 --> 00:06:10.640 to derive new ideas or maybe it's a numerical analysis 00:06:10.640 --> 00:06:13.500 or stats, like what, where are we in the math world? 00:06:14.760 --> 00:06:17.560 - Yeah, I think applied mathematics 00:06:17.560 --> 00:06:20.640 is an interesting kind of like term 00:06:20.640 --> 00:06:22.600 because in a way it's become a, 00:06:22.600 --> 00:06:25.040 it's come destroyed from its meaning 00:06:25.040 --> 00:06:28.080 in a lot of cases in that there's a whole area 00:06:28.080 --> 00:06:31.600 of applied mathematics as a subfield of mathematics. 00:06:31.600 --> 00:06:36.000 That's not necessarily applied in any realistic sense. 00:06:36.000 --> 00:06:38.960 I don't know what you think, Gav. 00:06:38.960 --> 00:06:41.560 - Yeah, yeah, so I think traditionally 00:06:41.560 --> 00:06:47.400 what applied mathematics was when I was doing my undergrad was these sort of physics models 00:06:47.400 --> 00:06:52.520 where they assume no gravity and they assume no friction and stuff like that which doesn't seem 00:06:52.520 --> 00:07:01.480 very realistic to me at all. Whereas when me and Vince have been talking about applied 00:07:01.480 --> 00:07:07.240 mathematics sometimes that goes under another name called operational research or operations research 00:07:08.840 --> 00:07:14.440 that we call it applied mathematics because we're applying various techniques in mathematics 00:07:14.440 --> 00:07:24.200 to a situation, a real situation. Right. So that they are and I do think not necessarily by 00:07:24.200 --> 00:07:29.080 definition but just in general different techniques that apply to the more physicsy problems to the 00:07:29.080 --> 00:07:35.240 more management style problems maybe that is yeah but not by definition it doesn't have to be like 00:07:35.240 --> 00:07:41.880 that. It's just that's what people find useful. Yeah, in a way a lot of these labels in terms of 00:07:41.880 --> 00:07:48.520 the mathematical subfields and things are not terribly helpful because they create barriers 00:07:48.520 --> 00:07:57.720 between these fields. There's this problem I studied in my PhD where it's in a pure enumerative 00:07:57.720 --> 00:08:03.160 combinatorics trying to count these types of matrices. Really neat problem actually, 00:08:03.160 --> 00:08:05.840 'cause a whole other series of conversations. 00:08:05.840 --> 00:08:09.200 And the most elegant proof that came for this conjecture 00:08:09.200 --> 00:08:13.200 came from statistical mechanics, whatever that means, 00:08:13.200 --> 00:08:15.880 but it's a field of mathematical physics, 00:08:15.880 --> 00:08:18.680 and it's where like all these boundaries from fields 00:08:18.680 --> 00:08:20.640 not always are helpful, 00:08:20.640 --> 00:08:23.000 whereas really the techniques are the helpful ones 00:08:23.000 --> 00:08:24.560 and knowing when to apply them. 00:08:24.560 --> 00:08:30.400 Yeah, so I think the definition that we would use 00:08:30.400 --> 00:08:32.200 for the purpose of what we're talking about today 00:08:32.200 --> 00:08:34.880 in terms of applied mathematics are just, 00:08:34.880 --> 00:08:37.720 without necessarily going to an incredibly high level 00:08:37.720 --> 00:08:39.740 of mathematics where you're talking about the stuff 00:08:39.740 --> 00:08:43.400 that they do at CERN that is certainly applied, 00:08:43.400 --> 00:08:46.560 you know, there's some very low hanging fruit. 00:08:46.560 --> 00:08:47.600 I don't know if that's the right word. 00:08:47.600 --> 00:08:50.000 Low hanging fruit of where mathematics can vary much. 00:08:50.000 --> 00:08:51.960 - Like day to day trumps, yeah. 00:08:51.960 --> 00:08:54.040 - Exactly, day to day. 00:08:54.040 --> 00:08:56.200 And it's where you take these ideas of, you know, 00:08:56.200 --> 00:08:57.480 in high school where you're told, 00:08:57.480 --> 00:09:00.100 oh, matrices are important because computers 00:09:00.100 --> 00:09:01.600 can do mathematics really quickly with them, 00:09:01.600 --> 00:09:03.240 but you don't do it with a computer. 00:09:03.240 --> 00:09:05.760 So, you know, who cares, right? 00:09:05.760 --> 00:09:06.600 - Yeah, exactly. 00:09:06.600 --> 00:09:07.420 - But I'm happy with the matrix. 00:09:07.420 --> 00:09:08.880 - They tell you how to do it with computers 00:09:08.880 --> 00:09:11.240 and then you, yeah, then you proceed to do it by hand 00:09:11.240 --> 00:09:13.280 for the next two weeks, yeah. 00:09:13.280 --> 00:09:15.200 - Exactly, two weeks if you're lucky. 00:09:15.200 --> 00:09:17.040 - I wish I could tell you. 00:09:17.040 --> 00:09:18.880 I wish I could tell you that, but yeah, exactly. 00:09:18.880 --> 00:09:20.360 You're like, well, I could tell you 00:09:20.360 --> 00:09:22.760 whether this matrix is singular or not, 00:09:22.760 --> 00:09:26.360 but I have no idea why I would do that, right? 00:09:26.360 --> 00:09:28.200 So this is sort of the next step, like, 00:09:28.200 --> 00:09:30.160 well, what would you, if you had that knowledge, 00:09:30.160 --> 00:09:33.000 that kind of knowledge, what would you do with it? 00:09:33.000 --> 00:09:34.660 Like what kind of problems could you answer? 00:09:34.660 --> 00:09:37.600 And some of the examples that you all cover in this book 00:09:37.600 --> 00:09:39.400 that we're gonna highlight a little bit 00:09:39.400 --> 00:09:42.780 are things like if you have two businesses 00:09:42.780 --> 00:09:45.500 that are competing, what choices might they make? 00:09:45.500 --> 00:09:50.080 Or if, no, I know this is extremely theoretical 00:09:50.080 --> 00:09:51.080 and it's never gonna happen, 00:09:51.080 --> 00:09:53.080 but what if there was like a pandemic 00:09:53.080 --> 00:09:55.200 and there were people who were sick? 00:09:55.200 --> 00:09:56.240 (laughing) 00:09:56.240 --> 00:09:57.080 - Probably not that fun to be in. 00:09:57.080 --> 00:09:57.920 (laughing) 00:09:57.920 --> 00:10:02.640 We're using it to make weird trade-offs about society, like should we shut everybody in a basement? 00:10:02.640 --> 00:10:05.240 Should we make them behave in different ways? 00:10:05.240 --> 00:10:09.120 What's the cost versus benefit analysis? 00:10:09.120 --> 00:10:11.120 And those kinds of things, right? 00:10:11.120 --> 00:10:16.400 And all these things that you can, without needing too much high-level mathematics, 00:10:16.400 --> 00:10:20.000 you can describe them mathematically relatively simply. 00:10:20.000 --> 00:10:26.000 And then just with a little bit of code, you can really do cool stuff with it. 00:10:26.000 --> 00:10:27.680 It doesn't take much code, you know, 00:10:27.680 --> 00:10:30.240 and that's where Python really comes in. 00:10:30.240 --> 00:10:31.260 - Yeah, for sure. 00:10:31.260 --> 00:10:34.520 One of the things that we'll see throughout here 00:10:34.520 --> 00:10:36.120 is there's a bunch of different examples 00:10:36.120 --> 00:10:38.400 across these different areas of math 00:10:38.400 --> 00:10:40.320 and these different types of problems 00:10:40.320 --> 00:10:42.440 in different libraries that apply to solving them. 00:10:42.440 --> 00:10:46.800 But the thing that's cool is every one of those solutions 00:10:46.800 --> 00:10:51.160 fits within a couple of pages on the long ones, right? 00:10:51.160 --> 00:10:53.080 For Jupyter Notebooks that have the solutions 00:10:53.080 --> 00:10:55.400 plus have some of the output of the answer, right? 00:10:55.400 --> 00:10:58.760 It's not a ton of code, is it? 00:10:58.760 --> 00:11:00.160 - No, no, exactly. 00:11:00.160 --> 00:11:05.000 And that's, this kind of touches on something else 00:11:05.000 --> 00:11:08.980 that we were gonna talk about is the idea 00:11:08.980 --> 00:11:12.640 that a lot of the time when these things are taught, 00:11:12.640 --> 00:11:16.080 they're taught with specific pieces of software, 00:11:16.080 --> 00:11:18.160 mostly commercial pieces of software. 00:11:18.160 --> 00:11:21.740 And then the topic itself is kind of not separated 00:11:21.740 --> 00:11:24.240 from the software used to attack the topic. 00:11:24.240 --> 00:11:27.360 we often go into meetings with industrial partners for research products, 00:11:27.360 --> 00:11:30.960 and they talk about the tool as opposed to the idea. 00:11:30.960 --> 00:11:36.560 And that's a pity because that makes the idea much more complicated than it is, 00:11:36.560 --> 00:11:39.440 because all of a sudden you have to take apart this really complex idea. 00:11:39.440 --> 00:11:44.000 But often with open source software, or with Python and R, 00:11:44.000 --> 00:11:46.720 which are the two examples that we've used, 00:11:46.720 --> 00:11:53.280 it's like three lines of code to find out the effect of a pandemic or other things. 00:11:53.280 --> 00:11:58.280 - I also think it demystifies things a little bit 00:11:58.280 --> 00:12:07.780 because if what you do is you go to some expensive 00:12:07.780 --> 00:12:12.160 polished piece of software like Maple or something 00:12:12.160 --> 00:12:14.800 and you can say, you say, well, I could ask this 00:12:14.800 --> 00:12:17.400 expensive, complex, huge piece of software a question 00:12:17.400 --> 00:12:19.600 and it can magically give me the answer. 00:12:19.600 --> 00:12:22.440 - Yeah. 00:12:22.440 --> 00:12:24.400 - And it's great that you know you have this 00:12:24.400 --> 00:12:27.600 very fancy tool, but it doesn't necessarily reveal 00:12:27.600 --> 00:12:30.280 a ton of understanding because of it, right? 00:12:30.280 --> 00:12:31.120 - Yeah. 00:12:31.120 --> 00:12:32.800 - Yeah, cool. 00:12:32.800 --> 00:12:35.560 - Yeah, and an idea that's beginning to form in my head, 00:12:35.560 --> 00:12:37.600 I was just saying this to Gary, 00:12:37.600 --> 00:12:39.040 I just haven't fully formed, 00:12:39.040 --> 00:12:41.680 I think there's a blog post that no one's gonna read 00:12:41.680 --> 00:12:43.720 that I wanna write one day about, 00:12:43.720 --> 00:12:44.960 you know, the ethics of it, 00:12:44.960 --> 00:12:48.200 about teaching these fancy commercial softwares, 00:12:48.200 --> 00:12:55.000 why these great companies give out these educational software is that 00:12:55.000 --> 00:13:00.680 they immediately have lots of users of the software that don't know how to use anything 00:13:00.680 --> 00:13:08.680 else. And I wonder if ethically as educators if that's okay. I think we should make more of an 00:13:08.680 --> 00:13:14.840 effort to separate the concept from the software. And I was kind of like saying like I don't think 00:13:14.840 --> 00:13:16.420 I don't think we should teach any commercial software. 00:13:16.420 --> 00:13:18.220 Geraint, you made a good point. 00:13:18.220 --> 00:13:21.400 - Yeah, I don't really have a problem 00:13:21.400 --> 00:13:26.180 with teaching a particular topic through commercial software 00:13:26.180 --> 00:13:29.480 as long as we teach it in a separated way 00:13:29.480 --> 00:13:32.120 so that you know, once you've formulated the concepts 00:13:32.120 --> 00:13:34.060 and the ideas mathematically, 00:13:34.060 --> 00:13:35.960 you can use whatever software you want. 00:13:35.960 --> 00:13:38.260 But in the classroom, we happen to have 00:13:38.260 --> 00:13:40.040 this expensive license, we're gonna use this. 00:13:40.040 --> 00:13:41.700 But outside of the classroom, 00:13:41.700 --> 00:13:43.540 there are other things you can use. 00:13:43.540 --> 00:13:47.140 - Yeah, well, I think there's a couple aspects here. 00:13:47.140 --> 00:13:50.380 One, Vince, you spoke about the ethics of it. 00:13:50.380 --> 00:13:51.660 Is it the right thing to do 00:13:51.660 --> 00:13:53.900 to basically reinforce this loop? 00:13:53.900 --> 00:13:56.020 - Exactly, exactly. 00:13:56.020 --> 00:13:58.060 - That entrenches some of these. 00:13:58.060 --> 00:14:02.260 The other part is, if you're in the UK 00:14:02.260 --> 00:14:06.320 or if you're in the US and you say to your student, 00:14:06.320 --> 00:14:08.060 probably especially if you're in the US, 00:14:08.060 --> 00:14:10.540 they're used to getting paid so much. 00:14:10.540 --> 00:14:12.580 I just paid for both my daughters to go through college. 00:14:12.580 --> 00:14:20.960 So I'm aware that here you pay a lot for the actual tuition, but many places you'll say 00:14:20.960 --> 00:14:22.880 to students, what is it in the UK? 00:14:22.880 --> 00:14:25.600 Is there, how is college, what's the affordability? 00:14:25.600 --> 00:14:29.160 I know in Germany and other places, but I don't know what that was. 00:14:29.160 --> 00:14:36.000 - So it's a touchy subject in that tuition fees have just come in. 00:14:36.000 --> 00:14:40.800 And so cost of universities here are equivalent, 00:14:40.800 --> 00:14:43.780 not far off to in-state tuition 00:14:43.780 --> 00:14:45.880 in public universities in the United States. 00:14:45.880 --> 00:14:48.700 I think they're not far off. 00:14:48.700 --> 00:14:52.880 But then we get to charge, and I'm saying we, 00:14:52.880 --> 00:14:54.840 very, very not talking about me, 00:14:54.840 --> 00:14:57.120 but we get to charge whatever we want 00:14:57.120 --> 00:15:00.000 to a certain extent to people from the European Union 00:15:00.000 --> 00:15:02.800 and then even more to people from outside of that. 00:15:02.800 --> 00:15:03.920 Actually, I don't even know if that's true 00:15:03.920 --> 00:15:08.640 about the European Union because of recent events anymore. 00:15:08.640 --> 00:15:09.480 But yeah. 00:15:09.480 --> 00:15:13.840 So yeah, there is a cost. 00:15:13.840 --> 00:15:14.680 - Sure, okay. 00:15:14.680 --> 00:15:18.920 So going back though, my point about the ethics was, 00:15:18.920 --> 00:15:21.820 it's one thing to be in the US or places in Europe 00:15:21.820 --> 00:15:24.960 where we have a decent amount of money. 00:15:24.960 --> 00:15:27.200 It's another to say to somebody, 00:15:27.200 --> 00:15:31.400 you have to pay $500 for this software 00:15:31.400 --> 00:15:33.260 to learn the subject, right? 00:15:33.260 --> 00:15:37.620 where 500 US dollars might be the yearly income 00:15:37.620 --> 00:15:39.620 for an employed person and their student. 00:15:39.620 --> 00:15:47.540 It seems like there's a lot of good would be done 00:15:47.540 --> 00:15:52.320 by building up maybe the missing gaps 00:15:52.320 --> 00:15:53.840 that force or encourage people 00:15:53.840 --> 00:15:55.600 to go to this commercial software, 00:15:55.600 --> 00:16:00.220 building that up rather in the form of SciPy libraries 00:16:00.220 --> 00:16:05.220 and the Python data science stack in general. 00:16:05.220 --> 00:16:07.980 So that it's free, open source and all those things. 00:16:07.980 --> 00:16:10.300 - I think that would apply for all subjects. 00:16:10.300 --> 00:16:14.020 I think really close to what we're talking about here 00:16:14.020 --> 00:16:19.020 is with mathematics, I think it's really frustrating 00:16:19.020 --> 00:16:22.740 'cause maybe I'm thinking too purely now, 00:16:22.740 --> 00:16:25.580 but I mean, pure of heart, not pure mathematics. 00:16:25.580 --> 00:16:28.660 In terms of like, mathematics is just such a clean 00:16:28.660 --> 00:16:30.860 and minimalistic subject. 00:16:30.860 --> 00:16:33.500 You need a pen and a paper to do it. 00:16:33.500 --> 00:16:34.900 And if all of a sudden we're teaching people 00:16:34.900 --> 00:16:36.540 to use a pen and paper to do mathematics 00:16:36.540 --> 00:16:38.660 and saying like, oh, but you can only do it 00:16:38.660 --> 00:16:41.380 with a pen made by a BIC. 00:16:41.380 --> 00:16:44.620 But don't worry, BIC is-- 00:16:44.620 --> 00:16:46.580 - Long pen is the only one that can do calculus. 00:16:46.580 --> 00:16:47.700 - Exactly, right? 00:16:47.700 --> 00:16:49.940 And then once you graduate, 00:16:49.940 --> 00:16:52.580 if you want to write down this idea again, 00:16:52.580 --> 00:16:54.100 you have to use a BIC pen, 00:16:54.100 --> 00:16:55.300 but you have to pay for it yourself. 00:16:55.300 --> 00:16:57.100 And I really do think mathematics, 00:16:57.100 --> 00:17:03.260 evolution of mathematics and a lot of science, I would argue, is into computing, right? Is 00:17:03.260 --> 00:17:09.420 into getting computers to do it. And that extension of using the pen now is to use code. 00:17:09.420 --> 00:17:10.420 And yeah, it's... 00:17:10.420 --> 00:17:17.420 I do think, I think, for me at least, I think one of the important things is our separation 00:17:17.420 --> 00:17:23.580 of mathematical concepts to software. Because it's a lot less of a problem, but there's 00:17:23.580 --> 00:17:30.620 still a problem going, the only way you can do this is by using free open software. There 00:17:30.620 --> 00:17:35.260 are some places, unfortunately, that are not allowed to use open software because they 00:17:35.260 --> 00:17:39.020 think there's security problems and stuff. So if you've only taught open software, then 00:17:39.020 --> 00:17:45.180 certain, like the NHS, for example, I know they discourage using open software. So maybe 00:17:45.180 --> 00:17:49.100 you think then, think, "I can't do this maths thing anymore." But if you've separated the 00:17:49.100 --> 00:17:53.900 concept from the software, at least you know the concept and you know you've got choices. 00:17:53.900 --> 00:18:01.100 Yeah, absolutely. I think that's very true. Separating the concept from the software is key 00:18:01.100 --> 00:18:07.900 where possible and I think perhaps we don't always do a good job of that. And here I am speaking as 00:18:07.900 --> 00:18:12.940 an industry, I think sometimes we often... I've been to conversations where people have said, 00:18:12.940 --> 00:18:16.620 "I need to use MATLAB. Can you help me with MATLAB?" And it turned out they wanted to know 00:18:16.620 --> 00:18:20.460 how to numerically solve a differential equation. They didn't want to do math lab. They just wanted 00:18:20.460 --> 00:18:24.700 to solve a numeric equation. They just did not know that that's what they were doing. 00:18:24.700 --> 00:18:38.540 I do want to move off of this so we can dive into the applied math aspects. But I think one other 00:18:38.540 --> 00:18:47.860 final thing on this is I feel like professors, especially as they get older, they've taught 00:18:47.860 --> 00:18:51.260 a certain way with a certain set of tools for 20 years. 00:18:51.260 --> 00:18:52.260 And you know what? 00:18:52.260 --> 00:18:56.700 That course they wrote, they already have the materials and the exercises and all of 00:18:56.700 --> 00:18:57.700 that. 00:18:57.700 --> 00:19:01.300 And the idea of saying, "Well, we're going to now throw out this and grab some new open 00:19:01.300 --> 00:19:02.300 source library." 00:19:02.300 --> 00:19:08.020 I mean, there's 350,000 libraries on PyPI and they're always changing and turning and 00:19:08.020 --> 00:19:09.520 and something new is coming along. 00:19:09.520 --> 00:19:13.700 And it's maybe a lot to ask, 00:19:13.700 --> 00:19:16.320 but also maybe not too much to ask to say, 00:19:16.320 --> 00:19:18.560 look, you should keep up with these things. 00:19:18.560 --> 00:19:21.640 And if there's a new way to present it to your students, 00:19:21.640 --> 00:19:24.080 not because even some of the ethics stuff, 00:19:24.080 --> 00:19:26.760 but you might be doing a disservice to your student 00:19:26.760 --> 00:19:29.520 to say, look, the only way that you can solve these problems 00:19:29.520 --> 00:19:30.720 is with say Fortran, 00:19:30.720 --> 00:19:31.560 or the only way you can do 00:19:31.560 --> 00:19:35.000 is with a $2,000 toolbox extension to MATLAB. 00:19:35.000 --> 00:19:37.040 That's the way that you have to go to solve this. 00:19:37.040 --> 00:19:40.960 here's this super well-respected professor telling you that's how you do it. 00:19:40.960 --> 00:19:41.960 Well, that's not actually how you do it. 00:19:41.960 --> 00:19:43.560 That's how they've done it for 20 years. 00:19:43.560 --> 00:19:46.920 And so there's a lot of inertia there, right? 00:19:46.920 --> 00:19:53.120 I'm really new at being a lecturer, so maybe I'm being really naive here, but 00:19:53.120 --> 00:19:58.920 it is an effort to keep up with all this stuff, but that's our job. 00:19:58.920 --> 00:20:01.280 Our job is to keep up with the latest maths. 00:20:01.280 --> 00:20:05.280 Anyway, if I was still using, if in 30 years time, I was still using the same 00:20:05.280 --> 00:20:08.280 math that I'm using today, I wouldn't be doing my job properly. 00:20:08.280 --> 00:20:10.560 So why is the same true with software? 00:20:10.560 --> 00:20:21.800 Yeah, I think it actually, frankly, comes back to ethics in that it's unethical to not make the effort to update your training. 00:20:21.800 --> 00:20:29.600 And if we were talking about doctors and surgeons, they do need to learn new things as the science evolves. 00:20:29.600 --> 00:20:36.160 I think it could probably with lecturers, professors, higher education, it comes back 00:20:36.160 --> 00:20:43.160 to that dichotomy between research and teaching and how teaching is viewed. 00:20:43.160 --> 00:20:44.160 But yes, absolutely. 00:20:44.160 --> 00:20:45.160 I think, yeah. 00:20:45.160 --> 00:20:51.240 In a way, I would be disappointed if at the end of my career, I'm still teaching Python. 00:20:51.240 --> 00:20:53.200 In a way, I also hope I have. 00:20:53.200 --> 00:20:54.200 in a way. 00:20:54.200 --> 00:20:55.200 Yeah, yeah. 00:20:55.200 --> 00:21:00.600 Well, but not 2020 Python, but 2050 Python or whatever it is, right? 00:21:00.600 --> 00:21:01.600 Absolutely. 00:21:01.600 --> 00:21:02.600 Yeah, exactly. 00:21:02.600 --> 00:21:03.600 Oh, Python's already on. 00:21:03.600 --> 00:21:08.040 I started teaching Python 2, and then I had to figure out how to teach both. 00:21:08.040 --> 00:21:09.040 Yeah, exactly. 00:21:09.040 --> 00:21:10.040 Yeah, yeah. 00:21:10.040 --> 00:21:11.040 Sorry to cut you off. 00:21:11.040 --> 00:21:15.360 So you started teaching Python 2, and then now you've moved on. 00:21:15.360 --> 00:21:19.800 And then I had to figure out how to deal with Python 2 and 3, and now I just teach Python 00:21:19.800 --> 00:21:20.800 3, and yeah. 00:21:20.800 --> 00:21:21.800 Yeah. 00:21:21.800 --> 00:21:24.440 I can't believe that transition took so long, 00:21:24.440 --> 00:21:26.040 but well, there it is. 00:21:26.040 --> 00:21:29.360 All right, well, let's dive into some of the problems. 00:21:29.360 --> 00:21:33.120 And we're gonna, more specifically, 00:21:33.120 --> 00:21:36.240 I'm gonna take this book that you all created 00:21:36.240 --> 00:21:39.200 and use it to sort of guide our exploration 00:21:39.200 --> 00:21:40.640 of both some of these problems, 00:21:40.640 --> 00:21:42.520 how we might solve them with Python, 00:21:42.520 --> 00:21:44.920 and some of the libraries that make it possible. 00:21:44.920 --> 00:21:47.720 I guess one of the things that struck me about that journey 00:21:47.720 --> 00:21:52.280 is that there's not that many external packages 00:21:52.280 --> 00:21:53.680 that are required. 00:21:53.680 --> 00:21:56.360 It's not like, well, this one takes 10 to solve this problem. 00:21:56.360 --> 00:21:58.400 This one takes these complex, these five. 00:21:58.400 --> 00:22:00.320 If you put them together just right, you get the answer. 00:22:00.320 --> 00:22:01.780 So that'll be fun. 00:22:01.780 --> 00:22:04.600 But tell us a bit about this book, 00:22:04.600 --> 00:22:06.940 Applied Mathematics with Open Source Software. 00:22:06.940 --> 00:22:12.840 - Yeah, so publisher, this is an academic publisher, 00:22:12.840 --> 00:22:15.760 which amongst other things means 00:22:15.760 --> 00:22:17.720 the book is really too expensive. 00:22:17.720 --> 00:22:21.840 But they often just send out emails to people saying, 00:22:21.840 --> 00:22:23.400 hey, could you write a book? 00:22:23.400 --> 00:22:26.060 It's not necessarily a source of flattery. 00:22:26.060 --> 00:22:30.040 But we got one of these emails 00:22:30.040 --> 00:22:35.040 and Geraint actually had just given a talk at PyCon UK. 00:22:35.040 --> 00:22:36.400 I don't know if you want to say a little bit 00:22:36.400 --> 00:22:39.120 about the talk you gave, Geraint. 00:22:39.120 --> 00:22:42.400 - Yeah, so it was very much a precursor to this book 00:22:42.400 --> 00:22:45.820 where I had given an introduction 00:22:45.820 --> 00:22:48.260 to the field of operational research, 00:22:48.260 --> 00:22:52.940 which is how we label this certain type 00:22:52.940 --> 00:22:54.380 of applied mathematics 00:22:54.380 --> 00:22:56.780 and all the different problems that could occur. 00:22:56.780 --> 00:22:58.580 And I think the title of the talk was, 00:22:58.580 --> 00:22:59.780 there's a library for that, 00:22:59.780 --> 00:23:02.620 because every sort of problem that we could come up with, 00:23:02.620 --> 00:23:04.220 you could pip install a library 00:23:04.220 --> 00:23:07.380 and in a function or two solve the problem, 00:23:07.380 --> 00:23:08.940 which was a neat little, 00:23:08.940 --> 00:23:10.380 oh, there it is, it's a neat little. 00:23:10.380 --> 00:23:11.220 - Is this it? 00:23:11.220 --> 00:23:12.060 - Yeah, yeah. 00:23:12.060 --> 00:23:15.980 - If I could just interrupt the call for proposals 00:23:15.980 --> 00:23:18.060 for PyCon UK closes on Saturday. 00:23:18.060 --> 00:23:21.940 So if you're thinking of talking, please submit a talk. 00:23:21.940 --> 00:23:26.980 - So yeah, and it was just really neat 00:23:26.980 --> 00:23:30.220 that we had these, like what we call standard problems. 00:23:30.220 --> 00:23:33.220 It was essentially our postgraduate MSC course 00:23:33.220 --> 00:23:35.740 that we teach, but instead of teaching the maths, 00:23:35.740 --> 00:23:39.020 there was one or two Python functions that solved it for you 00:23:40.500 --> 00:23:44.320 And then, yeah, that eventually evolved into this book 00:23:44.320 --> 00:23:45.860 where instead of each little topic 00:23:45.860 --> 00:23:47.440 being a couple of functions, 00:23:47.440 --> 00:23:49.760 we filled out chapters on some of the theory, 00:23:49.760 --> 00:23:53.460 and again, tried to separate the maths and the programming, 00:23:53.460 --> 00:23:55.700 emphasizing that by introducing another language, 00:23:55.700 --> 00:23:57.900 which was R, to show that you can do it 00:23:57.900 --> 00:23:58.740 in two different ways, 00:23:58.740 --> 00:24:01.380 and the software is independent of the problem. 00:24:01.380 --> 00:24:02.660 - Yeah. - Yeah. 00:24:02.660 --> 00:24:05.060 - And we kind of, I think you and I have described it, 00:24:05.060 --> 00:24:07.220 'cause every now and then as we were writing the book, 00:24:07.220 --> 00:24:09.980 we kind of stop and go, "Wait, who's the book for?" 00:24:09.980 --> 00:24:14.060 And as we were making decisions about how exactly to do something, we're like, "Wait, 00:24:14.060 --> 00:24:16.940 who's the before and after?" 00:24:16.940 --> 00:24:17.940 I won't necessarily... 00:24:17.940 --> 00:24:19.540 Well, maybe we should talk about that. 00:24:19.540 --> 00:24:26.540 But I think we've written a book that's meant to be useful to people wanting to get started 00:24:26.540 --> 00:24:34.780 either with the mathematical field problem or with how to actually do it with the code. 00:24:34.780 --> 00:24:37.520 And so every chapter has got the same kind of structure 00:24:37.520 --> 00:24:39.000 that describes a problem. 00:24:39.000 --> 00:24:42.800 Then it describes the basics ideas 00:24:42.800 --> 00:24:44.900 between behind the theory of the problem 00:24:44.900 --> 00:24:46.080 or the mathematical tools, 00:24:46.080 --> 00:24:47.360 the theory behind the mathematical tools. 00:24:47.360 --> 00:24:48.840 But again, not going into too much depth, 00:24:48.840 --> 00:24:50.440 kind of what I said before about, 00:24:50.440 --> 00:24:52.600 you don't need to understand 00:24:52.600 --> 00:24:55.460 all of Newton and Leibniz's calculus 00:24:55.460 --> 00:25:00.460 to be able to kind of predict the outcome of a pandemic. 00:25:00.460 --> 00:25:04.600 And then it just solves the problem. 00:25:04.600 --> 00:25:09.400 original problem, it solves it in two separate ways, the R and the Python, using R and Python. 00:25:09.400 --> 00:25:16.080 And the final kind of section, every chapter is pointing at a bunch of literature on it, 00:25:16.080 --> 00:25:17.080 which should be useful. 00:25:17.080 --> 00:25:21.360 Yeah, and more broadly, you might be able to, these types of problems appear and what 00:25:21.360 --> 00:25:23.600 you might be able to do with them. 00:25:23.600 --> 00:25:27.320 But the really cool stuff with the publisher is that we had an ongoing kind of conversation 00:25:27.320 --> 00:25:28.320 before the start. 00:25:28.320 --> 00:25:32.480 Garren and I were both like, well, the book has to be open. 00:25:32.480 --> 00:25:36.080 And so they've agreed, like all-- 00:25:36.080 --> 00:25:38.880 there's not a PDF floating around online of the book. 00:25:38.880 --> 00:25:40.680 But all the source files are there. 00:25:40.680 --> 00:25:42.720 So all the LaTeX files are there. 00:25:42.720 --> 00:25:45.400 All the Jupyter notebooks are there with the code. 00:25:45.400 --> 00:25:47.840 We haven't quite gotten all our Markdown files up yet, 00:25:47.840 --> 00:25:50.320 but they are theoretically all there. 00:25:50.320 --> 00:25:55.720 And so the book is very open, which we're happy about. 00:25:55.720 --> 00:25:57.640 Yeah, that's great. 00:25:57.640 --> 00:25:59.400 - It is very shiny new. 00:25:59.400 --> 00:26:01.040 It still has that new book smell. 00:26:01.040 --> 00:26:05.000 It was released just almost exactly a month ago, right? 00:26:05.000 --> 00:26:07.040 - That's right, that's right. 00:26:07.040 --> 00:26:07.880 Yeah, yeah. 00:26:07.880 --> 00:26:11.560 Keep on saying I've got to have Garent over to celebrate, 00:26:11.560 --> 00:26:13.360 but we don't have enough doing that. 00:26:13.360 --> 00:26:17.180 - I have to sign a copy for my nan. 00:26:17.180 --> 00:26:19.760 (all laughing) 00:26:19.760 --> 00:26:24.840 - All right, now before we dive into the various problems 00:26:24.840 --> 00:26:28.280 on the Python side, while we're still kind of talking 00:26:28.280 --> 00:26:31.440 a little bit high level, this is, 00:26:31.440 --> 00:26:33.660 one of the interesting aspects here is the Python 00:26:33.660 --> 00:26:36.960 and R aspect. 00:26:36.960 --> 00:26:39.360 So when you go through each chapter, 00:26:39.360 --> 00:26:40.840 which is, I think I agree with you 00:26:40.840 --> 00:26:44.320 that it's pretty approachable, even if you don't have a, 00:26:44.320 --> 00:26:45.960 you don't have to have like a master's in math 00:26:45.960 --> 00:26:48.020 or specialize in that area for it to make sense. 00:26:48.020 --> 00:26:50.080 It doesn't have, if you don't really want to see 00:26:50.080 --> 00:26:53.160 a ton of formulas, yeah, it's not super intense. 00:26:53.160 --> 00:26:55.220 - I think that's our first official review, Michael. 00:26:55.220 --> 00:26:57.120 Pretty approachable, it's fantastic to hear. 00:26:57.120 --> 00:26:59.400 (laughing) 00:26:59.400 --> 00:27:00.800 - Well, like I said, my math, 00:27:00.800 --> 00:27:04.480 while I study a ton of it is highly rusted 00:27:04.480 --> 00:27:07.760 and it was pretty approachable for me, so there's that. 00:27:07.760 --> 00:27:12.760 But maybe just talk about putting R and Python side by side 00:27:12.760 --> 00:27:14.560 for solving a set of different problems. 00:27:14.560 --> 00:27:15.960 What are some of the takeaways 00:27:15.960 --> 00:27:17.360 either of you got from that? 00:27:17.360 --> 00:27:22.160 - Yeah, so one thing I wanna say, 00:27:22.160 --> 00:27:24.440 - Yeah, I'm sorry, I'm interrupting you there, 00:27:24.440 --> 00:27:27.280 but one thing we wanted to do here, 00:27:27.280 --> 00:27:30.360 'cause we would, well, I would certainly describe myself 00:27:30.360 --> 00:27:33.040 as a Python person, not an R person. 00:27:33.040 --> 00:27:35.960 I know R, I write R, I've written a book in R, 00:27:35.960 --> 00:27:37.080 but I would certainly describe myself 00:27:37.080 --> 00:27:38.640 as a Python person in that. 00:27:38.640 --> 00:27:40.600 - If you're gonna sit down and write something, 00:27:40.600 --> 00:27:41.840 you would pick Python first. 00:27:41.840 --> 00:27:44.160 - I would pick Python, exactly. 00:27:44.160 --> 00:27:47.400 But also, I'm embedded in the Python community, 00:27:47.400 --> 00:27:52.040 I listen to some good Python podcasts, 00:27:52.040 --> 00:27:57.040 I'm a Python person and I can look at some Python code 00:27:57.040 --> 00:28:01.400 and the joyous, that looks very Pythonic, right? 00:28:01.400 --> 00:28:04.760 I can tell you that. 00:28:04.760 --> 00:28:07.200 And so we were kind of aware that we didn't want 00:28:07.200 --> 00:28:11.440 to translate the Python to R when we were writing this. 00:28:11.440 --> 00:28:16.440 We wanted to write this as close to R people as we could. 00:28:16.440 --> 00:28:20.160 I don't know if we managed that, 00:28:20.160 --> 00:28:21.880 but that was something as well that we were aware of. 00:28:21.880 --> 00:28:24.720 It's not just translating languages. 00:28:24.720 --> 00:28:25.560 Geraint, did you-- 00:28:25.560 --> 00:28:28.420 - In Python, yeah, in Python we have the word 00:28:28.420 --> 00:28:30.400 Pythonic for idiomatic Python. 00:28:30.400 --> 00:28:32.800 Do you all know, is there a word for that in R? 00:28:32.800 --> 00:28:35.320 Or is it just idiomatic R? 00:28:35.320 --> 00:28:37.640 - I don't know, I don't know, yeah. 00:28:37.640 --> 00:28:38.840 - I don't either. 00:28:38.840 --> 00:28:41.700 Geraint, you were gonna say something, jump in here. 00:28:41.700 --> 00:28:44.280 - So I was gonna say, as we were writing the book, 00:28:44.280 --> 00:28:47.240 we noticed that there were certain problems 00:28:47.240 --> 00:28:50.900 which the R and the Python lined up exactly, 00:28:50.900 --> 00:28:53.260 not from design, just from, 00:28:53.260 --> 00:28:56.020 if we were gonna approach these independently, 00:28:56.020 --> 00:28:59.280 it is pretty much exactly the same way to solve it. 00:28:59.280 --> 00:29:01.500 There were some problems where 00:29:01.500 --> 00:29:04.340 we had to reformulate the mathematics 00:29:04.340 --> 00:29:07.120 because the way to do it in R 00:29:07.120 --> 00:29:10.340 was so different to the way you do it in Python. 00:29:10.340 --> 00:29:11.660 That doesn't mean the math's changed, 00:29:11.660 --> 00:29:14.140 we just had to reformulate it, re-communicate it 00:29:14.140 --> 00:29:16.540 so that we could write it down in R. 00:29:17.700 --> 00:29:20.880 And then there were some problems again 00:29:20.880 --> 00:29:23.000 where we have to use different mathematics 00:29:23.000 --> 00:29:24.300 to solve it in Python and R 00:29:24.300 --> 00:29:26.700 because of the availability of libraries and stuff. 00:29:26.700 --> 00:29:28.540 So I thought that was really, really neat. 00:29:28.540 --> 00:29:30.980 And I think that emphasizes again, 00:29:30.980 --> 00:29:34.300 the separation of concept to software 00:29:34.300 --> 00:29:37.020 because sometimes you did have to do very different things 00:29:37.020 --> 00:29:38.640 in different softwares. 00:29:38.640 --> 00:29:41.620 - My favorite chapter on this is the one 00:29:41.620 --> 00:29:44.360 that is your specialty, Darren, 00:29:44.360 --> 00:29:47.140 the discrete event simulation chapter 00:29:47.140 --> 00:29:51.300 where I forget the name of the two 00:29:51.300 --> 00:29:54.940 theoretic ideas about discrete event simulation, 00:29:54.940 --> 00:29:58.060 process-based and what's the other one? 00:29:58.060 --> 00:30:00.540 - Yeah, so there's process-based 00:30:00.540 --> 00:30:02.620 and there's the event scheduling approach. 00:30:02.620 --> 00:30:05.140 There's two different ways of approaching 00:30:05.140 --> 00:30:06.740 discrete event simulation 00:30:06.740 --> 00:30:11.740 and the standard library in R to do it is process-based 00:30:11.740 --> 00:30:16.900 and I don't wanna call it the way to do it in Python, 00:30:16.900 --> 00:30:18.740 The way we've said in Python to do it 00:30:18.740 --> 00:30:22.700 is by using the Q libraries, CIW library. 00:30:22.700 --> 00:30:24.620 - The only reason Gerard doesn't want to say 00:30:24.620 --> 00:30:25.460 it's the way to do it in Python 00:30:25.460 --> 00:30:26.740 is because it's using his library, 00:30:26.740 --> 00:30:29.260 the library that he's the maintainer of. 00:30:29.260 --> 00:30:31.860 (laughing) 00:30:31.860 --> 00:30:32.700 - Yeah, nice. 00:30:32.700 --> 00:30:37.700 - Both those libraries, I'm pretty sure that underneath, 00:30:37.700 --> 00:30:40.100 well, I know how Q works underneath, 00:30:40.100 --> 00:30:42.700 but the Simmer, which is the R version, 00:30:42.700 --> 00:30:46.540 I'm pretty sure underneath they work very, very similarly. 00:30:46.540 --> 00:30:49.260 There's not many ways you can do different ways 00:30:49.260 --> 00:30:50.800 of discrete dimensionalization, 00:30:50.800 --> 00:30:54.260 but the way you formulate the problem is very different. 00:30:54.260 --> 00:30:58.780 And going through that in the book and going in Python, 00:30:58.780 --> 00:31:02.000 you have to take like an overhead worldview 00:31:02.000 --> 00:31:03.580 where you look at the system, 00:31:03.580 --> 00:31:06.460 whereas in R you have to take a sort of, 00:31:06.460 --> 00:31:09.500 you have to put yourself mind in the, sorry, 00:31:09.500 --> 00:31:11.500 put yourself in the mind of the customer and go, 00:31:11.500 --> 00:31:13.260 what is the customer doing right now 00:31:13.260 --> 00:31:15.260 rather than from a systems point of view 00:31:16.140 --> 00:31:17.740 in order to formulate the problem 00:31:17.740 --> 00:31:20.080 before you could just then go and solve it. 00:31:20.080 --> 00:31:21.500 I just thought it was very, very interesting 00:31:21.500 --> 00:31:25.780 that the way to do it in each language was so different 00:31:25.780 --> 00:31:26.980 and yet probably underneath 00:31:26.980 --> 00:31:28.180 it's doing exactly the same thing. 00:31:28.180 --> 00:31:29.540 You get the same answers out. 00:31:29.540 --> 00:31:31.520 You just got to formulate it in a different way. 00:31:31.520 --> 00:31:34.140 - I think that's such a nice example where diversity, 00:31:34.140 --> 00:31:35.060 and I'm using diversity 00:31:35.060 --> 00:31:37.940 from the way that languages do things. 00:31:37.940 --> 00:31:40.200 I think that's the best chapter in the book, frankly. 00:31:40.200 --> 00:31:42.140 I think that's the best chapter in the book 00:31:42.140 --> 00:31:45.180 because you not only do things differently 00:31:45.180 --> 00:31:46.140 from a programming point of view, 00:31:46.140 --> 00:31:47.580 but because you do things differently 00:31:47.580 --> 00:31:48.860 from a programming point of view, 00:31:48.860 --> 00:31:52.060 the theoretic discussion allows you to kind of, 00:31:52.060 --> 00:31:54.220 yeah, give a really good understanding 00:31:54.220 --> 00:31:55.860 of these two ways of doing this. 00:31:55.860 --> 00:31:58.500 - Yeah. - Yeah. 00:31:58.500 --> 00:32:00.860 - Yeah. - Something else 00:32:00.860 --> 00:32:03.660 that's kind of worth mentioning about the Python in R bit. 00:32:03.660 --> 00:32:07.900 I don't know if this is a terrible address, 00:32:07.900 --> 00:32:09.620 but I like tests. 00:32:09.620 --> 00:32:11.180 I don't like trusting any code. 00:32:11.180 --> 00:32:13.020 I like writing tests all the time. 00:32:13.020 --> 00:32:14.820 And we came to this immediate thing 00:32:14.820 --> 00:32:16.700 So we wanted the book to be tested. 00:32:16.700 --> 00:32:18.260 We wanted to know the code was correct in the book, 00:32:18.260 --> 00:32:22.340 but we wanted to have these two different languages. 00:32:22.340 --> 00:32:24.300 And we didn't want to kind of use the standard 00:32:24.300 --> 00:32:26.940 doc test notation for the Python. 00:32:26.940 --> 00:32:28.220 And then we wanted to find something that would work 00:32:28.220 --> 00:32:29.180 for the R, et cetera. 00:32:29.180 --> 00:32:34.180 So we actually wrote a little language of Gnostic doc tester 00:32:34.180 --> 00:32:37.940 that basically runs through and tests all the code 00:32:37.940 --> 00:32:39.100 in the book for us. 00:32:39.100 --> 00:32:41.260 And theoretically, when we write the second edition, 00:32:41.260 --> 00:32:42.420 when we add Julia as well, 00:32:42.420 --> 00:32:44.380 it will be able to handle that as well. 00:32:44.380 --> 00:32:45.860 (laughing) 00:32:45.860 --> 00:32:47.260 - Yeah, I guess Julia is another option 00:32:47.260 --> 00:32:50.140 that could have possibly shown up in here. 00:32:50.140 --> 00:32:53.360 Pretty interesting. 00:32:53.360 --> 00:32:56.740 I guess it's worth pulling this up. 00:32:56.740 --> 00:33:00.980 It's probably worth pulling up the Stack Overflow trends 00:33:00.980 --> 00:33:04.220 and you're putting those in there. 00:33:04.220 --> 00:33:05.800 - Yeah. 00:33:05.800 --> 00:33:10.800 - Right, so we have R, we've got Julia. 00:33:10.800 --> 00:33:13.620 I don't know where these all lie right now, 00:33:13.620 --> 00:33:16.780 but I would imagine the graph, 00:33:16.780 --> 00:33:21.360 the graph looks a little bit different across these. 00:33:21.360 --> 00:33:23.360 Just for people listening, I would say, 00:33:23.360 --> 00:33:25.880 you know, R is certainly growing. 00:33:25.880 --> 00:33:28.320 It's actually growing pretty healthily 00:33:28.320 --> 00:33:31.040 compared to many, many programming languages. 00:33:31.040 --> 00:33:35.360 And it's not going crazy, but it's going across. 00:33:35.360 --> 00:33:38.520 You've got Python, which if anyone's looked 00:33:38.520 --> 00:33:39.400 in the last couple of years, 00:33:39.400 --> 00:33:43.480 it's just done insane stuff in terms of popularity 00:33:43.480 --> 00:33:45.480 - Over there, so there's that. 00:33:45.480 --> 00:33:48.480 And then Julia is, it's, I don't know, 00:33:48.480 --> 00:33:50.240 I can't really read it. 00:33:50.240 --> 00:33:55.240 It's like 0.01% versus say like 2% for Julia, 00:33:55.240 --> 00:34:01.680 for R, excuse me, and then for 16% for Python. 00:34:01.680 --> 00:34:04.360 And there is something to be considered 00:34:04.360 --> 00:34:07.800 about choosing not just a language, 00:34:07.800 --> 00:34:10.200 'cause the language has a cool way of doing async 00:34:10.200 --> 00:34:11.480 or its generators are beautiful, 00:34:11.480 --> 00:34:14.680 but choosing a language for its ecosystem as well. 00:34:14.680 --> 00:34:15.520 - Yeah. 00:34:15.520 --> 00:34:20.040 - And I think that's where it touches on this here, right? 00:34:20.040 --> 00:34:23.200 - But also for the community that's already there, 00:34:23.200 --> 00:34:28.200 I think, at least in the area of mathematics 00:34:28.200 --> 00:34:30.480 that me and Vincent are in, 00:34:30.480 --> 00:34:34.080 I think R and Python are quite prevalent, 00:34:34.080 --> 00:34:34.920 but they're also used- 00:34:34.920 --> 00:34:37.000 - Maybe they're people there, right? 00:34:37.000 --> 00:34:37.840 - Yeah. 00:34:37.840 --> 00:34:41.640 - But I think that also used in different ways, 00:34:41.640 --> 00:34:43.120 would you agree Vince? 00:34:43.120 --> 00:34:44.900 I would say Python's very, 00:34:44.900 --> 00:34:50.240 because of PyPy, things like out of the box, 00:34:50.240 --> 00:34:54.120 there's one library to do this and it's their way to do it. 00:34:54.120 --> 00:34:58.280 Whereas with R, people tend to write their own stuff 00:34:58.280 --> 00:35:00.760 and then upload it. 00:35:00.760 --> 00:35:01.600 - Yeah. 00:35:01.600 --> 00:35:05.840 - So you might get lots and lots of different ways 00:35:05.840 --> 00:35:07.040 of doing the same thing, 00:35:07.040 --> 00:35:09.460 but each one might specialize slightly in a different way. 00:35:09.460 --> 00:35:13.620 Whereas with Python, I feel like there's one library 00:35:13.620 --> 00:35:15.380 that does it really, really well. 00:35:15.380 --> 00:35:18.380 I think people just use the ecosystems in different ways. 00:35:18.380 --> 00:35:20.580 - Yeah, both those two things are often talked as 00:35:20.580 --> 00:35:22.140 strengths of either library, right? 00:35:22.140 --> 00:35:24.740 The fact that Python has that one way to do things, 00:35:24.740 --> 00:35:27.660 and then the seven different ways to do string formatting 00:35:27.660 --> 00:35:28.780 conversation comes up. 00:35:28.780 --> 00:35:33.580 Then the fact that R is kind of like 00:35:36.020 --> 00:35:37.100 closer to the science. 00:35:37.100 --> 00:35:38.500 I don't know if that's even accurate, 00:35:38.500 --> 00:35:40.700 but that's the feeling I guess. 00:35:40.700 --> 00:35:42.060 It's also a strength, right? 00:35:42.060 --> 00:35:44.340 - Yeah, the reason there's lots and lots of libraries 00:35:44.340 --> 00:35:46.620 to do the same thing is 'cause they've each specialized 00:35:46.620 --> 00:35:49.220 in something which a new academic 00:35:49.220 --> 00:35:50.420 has just written a paper on. 00:35:50.420 --> 00:35:52.260 And that's why there's lots of different ways of doing it. 00:35:52.260 --> 00:35:53.100 - Yeah. 00:35:53.100 --> 00:35:53.920 - All right, sure. 00:35:53.920 --> 00:35:56.660 And maybe, you know, like out in the audience, 00:35:56.660 --> 00:35:59.500 the ninja says, "R is really powerful 00:35:59.500 --> 00:36:02.460 "when it comes to things like analytics and so on." 00:36:02.460 --> 00:36:05.100 So maybe there's certain areas where... 00:36:05.100 --> 00:36:06.260 - Yeah. 00:36:06.260 --> 00:36:07.780 - You know, there's the libraries you can pick, 00:36:07.780 --> 00:36:08.820 there's definitely better. 00:36:08.820 --> 00:36:10.940 Okay, now we talked about the book. 00:36:10.940 --> 00:36:12.340 The book also, as you pointed out, 00:36:12.340 --> 00:36:17.340 has an open version where you can find it on GitHub, 00:36:17.340 --> 00:36:20.480 which obviously we'll link to. 00:36:20.480 --> 00:36:23.440 And in here for each one of these, 00:36:23.440 --> 00:36:27.660 you've got some examples which are basically the, 00:36:27.660 --> 00:36:29.900 at least for the Python side, 00:36:29.900 --> 00:36:33.060 the Jupyter Notebook examples here. 00:36:33.060 --> 00:36:36.860 So I thought maybe we could sort of talk through a little bit 00:36:36.860 --> 00:36:39.460 of what is the problem and then, 00:36:39.460 --> 00:36:42.020 maybe really first quick, 00:36:42.020 --> 00:36:44.780 quickly introduce what this area is. 00:36:44.780 --> 00:36:49.540 And then we can talk about the problem, 00:36:49.540 --> 00:36:50.820 the example problem you put out there 00:36:50.820 --> 00:36:53.660 and some of the libraries and techniques there. 00:36:53.660 --> 00:36:54.500 - Sure. 00:36:54.500 --> 00:36:59.000 So the chapter two, which you're looking at right there, 00:36:59.860 --> 00:37:04.860 uses is about a mathematical concept called Markov chain. 00:37:04.860 --> 00:37:11.820 So it's this probability model that you loosely go that 00:37:11.820 --> 00:37:17.900 as the system changes over time, 00:37:17.900 --> 00:37:19.780 the system is in a particular state 00:37:19.780 --> 00:37:22.520 and then you go with a given probability 00:37:22.520 --> 00:37:24.260 of being in that state to another state 00:37:24.260 --> 00:37:26.780 and you can go around like that. 00:37:26.780 --> 00:37:28.380 That's not the best explanation I've ever given. 00:37:28.380 --> 00:37:32.140 I've explained that many times, that was probably one of my worst explanations. 00:37:32.140 --> 00:37:39.500 But Markov chains can be used to model queues. And there's a whole field of mathematics called 00:37:39.500 --> 00:37:45.980 queuing theory, and that is often used as a very applied problem. And so the problem we got here 00:37:45.980 --> 00:37:52.460 is, imagine you've got a barber, and the barber has kind of two decisions, how many chairs they 00:37:52.460 --> 00:38:00.660 have to cut hair in and how many chairs they have to keep people waiting for a chair. 00:38:00.660 --> 00:38:04.460 And obviously that has an impact on the queue, right, of how long people have to wait to 00:38:04.460 --> 00:38:05.900 get their hair cut. 00:38:05.900 --> 00:38:11.780 And you can use Markup Change to build up a model and find the probability of having 00:38:11.780 --> 00:38:14.100 to wait relatively simply. 00:38:14.100 --> 00:38:18.460 I don't know if you want to clean up what I just said. 00:38:18.460 --> 00:38:20.040 (laughing) 00:38:20.040 --> 00:38:21.400 - No, yeah, so I think, 00:38:21.400 --> 00:38:29.140 the model then would be the set of states 00:38:29.140 --> 00:38:31.180 and the probabilities of going between each states 00:38:31.180 --> 00:38:32.320 from the state you're in. 00:38:32.320 --> 00:38:35.140 And that can be written as a matrix. 00:38:35.140 --> 00:38:36.900 And the neat thing then is there's loads and loads 00:38:36.900 --> 00:38:38.460 of linear algebra techniques, 00:38:38.460 --> 00:38:41.660 which at this point you don't really need to know about, 00:38:41.660 --> 00:38:43.460 but there are linear algebra techniques, 00:38:43.460 --> 00:38:45.860 which stuff like NumPy can just do for you, 00:38:46.900 --> 00:38:49.060 which if you know which techniques to use, 00:38:49.060 --> 00:38:50.880 you know how to interpret that 00:38:50.880 --> 00:38:54.840 as a real life interpretation. 00:38:54.840 --> 00:38:57.960 So for example, there's one certain set of equations 00:38:57.960 --> 00:39:00.480 you can solve using our Markov chain, 00:39:00.480 --> 00:39:01.920 sorry, using our matrix, 00:39:01.920 --> 00:39:04.520 which will give you the long run probabilities 00:39:04.520 --> 00:39:05.760 of being in each state. 00:39:05.760 --> 00:39:08.520 There's another certain linear algebraic technique 00:39:08.520 --> 00:39:10.360 which will give you something else. 00:39:10.360 --> 00:39:12.040 And that's what this is. 00:39:12.040 --> 00:39:13.840 - Nice. 00:39:13.840 --> 00:39:16.760 - Yeah, the problem is essentially comes down 00:39:16.760 --> 00:39:19.800 of solving a matrix equation, 00:39:19.800 --> 00:39:21.420 which you can write down and understand 00:39:21.420 --> 00:39:23.780 with basic mathematical knowledge. 00:39:23.780 --> 00:39:26.260 And then that can be solved. 00:39:26.260 --> 00:39:27.580 This goes back to what you told me in high school, 00:39:27.580 --> 00:39:28.420 that matrices are great 00:39:28.420 --> 00:39:29.480 'cause computers can do them fast, 00:39:29.480 --> 00:39:30.820 but then you never actually get to do that. 00:39:30.820 --> 00:39:33.060 You just write down equations. 00:39:33.060 --> 00:39:35.340 But it's just a call to NumPy's, 00:39:35.340 --> 00:39:39.780 the NALS library can just solve it immediately for you. 00:39:39.780 --> 00:39:40.620 - It's amazing. 00:39:40.620 --> 00:39:43.700 Yeah, so the problem here to make this applied 00:39:43.700 --> 00:39:46.580 or more operational, I guess, 00:39:46.580 --> 00:39:48.780 that you all put out there says you have a barber shop 00:39:48.780 --> 00:39:52.060 and the shop notices that there's a lot of customers 00:39:52.060 --> 00:39:55.180 who are, they come and the shop is full 00:39:55.180 --> 00:39:57.000 and the waiting room is full and people just leave. 00:39:57.000 --> 00:40:00.540 And I, you know, since COVID I've just decided 00:40:00.540 --> 00:40:01.420 I'm cutting my own hair. 00:40:01.420 --> 00:40:03.940 I can't, it took too long to find a barber 00:40:03.940 --> 00:40:04.780 or anything that worked. 00:40:04.780 --> 00:40:05.940 And then after that, I kind of figured it out. 00:40:05.940 --> 00:40:07.880 But there used to be this place I would go to 00:40:07.880 --> 00:40:09.320 and boy, did it need this problem. 00:40:09.320 --> 00:40:10.780 It would be, you would go there 00:40:10.780 --> 00:40:13.100 and it'd be like an hour and a half wait. 00:40:13.100 --> 00:40:16.440 And you know, you just, all the time. 00:40:16.440 --> 00:40:20.200 And you never knew, so they would solve it by giving away free beer to people while they 00:40:20.200 --> 00:40:22.560 wait, which was nice. 00:40:22.560 --> 00:40:27.120 But this one wants to solve it more in a more formal business way where they would have 00:40:27.120 --> 00:40:28.800 people just wait less. 00:40:28.800 --> 00:40:33.360 So it says you have two barber chairs, there's room for four people in the waiting room, 00:40:33.360 --> 00:40:40.000 there's about 10 customers an hour, and it takes about 15 minutes to serve a customer. 00:40:40.000 --> 00:40:45.000 How can we minimize or how do we change things 00:40:45.000 --> 00:40:48.360 so that we don't have customers leaving 00:40:48.360 --> 00:40:50.040 'cause they come in and see a full waiting room 00:40:50.040 --> 00:40:51.080 and take off, right? 00:40:51.080 --> 00:40:53.040 Yeah. 00:40:53.040 --> 00:40:55.360 - So instead of knocking down a wall 00:40:55.360 --> 00:40:57.960 and building a bigger waiting room 00:40:57.960 --> 00:41:01.040 or spending a lot of money on an extra barber chair 00:41:01.040 --> 00:41:02.360 and just seeing the effect 00:41:02.360 --> 00:41:04.820 and maybe five years later trying the other way, 00:41:04.820 --> 00:41:06.740 you can just mathematically model this. 00:41:06.740 --> 00:41:08.040 And this is a good example of, I think, 00:41:08.040 --> 00:41:09.940 what we've described as applied mathematics 00:41:09.940 --> 00:41:13.660 so that you can answer these cool questions. 00:41:13.660 --> 00:41:14.500 - So you could say, 00:41:14.500 --> 00:41:16.460 well, maybe we need a bigger waiting room 00:41:16.460 --> 00:41:18.140 or maybe we need more barber chairs 00:41:18.140 --> 00:41:19.320 or something like that, right? 00:41:19.320 --> 00:41:22.060 And then you can make that trade off. 00:41:22.060 --> 00:41:25.620 Yeah, so let me find the, 00:41:25.620 --> 00:41:34.260 this is the numpy, numpy.linalg magic. 00:41:34.260 --> 00:41:35.660 And so basically you set it up 00:41:35.660 --> 00:41:39.860 so that you set up all these scenarios in these constraints 00:41:39.860 --> 00:41:43.660 And then you just say, "NumPy, solve it," right? 00:41:43.660 --> 00:41:45.220 - That's pretty much it, yeah. 00:41:45.220 --> 00:41:51.220 Mathematically, you write down this matrix A 00:41:51.220 --> 00:41:52.360 and another vector B, 00:41:52.360 --> 00:41:55.140 and you're solving an equation AX equals B. 00:41:55.140 --> 00:41:59.380 Most of the code is just getting the matrix set up 00:41:59.380 --> 00:42:00.740 and the B set up. 00:42:00.740 --> 00:42:03.100 Actually, most of the code is the doc strings. 00:42:03.100 --> 00:42:06.860 And then, yeah, you just use the linalg.leastSquares. 00:42:06.860 --> 00:42:08.900 That's one of many ways you can do it. 00:42:08.900 --> 00:42:12.980 least squares is actually getting an approximate solution 00:42:12.980 --> 00:42:16.280 to the linear algebraic equation. 00:42:16.280 --> 00:42:18.300 And there's various reasons why that's a better idea 00:42:18.300 --> 00:42:19.620 than solving it directly. 00:42:19.620 --> 00:42:22.680 And yeah, it's just basically one line. 00:42:22.680 --> 00:42:27.340 - Well, I think one of the neat things about this then 00:42:27.340 --> 00:42:30.660 is all that maths you sort of learn in school 00:42:30.660 --> 00:42:32.620 or even first year university where you're doing 00:42:32.620 --> 00:42:36.060 sort of row operations and stuff. 00:42:36.060 --> 00:42:38.660 That's not the mathematics that matters here. 00:42:38.660 --> 00:42:42.540 The mathematics of math is, what is the matrix you need to do that to? 00:42:42.540 --> 00:42:45.500 And once you've done it, how do you interpret the result? 00:42:45.500 --> 00:42:47.620 That is the mathematics. 00:42:47.620 --> 00:42:53.340 It's not the actual operations that you spent so long doing in first year university. 00:42:53.340 --> 00:42:56.220 That's such a good point, Garen. 00:42:56.220 --> 00:42:59.980 That's such a good point, Garen, because I think what is mathematics is an interesting 00:42:59.980 --> 00:43:00.980 question, right? 00:43:00.980 --> 00:43:05.460 And is it being able to differentiate a whole bunch of quadratics really fast? 00:43:05.460 --> 00:43:07.340 Or is it knowing which quadratic 00:43:07.340 --> 00:43:08.780 you need to differentiate, right? 00:43:08.780 --> 00:43:12.620 And I would argue that it is that, you know, 00:43:12.620 --> 00:43:15.700 it's knowing what, really knowing what the problem is 00:43:15.700 --> 00:43:17.380 so that, okay, then the actual specific 00:43:17.380 --> 00:43:20.020 mathematical technique, well, who cares, right? 00:43:20.020 --> 00:43:20.860 - Sure. 00:43:20.860 --> 00:43:22.740 Well, Vince, people so often say, 00:43:22.740 --> 00:43:24.340 oh, I'm never gonna use that. 00:43:24.340 --> 00:43:26.100 I'm never gonna do these things. 00:43:26.100 --> 00:43:28.460 I can do that with a calculator, or I can do that, 00:43:28.460 --> 00:43:30.980 you know, and I think a lot of that might be 00:43:30.980 --> 00:43:32.220 slightly misplaced. 00:43:32.220 --> 00:43:33.260 I'm not gonna say misplaced, 00:43:33.260 --> 00:43:37.300 a somewhat misplaced focus on some of these things, right? 00:43:37.300 --> 00:43:38.460 Like if you could say, well, 00:43:38.460 --> 00:43:40.700 spend a little time showing you how to differentiate, 00:43:40.700 --> 00:43:44.240 then we'll show you how to actually solve problems 00:43:44.240 --> 00:43:46.520 with that instead of just getting, you know, 00:43:46.520 --> 00:43:50.300 more and more complicated techniques that you can apply, 00:43:50.300 --> 00:43:52.780 I guess, integrations more of a pick and choose 00:43:52.780 --> 00:43:55.860 or I like to find which thing applies, but still, 00:43:55.860 --> 00:43:59.060 you know, instead of going deep, deep, deep, deep, 00:43:59.060 --> 00:44:02.260 deep into that on the first year stuff, yeah. 00:44:02.260 --> 00:44:03.100 - Yeah, absolutely. 00:44:03.100 --> 00:44:05.420 You had someone on the show a little while ago 00:44:05.420 --> 00:44:06.660 called Allen Downey. 00:44:06.660 --> 00:44:07.660 - Yeah. 00:44:07.660 --> 00:44:11.180 - And he writes a lot of really great books. 00:44:11.180 --> 00:44:15.100 And I remember what he said on your show was about, 00:44:15.100 --> 00:44:17.560 he likes to think of teaching these things in the other way 00:44:17.560 --> 00:44:19.740 that code allows you to do these things immediately. 00:44:19.740 --> 00:44:22.540 So instead of waiting through and waiting 00:44:22.540 --> 00:44:25.440 and having to have faith that there's gonna be used to it, 00:44:25.440 --> 00:44:27.420 you can just flip that around, you know, 00:44:27.420 --> 00:44:29.260 and understand what it is. 00:44:29.260 --> 00:44:30.660 I think there's also a lot of that 00:44:30.660 --> 00:44:33.380 in what we should be doing. 00:44:33.380 --> 00:44:34.460 - Yeah, that's a very good point. 00:44:34.460 --> 00:44:36.060 I totally agree. 00:44:36.060 --> 00:44:37.500 All right, wrap this one up. 00:44:37.500 --> 00:44:40.340 You were able to find that it would be better 00:44:40.340 --> 00:44:42.460 to increase the number of barbers by one 00:44:42.460 --> 00:44:46.220 than increase the waiting room capacity by two. 00:44:46.220 --> 00:44:48.060 'Cause I think the chance of the shop being full 00:44:48.060 --> 00:44:50.660 is like 23% if you had-- 00:44:50.660 --> 00:44:51.980 - Something like that, yeah. 00:44:51.980 --> 00:44:55.180 - Yeah, yeah, versus like 8%, you know, 00:44:55.180 --> 00:44:56.020 those kinds of things. 00:44:56.020 --> 00:44:57.580 And those are really concrete numbers 00:44:57.580 --> 00:45:00.500 that you could go to a business and say, 00:45:00.500 --> 00:45:02.840 you hired us to analyze these things. 00:45:02.840 --> 00:45:04.780 We gathered all the necessary information 00:45:04.780 --> 00:45:08.420 like average time, how much that might vary 00:45:08.420 --> 00:45:10.020 and those kinds of things. 00:45:10.020 --> 00:45:11.180 And here are your choices 00:45:11.180 --> 00:45:14.060 and here are what are the rough expected outcomes. 00:45:14.060 --> 00:45:17.620 Like that's really, really valuable information. 00:45:17.620 --> 00:45:22.620 And I am very sure that most barbershops 00:45:22.620 --> 00:45:25.380 even chains don't do this kind of analysis. 00:45:25.380 --> 00:45:27.180 - Not enough linear algebra going on in barbershops. 00:45:27.180 --> 00:45:29.340 That's an interest, that's a bold thing. 00:45:29.340 --> 00:45:31.840 - I know. (laughs) 00:45:31.840 --> 00:45:36.580 - And this question, so a lot of the research 00:45:36.580 --> 00:45:38.220 Geraint and I do is within healthcare. 00:45:38.220 --> 00:45:40.940 So we work with hospitals solving essentially 00:45:40.940 --> 00:45:43.580 very similar problems to the one that we've just discussed. 00:45:43.580 --> 00:45:46.320 We're keen to avoid too much healthcare 00:45:46.320 --> 00:45:47.920 because that's what we do so much of. 00:45:47.920 --> 00:45:52.660 But yeah, if you get rid of the idea of a barber shop, 00:45:52.660 --> 00:45:54.740 you talk about a ward, how many beds are on the ward, 00:45:54.740 --> 00:45:57.380 how big's the parking lot for ambulances to wait in, 00:45:57.380 --> 00:46:00.260 et cetera, et cetera, that becomes very important 00:46:00.260 --> 00:46:04.860 and very powerful and not something you need to spend 00:46:04.860 --> 00:46:09.220 thousands of pounds or dollars on licenses for, 00:46:09.220 --> 00:46:13.020 not necessarily even have a huge understanding 00:46:13.020 --> 00:46:14.620 of underlying mathematics. 00:46:14.620 --> 00:46:15.700 It's all right there. 00:46:15.700 --> 00:46:18.260 It's all right there available to anyone. 00:46:18.260 --> 00:46:20.500 - Yeah, but there's way more at stake 00:46:20.500 --> 00:46:24.300 in a hospital and healthcare than there is for-- 00:46:24.300 --> 00:46:25.580 - Of course, of course. 00:46:25.580 --> 00:46:26.900 - A haircut. - Of course. 00:46:26.900 --> 00:46:28.900 - Yeah, of course. 00:46:28.900 --> 00:46:33.180 - Okay, let's go on to the next one. 00:46:33.180 --> 00:46:36.780 So the next topic is discrete events. 00:46:36.780 --> 00:46:39.640 So I'll find my way over to that one. 00:46:39.640 --> 00:46:47.020 And you'll introduce this one, discrete event simulation. 00:46:47.020 --> 00:46:49.220 This sounds like this might be somewhat 00:46:49.220 --> 00:46:51.460 in your wheelhouse, Garin. 00:46:51.460 --> 00:46:56.460 - Yeah, so I think discrete event simulation 00:46:56.580 --> 00:46:59.620 is probably, if you're used to programming, 00:46:59.620 --> 00:47:01.940 this is probably the one that probably makes the most sense 00:47:01.940 --> 00:47:04.620 because it's moving virtual things 00:47:04.620 --> 00:47:06.620 around the place essentially. 00:47:06.620 --> 00:47:07.460 - Yeah. 00:47:07.460 --> 00:47:11.180 - So the question we're asking here 00:47:11.180 --> 00:47:12.940 is very similar to the question 00:47:12.940 --> 00:47:16.180 we just answered with Markov chains. 00:47:16.180 --> 00:47:19.220 But sometimes things are too complicated 00:47:19.220 --> 00:47:21.900 to be able to formulate that correct matrix 00:47:21.900 --> 00:47:23.420 or the matrix doesn't quite work 00:47:23.420 --> 00:47:26.100 because the situation is a bit too complicated. 00:47:26.100 --> 00:47:30.140 But what we can do is build a virtual representation 00:47:30.140 --> 00:47:31.460 of our system. 00:47:31.460 --> 00:47:34.060 And by sampling random numbers, 00:47:34.060 --> 00:47:37.500 we can move virtual people around that barbershop 00:47:37.500 --> 00:47:41.580 and look at what would happen, right? 00:47:41.580 --> 00:47:44.900 Just observe, collect data, crunch that data. 00:47:44.900 --> 00:47:47.060 And this is what discrete event simulation is. 00:47:47.060 --> 00:47:49.900 It's building a virtual representation of the system, 00:47:49.900 --> 00:47:52.340 using random numbers to play 00:47:52.340 --> 00:47:54.220 that virtual representation system, 00:47:54.220 --> 00:47:58.620 and then collect some data about what just happened virtually. 00:47:58.620 --> 00:47:59.120 Right. 00:47:59.120 --> 00:47:59.740 OK, excellent. 00:47:59.740 --> 00:48:01.780 So this one-- let me set the problem that you all 00:48:01.780 --> 00:48:02.420 laid out here. 00:48:02.420 --> 00:48:05.140 This is a bicycle repair shop. 00:48:05.140 --> 00:48:10.380 And there's a set of gates or actions or, I guess, 00:48:10.380 --> 00:48:15.220 events, you might say, that it flows through. 00:48:15.220 --> 00:48:22.020 So a bike arrives randomly at a rate of 15 bikes per hour. 00:48:22.020 --> 00:48:23.660 They show up and they say, hey, there's 00:48:23.660 --> 00:48:25.100 something wrong with my bike. 00:48:25.100 --> 00:48:29.180 And the staff member looks at it and helps them. 00:48:29.180 --> 00:48:31.060 That takes about three minutes. 00:48:31.060 --> 00:48:32.900 But it turns out about 20% of the time, 00:48:32.900 --> 00:48:33.980 the bikes don't need repair. 00:48:33.980 --> 00:48:35.660 There's like, did you know that there's a thing 00:48:35.660 --> 00:48:36.900 to just twist here and tighten it? 00:48:36.900 --> 00:48:38.140 All right, go away. 00:48:38.140 --> 00:48:39.900 You're fixed, you're cured. 00:48:39.900 --> 00:48:41.700 But 80% of the time, there's something wrong, 00:48:41.700 --> 00:48:43.980 flat tire, broken chain, whatever. 00:48:43.980 --> 00:48:47.100 And that gets put into a place 00:48:47.100 --> 00:48:48.420 where they're waiting to work on it. 00:48:48.420 --> 00:48:50.580 And that takes about six minutes, right? 00:48:50.580 --> 00:48:51.940 And then you've got to collect it back. 00:48:51.940 --> 00:48:59.040 The question is, I guess the difference that I see here is there's not an uncertainty of 00:48:59.040 --> 00:49:02.400 whether or not you want a haircut when you show up at a barbershop. 00:49:02.400 --> 00:49:05.880 There's just amount of time and where the people are and actions they might take if 00:49:05.880 --> 00:49:06.880 it's too full. 00:49:06.880 --> 00:49:11.520 But here you may show up and you may need help or you may not need help and so on. 00:49:11.520 --> 00:49:13.680 So is that the difference? 00:49:13.680 --> 00:49:20.640 >> I suppose that is the difference between these two problems. 00:49:20.640 --> 00:49:24.640 but that's not the reason we would use simulation over Markov chains. 00:49:24.640 --> 00:49:32.800 In fact, the situation we're looking at here could be formulated as a Markov chain. 00:49:32.800 --> 00:49:36.640 The difference I see is that in this situation, 00:49:36.640 --> 00:49:39.680 you could have an infinite amount of bicycles in your bicycle shop. 00:49:39.680 --> 00:49:45.200 So if we were to formulate that as a Markov chain, we'd have an infinite matrix, 00:49:45.200 --> 00:49:47.360 which is not terrible to deal with, 00:49:47.360 --> 00:49:49.520 but you wouldn't be able to deal with it in the way we just did. 00:49:49.520 --> 00:49:52.040 - Got it, okay. 00:49:52.040 --> 00:49:52.880 - Yeah. 00:49:52.880 --> 00:49:54.880 - There's also, sorry, Gary. 00:49:54.880 --> 00:49:56.360 - No, go on. 00:49:56.360 --> 00:49:58.840 - There's also, talking about the states 00:49:58.840 --> 00:50:02.200 that I did kind of awkwardly in the previous chapter, 00:50:02.200 --> 00:50:04.920 it's just how many people are in the shop. 00:50:04.920 --> 00:50:06.580 So there's three people in the shop. 00:50:06.580 --> 00:50:08.200 Well, there's a probability that the next thing 00:50:08.200 --> 00:50:09.940 that happens is four, or the probability 00:50:09.940 --> 00:50:11.360 that the next thing that happens is two. 00:50:11.360 --> 00:50:16.360 So it's a very straightforward set of states 00:50:16.360 --> 00:50:18.160 that is finite, as Garen said. 00:50:18.160 --> 00:50:21.540 Here, there's two things to keep track of. 00:50:21.540 --> 00:50:23.920 There's the number of bikes waiting to be seen 00:50:23.920 --> 00:50:25.320 by the inspector, the number of bikes waiting 00:50:25.320 --> 00:50:26.760 to be seen by the repair shop. 00:50:26.760 --> 00:50:29.560 And that just immediately, the fact that now you've got 00:50:29.560 --> 00:50:32.020 these two dimensions that can change, 00:50:32.020 --> 00:50:34.000 just again adds to the complexity and the fact 00:50:34.000 --> 00:50:35.400 that it's an amount of them. 00:50:35.400 --> 00:50:38.060 - Yeah, okay. 00:50:38.060 --> 00:50:38.900 - Yeah. 00:50:38.900 --> 00:50:42.140 - So the reason we would use, no. 00:50:42.140 --> 00:50:44.760 So the reason we would use simulation for this 00:50:44.760 --> 00:50:47.800 is because it's a more complicated situation 00:50:47.800 --> 00:50:51.040 for a variety of reasons than what we had before. 00:50:51.040 --> 00:50:53.980 It would take a really, really big, 00:50:53.980 --> 00:50:56.680 if not infinite matrix to be able to solve this. 00:50:56.680 --> 00:50:58.960 So why would we go to that effort 00:50:58.960 --> 00:51:00.400 when we can get quick, easy answers 00:51:00.400 --> 00:51:02.820 just by virtually playing the system? 00:51:02.820 --> 00:51:04.920 - Right. 00:51:04.920 --> 00:51:07.480 - And these two chapters are paired. 00:51:07.480 --> 00:51:08.920 Sorry, Michael, I'm, please. 00:51:08.920 --> 00:51:10.920 - No, please go. 00:51:10.920 --> 00:51:12.480 - These two chapters are paired, 00:51:12.480 --> 00:51:14.400 and actually there's this, 00:51:14.400 --> 00:51:16.640 all the chapters are paired in the book 00:51:16.640 --> 00:51:23.880 the reason that they are kind of the two similar types of problems from opposite angles and 00:51:23.880 --> 00:51:27.360 correct me, Garen, if you don't agree, but I think that the two opposite angles about 00:51:27.360 --> 00:51:35.640 numerical tractability, how much you can do with an exact method, which is what the previous 00:51:35.640 --> 00:51:41.080 chapter was, versus a more approximative method. 00:51:41.080 --> 00:51:44.600 And it's not always easy to say exactly what you should use one or the other. 00:51:44.600 --> 00:51:47.520 Sometimes it's absolutely clear, but sometimes it's not. 00:51:47.520 --> 00:51:52.240 But there's these pairs of chapters that kind of reflect the size of the problem, for want 00:51:52.240 --> 00:51:53.920 of a better word. 00:51:53.920 --> 00:51:54.920 Very interesting. 00:51:54.920 --> 00:52:01.920 Okay, the fundamental Python bit here is the CIW, or you pronounce that Q? 00:52:01.920 --> 00:52:05.920 Yeah, I call that Q. 00:52:05.920 --> 00:52:10.680 CIW, Q, it's the Welsh word for Q, Q-U-E-U-E. 00:52:10.680 --> 00:52:14.480 It's the Welsh word for that, and that's why I call it the library, though. 00:52:14.480 --> 00:52:16.280 - Yeah, fantastic. 00:52:16.280 --> 00:52:19.160 All right, and so the idea is basically 00:52:19.160 --> 00:52:23.400 you state the problem in terms of 00:52:23.400 --> 00:52:25.520 the arrival rate of events, 00:52:25.520 --> 00:52:29.280 the inspection or the service distributions 00:52:29.280 --> 00:52:31.880 in terms of how those flow through there, 00:52:31.880 --> 00:52:33.960 the number of things that can be servicing it, 00:52:33.960 --> 00:52:35.560 and the routing and so on. 00:52:35.560 --> 00:52:40.160 You create a network with the Q library 00:52:40.160 --> 00:52:45.120 and then you could just ask it questions, right? 00:52:45.120 --> 00:52:48.360 You can tell it to run a simulation, 00:52:48.360 --> 00:52:50.820 you can run it for some amount of time, 00:52:50.820 --> 00:52:53.220 like eight seconds or so on. 00:52:53.220 --> 00:52:57.380 And it's interesting that it simulates it, 00:52:57.380 --> 00:53:00.180 that it doesn't exactly solve it, right? 00:53:00.180 --> 00:53:06.260 - Yeah, so that's the point of simulation, 00:53:06.260 --> 00:53:08.920 not the point, but like one of the uses of simulation 00:53:08.920 --> 00:53:12.760 is that we can quite easily simulate something 00:53:12.760 --> 00:53:15.800 that's too complicated to solve exactly, 00:53:15.800 --> 00:53:17.760 or would take too long to solve exactly, 00:53:17.760 --> 00:53:19.600 but we can quite easily simulate it. 00:53:19.600 --> 00:53:21.680 The trade-off then is, 00:53:21.680 --> 00:53:23.920 because assimilation is essentially 00:53:23.920 --> 00:53:26.320 streams of random numbers that we do things to, 00:53:26.320 --> 00:53:30.920 you could get extreme values, you could get flukes. 00:53:30.920 --> 00:53:35.920 So you lose accuracy, but you gain efficiency. 00:53:37.680 --> 00:53:40.320 Yeah, so the idea is you run it over and over and over again 00:53:40.320 --> 00:53:44.680 with the randomness playing out there. 00:53:44.680 --> 00:53:47.640 And then you just say, well, what is the most common set 00:53:47.640 --> 00:53:50.800 of outcomes look like? 00:53:50.800 --> 00:53:52.480 Yeah, yeah, essentially, yeah. 00:53:52.480 --> 00:53:55.120 Nice. 00:53:55.120 --> 00:53:55.960 Very cool. 00:53:55.960 --> 00:53:58.040 So what did we learn from this one? 00:53:58.040 --> 00:54:04.440 That we could add an extra inspector at the front, 00:54:04.440 --> 00:54:08.000 or we could add an extra repairer. 00:54:08.000 --> 00:54:11.160 And what was the better outcome here? 00:54:11.160 --> 00:54:15.720 - So we were measuring was the maximum amount of time 00:54:15.720 --> 00:54:17.920 a bicycle spends in the shop. 00:54:17.920 --> 00:54:20.480 We wanted to get bicycles out as quick as possible. 00:54:20.480 --> 00:54:25.480 So if we added an extra bicycle inspector, 00:54:25.480 --> 00:54:29.400 we would reduce our time, 00:54:29.400 --> 00:54:31.240 maximum time in the shop by quite a lot. 00:54:31.240 --> 00:54:33.840 But if we added an extra repairer, 00:54:33.840 --> 00:54:36.000 we'd reduce it, but not quite so much. 00:54:36.000 --> 00:54:37.740 So we essentially found that the bottleneck 00:54:37.740 --> 00:54:40.140 was the inspection desk and not the repairing. 00:54:40.140 --> 00:54:42.060 - How interesting. 00:54:42.060 --> 00:54:44.940 And I suspect, maybe this is not true, 00:54:44.940 --> 00:54:47.440 but I feel like if I was a business, 00:54:47.440 --> 00:54:50.420 knowing that would not just help me hire the right person, 00:54:50.420 --> 00:54:53.680 but I think having an inspector type of person 00:54:53.680 --> 00:54:55.960 would be easier to get, right? 00:54:55.960 --> 00:54:58.480 You don't have to have as great of a skillset 00:54:58.480 --> 00:55:02.120 to actually be the mechanic that does the repairs. 00:55:02.120 --> 00:55:07.120 So that's really valuable as somebody who runs a bike shop. 00:55:07.120 --> 00:55:10.120 I will also throw out another statement here 00:55:10.120 --> 00:55:11.360 that's probably true. 00:55:11.360 --> 00:55:15.080 I also suspect bike shops don't employ these techniques 00:55:15.080 --> 00:55:15.920 but should. 00:55:15.920 --> 00:55:18.500 (all laughing) 00:55:18.500 --> 00:55:21.560 - Oh, they can now. 00:55:21.560 --> 00:55:23.860 - They can, well, and they can now, honestly. 00:55:23.860 --> 00:55:27.920 - I believe larger companies probably would. 00:55:27.920 --> 00:55:30.640 Stuff like supermarkets and airports probably would 00:55:30.640 --> 00:55:34.080 a team of people behind them doing this, but smaller shops probably not. 00:55:34.080 --> 00:55:38.560 Yeah. Oh gosh, I don't remember the name. 00:55:38.560 --> 00:55:45.360 Not always, right, would be a little caveat. We certainly know of lots of examples of big 00:55:45.360 --> 00:55:53.680 entities, companies, things that make very expensive decisions without doing these sorts of 00:55:53.680 --> 00:55:57.040 investigations. Yeah. 00:55:57.040 --> 00:56:01.080 - Yeah, well, you mentioned grocery stores and stuff. 00:56:01.080 --> 00:56:05.240 I had the folks from Kroger, which I think, if not, 00:56:05.240 --> 00:56:09.000 is the largest, one of the largest chains in the US. 00:56:09.000 --> 00:56:12.300 They have basically an analytics and data science 00:56:12.300 --> 00:56:15.320 subsidiary called 8451. 00:56:15.320 --> 00:56:19.440 They employ 200 data scientists who do R and Python. 00:56:19.440 --> 00:56:24.520 That's not joking around in terms of, 00:56:24.520 --> 00:56:25.780 where do the bananas go? 00:56:26.760 --> 00:56:28.680 Yeah, all those types of things, right? 00:56:28.680 --> 00:56:28.880 There. 00:56:28.880 --> 00:56:29.840 So you're right. 00:56:29.840 --> 00:56:33.120 The larger companies definitely, definitely invest in that. 00:56:33.120 --> 00:56:38.400 It's interesting thing about what is data science, right? 00:56:38.400 --> 00:56:43.600 So my data scientists, in that, are they looking at historic 00:56:43.600 --> 00:56:46.760 data and identifying things? 00:56:46.760 --> 00:56:50.000 And I suspect there's no answer to my question here as well. 00:56:50.000 --> 00:56:52.200 I suspect different data scientists do different things. 00:56:52.200 --> 00:56:56.120 Um, but when you hear a data science department, that doesn't necessarily 00:56:56.120 --> 00:57:03.080 mean they're doing this type of work? It might be, absolutely might be. But they might be diving 00:57:03.080 --> 00:57:08.600 into the data and understanding and observing as opposed to necessarily modeling. It's possible. 00:57:08.600 --> 00:57:16.120 Right. It could be AI, it could be AI and ML, it could be data ETL, just bringing in data, 00:57:16.120 --> 00:57:21.160 just getting into system. Yeah, there's all these different aspects. I wonder more about the data 00:57:21.160 --> 00:57:31.640 science on when do I go from being somebody that uses say Python for computation to becoming a data 00:57:31.640 --> 00:57:37.160 science right when do I where would you cross the boundary from being a mathematician or a biologist 00:57:37.160 --> 00:57:44.600 to becoming a data scientist that has some understanding of biology for example. I would 00:57:44.600 --> 00:57:48.440 argue it kind of goes back to what we were saying earlier about what is an applied mathematician and 00:57:48.440 --> 00:57:51.280 And at what point are these labels helpful 00:57:51.280 --> 00:57:53.540 and at what point are they not, right? 00:57:53.540 --> 00:57:55.920 - Yeah, yeah, exactly. 00:57:55.920 --> 00:57:57.840 Out in the audience, 00:57:57.840 --> 00:57:59.360 Preetam says, "Yeah, data science 00:57:59.360 --> 00:58:00.880 is such a catch-all phrase right now." 00:58:00.880 --> 00:58:02.480 I would agree, also a buzzword. 00:58:02.480 --> 00:58:03.760 So if you're looking for a job, 00:58:03.760 --> 00:58:05.680 so it's a good one to employ for that. 00:58:05.680 --> 00:58:06.520 All right. 00:58:06.520 --> 00:58:08.720 Let's go on to another one. 00:58:08.720 --> 00:58:10.880 We'll get through as many of these as we can. 00:58:10.880 --> 00:58:13.360 And then we have time for anyway. 00:58:13.360 --> 00:58:18.360 So those two problem areas were paired together. 00:58:18.360 --> 00:58:19.200 - Yeah. 00:58:19.200 --> 00:58:20.400 - The next area that you focused on 00:58:20.400 --> 00:58:24.280 is fairly different with differential equations. 00:58:24.280 --> 00:58:27.000 - Yeah, so those two areas that we were just in, 00:58:27.000 --> 00:58:29.520 the book's got parts and there's two chapters in every part 00:58:29.520 --> 00:58:31.020 and that was in the probabilistic modeling 00:58:31.020 --> 00:58:31.860 is what we'd call it, 00:58:31.860 --> 00:58:34.520 modeling these probabilistic type situations. 00:58:34.520 --> 00:58:37.400 And here in the dynamical systems section 00:58:37.400 --> 00:58:39.100 and so specifically here, 00:58:39.100 --> 00:58:40.080 we're looking at a problem 00:58:40.080 --> 00:58:42.400 where differential equations can be used. 00:58:42.400 --> 00:58:45.040 And we wrote, we started writing this book 00:58:46.120 --> 00:58:50.000 before the world changed, before COVID. 00:58:50.000 --> 00:58:55.120 And I remember coming into one of our writing sessions, 00:58:55.120 --> 00:58:57.440 I have to say I really enjoyed writing the book. 00:58:57.440 --> 00:59:00.320 Very glad to have it finished, but I enjoyed writing the book 00:59:00.320 --> 00:59:02.160 and I said to Garren, Garren, 00:59:02.160 --> 00:59:04.280 do we need to change this chapter? 00:59:04.280 --> 00:59:08.080 Because this chapter is, there's a disease going around, 00:59:08.080 --> 00:59:09.460 I think we call it a cold. 00:59:09.460 --> 00:59:13.400 Yeah, everyone's caught a cold in a small community. 00:59:13.400 --> 00:59:14.240 There's a cost to not being able to work. 00:59:14.240 --> 00:59:16.000 - It's a point now to have a cold. 00:59:16.000 --> 00:59:16.840 Right? 00:59:16.840 --> 00:59:19.040 And the cost, financial cost associated 00:59:19.040 --> 00:59:20.720 with not being able to work, 00:59:20.720 --> 00:59:23.840 financial costs with a possible cure 00:59:23.840 --> 00:59:26.880 that would double the rate at which you get better 00:59:26.880 --> 00:59:28.320 from the cure. 00:59:28.320 --> 00:59:30.600 Is it worth, from the cold, pardon me, 00:59:30.600 --> 00:59:35.600 is it worth financially to get this cure was the problem. 00:59:35.600 --> 00:59:39.960 And yeah, we were like, should we make this about COVID? 00:59:39.960 --> 00:59:43.280 You know, should we just essentially all the graphs 00:59:43.280 --> 00:59:45.300 we spent so long looking at that was on the news 00:59:45.300 --> 00:59:52.500 the time, this is it. This is essentially the same thing. Should we make it about COVID? 00:59:52.500 --> 01:00:00.420 We decided not to, didn't we, Garry? We decided to just keep it somewhat abstract. But yeah, 01:00:00.420 --> 01:00:10.940 that's the problem here. And the model is a textbook, for want of a better word, a textbook 01:00:10.940 --> 01:00:16.860 model that's often taught when you start learning about systems of differential equations called 01:00:16.860 --> 01:00:25.420 the SIR model. And the SIR model has a population in three groups, susceptible people. 01:00:25.420 --> 01:00:28.220 Sorry, Vint, I think you're talking about a different chapter. 01:00:28.220 --> 01:00:34.060 I am talking about the wrong chapter. Thank you. Sorry, I went off on that one. Thank you. 01:00:34.060 --> 01:00:35.180 That's the next chapter. 01:00:35.180 --> 01:00:38.700 They're similar. Yeah, they're similar. 01:00:38.700 --> 01:00:39.980 Very similar. 01:00:39.980 --> 01:00:44.980 - This one, you can write down a differential equation 01:00:44.980 --> 01:00:47.440 that dictates not a system, 01:00:47.440 --> 01:00:50.240 but just the number of people that are infected over time. 01:00:50.240 --> 01:00:52.240 And so you can write that down, that differential equation, 01:00:52.240 --> 01:00:54.140 you can get a solution for it. 01:00:54.140 --> 01:00:57.640 Sorry, thank you, Geraint, thank you. 01:00:57.640 --> 01:01:01.160 - Yeah, no worries. 01:01:01.160 --> 01:01:03.560 This one actually uses an interesting library 01:01:03.560 --> 01:01:06.460 that I am just fascinated with. 01:01:06.460 --> 01:01:07.660 - Awesome library, yeah. 01:01:08.840 --> 01:01:12.240 - Yeah, I just had the folks on back in May, 01:01:12.240 --> 01:01:13.960 not too long ago for this one, 01:01:13.960 --> 01:01:17.440 Andre and Aaron for this. 01:01:17.440 --> 01:01:21.440 I did not expect this from Python 01:01:21.440 --> 01:01:25.040 because I expected NumPy 01:01:25.040 --> 01:01:27.720 and the linear algebra type things, 01:01:27.720 --> 01:01:32.560 but not, here's the integral of this solution 01:01:32.560 --> 01:01:34.200 of this differential equation. 01:01:34.200 --> 01:01:36.200 And here were the steps that I took to get there. 01:01:36.200 --> 01:01:37.080 It is so neat. 01:01:37.960 --> 01:01:41.040 SimPy is an incredible library that just gives you 01:01:41.040 --> 01:01:43.840 so much of what in mathematics is thought 01:01:43.840 --> 01:01:45.200 to have to be commercial 01:01:45.200 --> 01:01:48.440 in that you can have all your symbolic stuff. 01:01:48.440 --> 01:01:51.840 So, if you wanna know what is X plus X, 01:01:51.840 --> 01:01:55.880 you don't need to tell the computer what value X has. 01:01:55.880 --> 01:01:58.480 With SimPy, the computer can just understand the concept 01:01:58.480 --> 01:02:01.680 that X is this mathematical idea, and it's incredible. 01:02:01.680 --> 01:02:04.400 And it's a fantastic, fantastic library. 01:02:04.400 --> 01:02:09.400 I think it was when I started teaching programming 01:02:09.400 --> 01:02:11.940 through our first year cohort, 01:02:11.940 --> 01:02:13.560 I actually taught SageMath 01:02:13.560 --> 01:02:15.240 and SageMath is built on top of SimPy. 01:02:15.240 --> 01:02:19.320 But at some point I decided to just teach with SimPy. 01:02:19.320 --> 01:02:20.440 And so that's what we use here. 01:02:20.440 --> 01:02:21.280 That's what we use here. 01:02:21.280 --> 01:02:25.560 We build up the actual numeric solution 01:02:25.560 --> 01:02:26.640 for the differential equations. 01:02:26.640 --> 01:02:29.320 We find the expression that if you put it 01:02:29.320 --> 01:02:31.160 into this differential equation, 01:02:31.160 --> 01:02:34.320 that would be the solution. 01:02:34.320 --> 01:02:36.080 So again, the exact solution here. 01:02:36.080 --> 01:02:38.840 - Yeah. 01:02:38.840 --> 01:02:39.760 It's pretty wild. 01:02:39.760 --> 01:02:42.420 You say, the way you set it up, 01:02:42.420 --> 01:02:44.160 I mean, everything about Senpai is wild, 01:02:44.160 --> 01:02:47.040 but the way you set it up here is you say, 01:02:47.040 --> 01:02:51.320 I'm gonna create some symbols like time T 01:02:51.320 --> 01:02:54.860 or a constant alpha or so on, or initial conditions. 01:02:54.860 --> 01:02:56.280 And then you say, I'm gonna have a function. 01:02:56.280 --> 01:02:57.360 You don't say what the function is. 01:02:57.360 --> 01:03:00.120 You say there is a function called I. 01:03:00.120 --> 01:03:03.240 And then what you define for the thing you're going to work with is you say, 01:03:03.240 --> 01:03:06.200 uh, sim dot equation. 01:03:06.200 --> 01:03:10.920 And you say the equation is going to be given the derivative of this function 01:03:10.920 --> 01:03:13.920 and, of T and T. 01:03:13.920 --> 01:03:16.600 And then it has this, this expression in there. 01:03:16.600 --> 01:03:16.940 Negative. 01:03:16.940 --> 01:03:20.560 I guess that's probably the, you, what you're specifying here is this is the 01:03:20.560 --> 01:03:25.040 derivative, not the equation itself, which is negative alpha times I have T. 01:03:25.040 --> 01:03:25.320 Right. 01:03:26.080 --> 01:03:31.300 This is one of those parts of SymPy that when we teach this to our first years, it allows 01:03:31.300 --> 01:03:35.880 us to help identify misunderstandings about the mathematics. 01:03:35.880 --> 01:03:40.760 I think programming can often help you understand mathematics better and likewise and vice versa, 01:03:40.760 --> 01:03:47.100 but people often come to study mathematics and don't know the difference between a formula 01:03:47.100 --> 01:03:49.680 and an equation, and an equation has two sides. 01:03:49.680 --> 01:03:52.200 An equation has an equal side in the middle. 01:03:52.200 --> 01:03:58.680 And so what you're creating here is sim.eq takes two variables, a left-hand side and 01:03:58.680 --> 01:03:59.680 a right-hand side. 01:03:59.680 --> 01:04:01.240 That's actually the name of the parameters. 01:04:01.240 --> 01:04:03.880 So the left-hand side is the derivative of i. 01:04:03.880 --> 01:04:10.400 So it's saying that the speed at which the number of infected people changes over time, 01:04:10.400 --> 01:04:14.360 that's the left-hand side of your equation, is equal to, and then the right-hand side 01:04:14.360 --> 01:04:19.760 of your equation, some constant alpha minus some constant alpha, sorry, times the number. 01:04:19.760 --> 01:04:21.240 So the speed is related to the number. 01:04:21.240 --> 01:04:25.240 And that's really the relationship that defines the differential equations. 01:04:25.240 --> 01:04:26.240 Right. 01:04:26.240 --> 01:04:31.480 And in this scenario, you can change the alpha, the rate of recovery by providing medicine 01:04:31.480 --> 01:04:35.240 or just letting people do their thing, you know? 01:04:35.240 --> 01:04:37.240 Naturally recover, yes. 01:04:37.240 --> 01:04:38.800 Yeah, yeah, exactly. 01:04:38.800 --> 01:04:42.560 So in here you say, you know, given these constants, we're going to, you know, get the 01:04:42.560 --> 01:04:45.240 equation and then you solve it. 01:04:45.240 --> 01:04:50.240 You come up with the actual symbolic solution, which is always, always blows my mind. 01:04:50.240 --> 01:04:52.180 - And then when you say sim.dsolve, 01:04:52.180 --> 01:04:54.980 like does that solve the differential equation? 01:04:54.980 --> 01:04:56.180 I'm guessing you give it the equation 01:04:56.180 --> 01:04:58.260 and the initial conditions and stuff, 01:04:58.260 --> 01:05:01.320 and you're like, where the initial condition is, 01:05:01.320 --> 01:05:06.980 we defined a function i, we didn't say what it is, really. 01:05:06.980 --> 01:05:09.740 What we said at zero, it's the initial condition 01:05:09.740 --> 01:05:10.900 of like how many people are sick 01:05:10.900 --> 01:05:13.420 or whatever that turned out to be, which is just amazing. 01:05:13.420 --> 01:05:14.660 - All of which is simple. 01:05:14.660 --> 01:05:16.340 Everything here is just an idea. 01:05:16.340 --> 01:05:17.580 Nothing's a number. 01:05:17.580 --> 01:05:18.420 Everything is just an idea. 01:05:18.420 --> 01:05:20.300 - Yeah, yeah, we don't know anything about it. 01:05:20.300 --> 01:05:23.580 We just know that these are the constraints of the equation 01:05:23.580 --> 01:05:28.380 and out it gives you, let's see. 01:05:28.380 --> 01:05:34.260 You get the solution and it says an equation. 01:05:34.260 --> 01:05:35.900 Let's see, I gotta go further down. 01:05:35.900 --> 01:05:36.740 - So that's it. 01:05:36.740 --> 01:05:38.860 - Yeah, so it gives you the actual solution 01:05:38.860 --> 01:05:40.740 and then you start plugging in like the numbers, 01:05:40.740 --> 01:05:43.820 the different conditions and it gives you the answers, right? 01:05:43.820 --> 01:05:45.140 - Exactly. 01:05:45.140 --> 01:05:47.740 - Yeah, you plug in the numbers at the end. 01:05:47.740 --> 01:05:49.420 - Yeah. 01:05:49.420 --> 01:05:53.400 So we get the cost if you were to purchase the cure 01:05:53.400 --> 01:05:57.300 would be 700 and the cost without purchasing the cure 01:05:57.300 --> 01:05:58.140 would be 500. 01:05:58.140 --> 01:06:01.060 And since the overall costing into account productivity 01:06:01.060 --> 01:06:04.620 offsetting all the impacts of, you know, 01:06:04.620 --> 01:06:06.900 the similar type of decisions that have been, 01:06:06.900 --> 01:06:09.020 you know, governments all over the world have been making. 01:06:09.020 --> 01:06:11.180 And in this particular case, for this cold data is, 01:06:11.180 --> 01:06:13.780 no, it is not worth getting the cure. 01:06:13.780 --> 01:06:14.620 (laughing) 01:06:14.620 --> 01:06:16.300 - Don't tell that to the people who are suffering 01:06:16.300 --> 01:06:17.500 with a fever or whatever. 01:06:17.500 --> 01:06:19.180 - It's a cold. 01:06:19.180 --> 01:06:20.020 - It's a little like, yeah, yeah, it's a cold. 01:06:20.020 --> 01:06:22.460 - This is not like a common cold, this is a cold. 01:06:22.460 --> 01:06:24.700 (laughing) 01:06:24.700 --> 01:06:28.620 - Well, this chapter, I think was, 01:06:28.620 --> 01:06:30.460 we found this chapter really, really neat 01:06:30.460 --> 01:06:33.980 because when we started doing exactly the same thing, 01:06:33.980 --> 01:06:35.940 going, how do we solve this in R, 01:06:35.940 --> 01:06:39.700 we realized we had to use a completely different approach. 01:06:39.700 --> 01:06:42.260 - Well, you know what, you skip, 01:06:42.260 --> 01:06:43.980 skipping a step, right? - It was a bad choice. 01:06:43.980 --> 01:06:46.460 - Yeah, 'cause, sorry, again, 01:06:46.460 --> 01:06:55.580 Sorry. So we went looking in R for an equivalent symbolic mathematics package in R. And there 01:06:55.580 --> 01:07:05.820 is one, but really it's a wrapper for Python's SymPy. And so we found ourselves writing strings 01:07:05.820 --> 01:07:11.900 of Python that you pass to R that R passes to SymPy. And yeah, sorry. 01:07:11.900 --> 01:07:13.220 - Yeah, I think that's-- 01:07:13.220 --> 01:07:16.540 - That doesn't sound like really like solving it in R. 01:07:16.540 --> 01:07:17.380 You know? 01:07:17.380 --> 01:07:18.220 - Exactly, exactly. 01:07:18.220 --> 01:07:20.780 So then, so we decided, well, no, 01:07:20.780 --> 01:07:23.460 if we were just to solve this in R, how would you do it? 01:07:23.460 --> 01:07:26.860 And as there is no symbolic library, 01:07:26.860 --> 01:07:29.780 a library for doing symbolic mathematics in R, 01:07:29.780 --> 01:07:30.900 we solved it numerically. 01:07:30.900 --> 01:07:34.660 And that just shows like exactly the same problem. 01:07:34.660 --> 01:07:36.460 We get exactly the same answers out, 01:07:36.460 --> 01:07:39.460 but the bit in the middle, the solution steps, 01:07:39.460 --> 01:07:42.100 were completely different in both Python and R 01:07:42.100 --> 01:07:47.100 for those reasons, which I think is really neat. 01:07:47.100 --> 01:07:51.980 I think that shows that you're concentrating 01:07:51.980 --> 01:07:55.140 on the problem rather than the solution steps. 01:07:55.140 --> 01:07:57.340 Yeah, I like that. 01:07:57.340 --> 01:07:59.740 - Yeah, absolutely. 01:07:59.740 --> 01:08:04.340 And what you've learned here is that this function 01:08:04.340 --> 01:08:07.780 that expresses the cost of people being sick, 01:08:07.780 --> 01:08:11.360 IFT that we talked about is 100 for a hundred people sick. 01:08:11.360 --> 01:08:15.560 E to the negative alpha of T, which is, it's pretty awesome. 01:08:15.560 --> 01:08:17.820 I mean, there's never, 01:08:17.820 --> 01:08:22.680 there's almost always a reason to marvel at the number E. 01:08:22.680 --> 01:08:26.460 Have you all read the book, E, the story of a number? 01:08:26.460 --> 01:08:28.460 - I don't think I have, no. 01:08:28.460 --> 01:08:33.440 - This, this book is so good. 01:08:33.440 --> 01:08:36.200 It just goes back to the history literally of just, 01:08:36.200 --> 01:08:38.820 - Oh yeah, I totally can recommend it. 01:08:38.820 --> 01:08:39.660 So people can check that out. 01:08:39.660 --> 01:08:41.980 - E is a ridiculously cool number, right? 01:08:41.980 --> 01:08:43.940 In terms of, I know pi gets all the press, 01:08:43.940 --> 01:08:45.580 but E is a ridiculously cool number. 01:08:45.580 --> 01:08:46.840 - It's way cooler than pi. 01:08:46.840 --> 01:08:48.060 It's way cooler than pi. 01:08:48.060 --> 01:08:51.980 I mean, pi is cool, but if you are into 01:08:51.980 --> 01:08:54.660 the change of anything, differential equations, 01:08:54.660 --> 01:08:58.620 integrations, like, there's nothing like it, yeah. 01:08:58.620 --> 01:09:00.420 - Recommendation, I haven't heard about that one. 01:09:00.420 --> 01:09:02.360 - We are going pretty long on time here, 01:09:02.360 --> 01:09:05.340 so I wanna be respectful of your time and everything. 01:09:05.340 --> 01:09:07.980 So maybe, is there any other of the problems 01:09:07.980 --> 01:09:10.060 or areas or libraries that you've made? 01:09:10.060 --> 01:09:11.940 Actually, let me pick one here. 01:09:11.940 --> 01:09:16.940 Which chapter is the game theory one? 01:09:16.940 --> 01:09:19.760 (laughing) 01:09:19.760 --> 01:09:24.100 Wait for it, no, it's nine. 01:09:24.100 --> 01:09:25.980 - Just one before that, yeah. 01:09:25.980 --> 01:09:27.820 - Yeah, or yeah, no, it was one before that. 01:09:27.820 --> 01:09:28.980 Yeah, got it, yep. 01:09:28.980 --> 01:09:32.540 The missing one is the linear programming one. 01:09:32.540 --> 01:09:34.380 All right, game theory. 01:09:34.380 --> 01:09:37.980 And the reason I want to pull this up is we talked about Q, 01:09:37.980 --> 01:09:41.300 Grant's library and his application. 01:09:41.300 --> 01:09:42.380 How about some Nash pie? 01:09:42.380 --> 01:09:46.100 I mean, there was John Nash won the Nobel Prize in economics 01:09:46.100 --> 01:09:51.140 for coming up with basically proving in every game 01:09:51.140 --> 01:09:56.180 there was an equilibrium position, which is insane. 01:09:56.180 --> 01:09:59.780 - In a 17 page PhD thesis. 01:09:59.780 --> 01:10:00.800 Yeah, incredible. 01:10:00.800 --> 01:10:03.780 - Not bad, not bad. 01:10:03.780 --> 01:10:07.140 So, quick game theory, what is it? 01:10:07.140 --> 01:10:10.580 People maybe have heard of it, but they don't really know, 01:10:10.580 --> 01:10:11.940 or maybe they do know. 01:10:11.940 --> 01:10:14.740 I know I fumbled through the previous one, 01:10:14.740 --> 01:10:17.220 but it probably makes sense for me to take this one. 01:10:17.220 --> 01:10:17.940 Yeah, yeah, sure. 01:10:17.940 --> 01:10:18.440 Right. 01:10:18.440 --> 01:10:25.700 So game theory is the study of emergent interactions, 01:10:25.700 --> 01:10:30.260 of if you can kind of make some decisions, 01:10:31.140 --> 01:10:37.860 Describe a system at the lower level, how individuals interact, what happens at the 01:10:37.860 --> 01:10:43.700 higher level. That's the study of game theory. It's interactive decision-making. A lot of the 01:10:43.700 --> 01:10:50.020 time you can think of decision-making, for example, with that barbershop problem we discussed at the 01:10:50.020 --> 01:10:56.180 first stage of, well, if I had this many chairs or this much waiting room, what's the best thing for 01:10:56.180 --> 01:11:02.420 me, but there you're the only thing that your decision gets hit back with. If you think of a 01:11:02.420 --> 01:11:06.340 game of tennis, it's playing against a wall, it's playing against that probability. Game theory is 01:11:06.340 --> 01:11:10.660 just taking it to a slightly different dimension where you have two barbershops. What if you had 01:11:10.660 --> 01:11:14.660 two barbershops and if one does this and the other does that, where are the customers going to go? 01:11:14.660 --> 01:11:20.260 Right. Both barbershops could say expand their waiting room. Both barbershops could hire more 01:11:20.260 --> 01:11:23.780 barbers or one could say, "You know what? If you hire barbers, I'm getting a bigger waiting room." 01:11:23.780 --> 01:11:24.180 Yeah. 01:11:24.180 --> 01:11:27.380 - Right, it's like that trade-off, yeah. 01:11:27.380 --> 01:11:29.900 - Exactly, a very famous problem in game theory 01:11:29.900 --> 01:11:31.300 is the prisoner's dilemma. 01:11:31.300 --> 01:11:34.260 Two prisoners are, 01:11:34.260 --> 01:11:37.560 two criminals are convicted 01:11:37.560 --> 01:11:39.460 and are separated and are questioned, 01:11:39.460 --> 01:11:43.380 and they can give evidence about the other prisoner. 01:11:43.380 --> 01:11:46.820 If they both stay quiet, they both give no evidence, 01:11:46.820 --> 01:11:49.500 the police won't have enough evidence 01:11:49.500 --> 01:11:52.020 to send them to prison for a very long time. 01:11:52.020 --> 01:11:54.300 they'll have to stay for a very short amount of time. 01:11:54.300 --> 01:11:55.540 So that's in their interest, 01:11:55.540 --> 01:11:57.340 but the police offer me a deal. 01:11:57.340 --> 01:12:00.060 And if I give evidence about Geraint, 01:12:00.060 --> 01:12:02.340 then I'll go free and Geraint will go to prison 01:12:02.340 --> 01:12:03.540 for far longer. 01:12:03.540 --> 01:12:05.060 Geraint gets offered the same deal 01:12:05.060 --> 01:12:06.940 and that immediately creates a dilemma 01:12:06.940 --> 01:12:09.340 that we will both end up getting to prison for a long time 01:12:09.340 --> 01:12:11.220 because we will both give evidence one about the other. 01:12:11.220 --> 01:12:14.340 And so that's a very simple model. 01:12:14.340 --> 01:12:16.020 And that's actually what I came on the show 01:12:16.020 --> 01:12:18.220 a long time ago to talk about was that actual model 01:12:18.220 --> 01:12:20.820 and all the interesting stuff you could do with that. 01:12:21.780 --> 01:12:27.060 But this game theoretic chapter is paired with another chapter 01:12:27.060 --> 01:12:29.860 called agent-based modeling. It's again one of those points 01:12:29.860 --> 01:12:32.980 where labeling is interesting because for some, agent-based 01:12:32.980 --> 01:12:35.220 modeling is a subset of game theory. In a way, it doesn't 01:12:35.220 --> 01:12:38.820 really matter. And so this chapter is all about emergent 01:12:38.820 --> 01:12:44.260 behavior. If we can define how decision makers in our system 01:12:44.260 --> 01:12:47.860 interact, what happens based on what they do, and they being 01:12:47.860 --> 01:12:54.900 plural, then what is the emergent behavior that you can measure? And so the game that 01:12:54.900 --> 01:13:04.740 we model in this chapter is there are two taxi firms that serve a community, again, a small town, 01:13:04.740 --> 01:13:15.300 and they get to decide how many taxis they're going to have. And the town wants to incentivize 01:13:15.300 --> 01:13:19.100 these two taxi firms, essentially not to collude. 01:13:19.100 --> 01:13:24.320 They want to incentivize the taxi firms to give better service to the population. 01:13:24.320 --> 01:13:29.360 And so we create the game that allows the taxi firms to decide how many taxis they're 01:13:29.360 --> 01:13:33.220 going to have, one, two, or three. 01:13:33.220 --> 01:13:41.380 And we build a little model that describes what happens if each taxi firm has one taxi, 01:13:41.380 --> 01:13:44.420 what happens if one has one, the other has two, what happens if one has one, the other 01:13:44.420 --> 01:13:47.620 as three, et cetera, et cetera. 01:13:47.620 --> 01:13:51.060 And then we obtain what is called the Nash equilibrium, 01:13:51.060 --> 01:13:54.380 which is a measure of if both tax firms know all this 01:13:54.380 --> 01:13:57.080 and act rationally, what would we expect to happen? 01:13:57.080 --> 01:14:03.020 - It's just amazing how these outcomes, 01:14:03.020 --> 01:14:04.740 it's just so clear, you know, 01:14:04.740 --> 01:14:08.440 if what's the likelihood of the other person doing 01:14:08.440 --> 01:14:12.460 or the other player participant taking this particular 01:14:12.460 --> 01:14:15.260 choice and if I take this choice, 01:14:15.260 --> 01:14:18.740 what are they most likely to do and where are things going to settle in? 01:14:18.740 --> 01:14:22.540 It's really neat how this all sets up here. 01:14:22.540 --> 01:14:25.620 Let me find the section. 01:14:25.620 --> 01:14:30.260 Yeah. So what you do is you create 01:14:30.260 --> 01:14:39.900 a NumPy array that represents one of the participants outcomes and choices. 01:14:39.900 --> 01:14:43.200 And this one, I guess it's a, what is this? 01:14:43.200 --> 01:14:44.480 A zero sum game? 01:14:44.480 --> 01:14:45.320 'Cause you can-- 01:14:45.320 --> 01:14:46.160 - Not quite, not quite. 01:14:46.160 --> 01:14:48.000 It's not zero sum, it's symmetric. 01:14:48.000 --> 01:14:48.840 So-- 01:14:48.840 --> 01:14:50.000 - Oh, symmetric, okay. 01:14:50.000 --> 01:14:52.200 So you can pass in the transpose of that, 01:14:52.200 --> 01:14:53.500 which says, here's the other player. 01:14:53.500 --> 01:14:56.600 They get basically the opposite of that. 01:14:56.600 --> 01:15:00.880 And then you just say, Nash.game, and off you go, right? 01:15:00.880 --> 01:15:03.200 - Yeah, Nash.game creates this game. 01:15:03.200 --> 01:15:05.760 It creates the game object, and in the game object, 01:15:05.760 --> 01:15:09.560 the Nash Pi library has all sorts of different algorithms 01:15:09.560 --> 01:15:11.400 that could be used and the one we use 01:15:11.400 --> 01:15:13.400 is something called support enumeration, 01:15:13.400 --> 01:15:18.400 which is essentially the basic by definition idea. 01:15:18.400 --> 01:15:23.640 And the thing that we do do here is we say, 01:15:23.640 --> 01:15:27.040 okay, if we are the town hall trying to decide 01:15:27.040 --> 01:15:29.900 how to let these two tax firms compete, 01:15:29.900 --> 01:15:33.520 is we essentially are deciding not how we regulate them, 01:15:33.520 --> 01:15:35.000 but how we incentivize them. 01:15:35.000 --> 01:15:38.020 So what game should we make the two taxi firms play? 01:15:38.020 --> 01:15:40.740 And we do that by essentially saying, 01:15:40.740 --> 01:15:42.980 I guess we will tax you slightly less 01:15:42.980 --> 01:15:45.220 if you put on this amount of taxis 01:15:45.220 --> 01:15:47.780 or give you an extra bonus if not. 01:15:47.780 --> 01:15:51.420 And the idea is to, what is the smallest amount 01:15:51.420 --> 01:15:54.940 that the city hall has to kind of guarantee 01:15:54.940 --> 01:15:58.660 to the taxi firms to ensure that their rational behavior 01:15:58.660 --> 01:16:01.400 would be to give best service to the population? 01:16:01.400 --> 01:16:03.220 - Yeah. - So yeah, 01:16:03.220 --> 01:16:04.140 then it's just those three lines 01:16:04.140 --> 01:16:04.980 you got on the screen right there, 01:16:04.980 --> 01:16:05.800 it's a little while loop 01:16:05.800 --> 01:16:07.540 where it just increments that offset. 01:16:07.540 --> 01:16:14.540 Yep, and you just say, you know, get the equilibrium from it and off it goes. 01:16:14.540 --> 01:16:16.540 Yeah, very nice. 01:16:16.540 --> 01:16:18.540 Okay. 01:16:18.540 --> 01:16:22.540 This is really great and I guess it's worth pointing out. 01:16:22.540 --> 01:16:24.540 I've heard of the guy. 01:16:24.540 --> 01:16:25.540 Yeah, that's me. 01:16:25.540 --> 01:16:26.540 I should say that. 01:16:26.540 --> 01:16:34.540 The Nash Pi Library is myself and a former undergraduate. 01:16:34.540 --> 01:16:36.540 Actually, they went on to start their PhD 01:16:36.540 --> 01:16:38.540 at the School of Mathematics. 01:16:38.540 --> 01:16:40.540 We started this library, 01:16:40.540 --> 01:16:44.540 and it's grown quite nicely now. 01:16:44.540 --> 01:16:46.540 To be honest, probably the part of the library 01:16:46.540 --> 01:16:48.540 I'm the most proud of is the documentation. 01:16:48.540 --> 01:16:50.540 There's arguably a game theory textbook in there, 01:16:50.540 --> 01:16:52.540 if anyone's interested, 01:16:52.540 --> 01:16:54.540 as well as all the functionality 01:16:54.540 --> 01:16:56.540 for two-player games. >> Yeah, fantastic. 01:16:56.540 --> 01:16:57.540 [laughter] 01:16:57.540 --> 01:16:59.540 Yeah, it looks really great. I'm a big fan of game theory. 01:16:59.540 --> 01:17:02.540 I think it's very simple, 01:17:02.540 --> 01:17:09.500 and yet it reveals pretty amazing answers and behaviors. So, you know, as opposed to something 01:17:09.500 --> 01:17:13.900 like partial differential equation, which can also reveal amazing answers, but the journey to get 01:17:13.900 --> 01:17:20.860 through it is extremely long versus this. You could sit down in an afternoon and explain it to somebody, 01:17:20.860 --> 01:17:24.860 you know, like that prisoner's dilemma and so on. We could all kind of relate to a lot of what's 01:17:24.860 --> 01:17:31.180 happening there. I mean, to be honest, if you, this is one of those things, right, you know, you 01:17:31.180 --> 01:17:34.220 you wonder, you realize that you're aging. 01:17:34.220 --> 01:17:36.940 But I remember when I first started teaching game theory, 01:17:36.940 --> 01:17:39.100 everyone had seen the movie "A Beautiful Mind." 01:17:39.100 --> 01:17:40.620 But if people listening 01:17:40.620 --> 01:17:42.260 and haven't, are slightly interested in game theory 01:17:42.260 --> 01:17:43.300 and haven't seen "A Beautiful Mind," 01:17:43.300 --> 01:17:44.660 I'd definitely recommend it. 01:17:44.660 --> 01:17:46.700 It's a Hollywood movie, 01:17:46.700 --> 01:17:49.780 so have the correct level of expectations. 01:17:49.780 --> 01:17:52.380 But it's a really nice movie. 01:17:52.380 --> 01:17:54.540 It's Russell Crowe plays John Nash. 01:17:54.540 --> 01:17:57.500 And it's more about the, 01:17:57.500 --> 01:17:59.900 not necessarily about the mathematics, 01:17:59.900 --> 01:18:02.140 about his life, which is incredibly interesting. 01:18:02.140 --> 01:18:04.340 And there's a couple of scenes in that movie 01:18:04.340 --> 01:18:07.660 that arguably if you just spend a little bit of time 01:18:07.660 --> 01:18:09.140 talking about a couple of scenes in that movie, 01:18:09.140 --> 01:18:11.140 you could explain most of the game theory. 01:18:11.140 --> 01:18:15.660 - Yeah, absolutely. 01:18:15.660 --> 01:18:18.060 All right, well, I get the sense we're a tad bit over time, 01:18:18.060 --> 01:18:21.760 which is fine, but maybe we should wrap it up here. 01:18:21.760 --> 01:18:24.720 There's a bunch of other areas that we haven't covered 01:18:24.720 --> 01:18:27.100 that are lots of fun that you go into. 01:18:27.100 --> 01:18:30.500 So yeah, very, very neat. 01:18:30.500 --> 01:18:32.580 But let's kind of wrap it up. 01:18:32.580 --> 01:18:36.940 Maybe we'll ask you the final two questions 01:18:36.940 --> 01:18:37.780 and then we can-- 01:18:37.780 --> 01:18:38.900 (laughing) 01:18:38.900 --> 01:18:40.340 - I want to thank you for having us, 01:18:40.340 --> 01:18:42.020 but I know that you got these two questions coming. 01:18:42.020 --> 01:18:43.260 So like, oh, do I thank you now? 01:18:43.260 --> 01:18:44.100 Do I thank you later? 01:18:44.100 --> 01:18:46.460 But no, I really do appreciate you having us on, Mike. 01:18:46.460 --> 01:18:47.420 I really do appreciate it. 01:18:47.420 --> 01:18:49.020 - Yeah, you're very welcome. 01:18:49.020 --> 01:18:50.180 It's been great to talk about it. 01:18:50.180 --> 01:18:52.580 All right, now maybe a lightning round. 01:18:52.580 --> 01:18:54.660 Vint, if you're gonna write some Python code, 01:18:54.660 --> 01:18:56.740 what editor are you using these days? 01:18:56.740 --> 01:18:57.580 - I use Vim. 01:18:57.580 --> 01:18:58.400 I use Vim. 01:18:58.400 --> 01:19:00.880 - Vim, right on. 01:19:00.880 --> 01:19:02.460 Grant? 01:19:02.460 --> 01:19:03.820 - I use Sublime. 01:19:03.820 --> 01:19:07.680 I really like having no features. 01:19:07.680 --> 01:19:09.240 I just like typing. 01:19:09.240 --> 01:19:10.080 I don't want features. 01:19:10.080 --> 01:19:10.900 - Right on. 01:19:10.900 --> 01:19:13.560 Perfect. 01:19:13.560 --> 01:19:17.000 And then a notable PyPI package that you've come across 01:19:17.000 --> 01:19:20.040 that you're thinking is worth giving a shout out to? 01:19:20.040 --> 01:19:21.480 - I was thinking about this before, 01:19:21.480 --> 01:19:25.680 and the one I'm gonna suggest is one called Python Ternary. 01:19:25.680 --> 01:19:26.960 You've got it on the screen there. 01:19:26.960 --> 01:19:31.960 Yeah, Python Ternary is a library for plotting on simplexes. 01:19:31.960 --> 01:19:35.480 So for plotting on triangles, want a better word. 01:19:35.480 --> 01:19:37.280 It's type of plots you draw a lot 01:19:37.280 --> 01:19:40.640 in evolutionary game theory, as well as other things. 01:19:40.640 --> 01:19:43.280 Actually a collaborator on another project of mine 01:19:43.280 --> 01:19:44.360 that maintains this. 01:19:44.360 --> 01:19:45.520 And it's a very nice library 01:19:45.520 --> 01:19:48.320 for plotting different looking plots. 01:19:48.320 --> 01:19:53.080 - Yeah, there's some, I'm sure people think about, 01:19:53.080 --> 01:19:54.640 well, you could have these different plots 01:19:54.640 --> 01:19:59.640 on triangle surfaces or how much are you, 01:19:59.640 --> 01:20:02.160 how close are each three different states 01:20:02.160 --> 01:20:03.400 or something like that. 01:20:03.400 --> 01:20:04.240 - Yeah. 01:20:04.240 --> 01:20:05.880 - You've got, some of these are really amazing, 01:20:05.880 --> 01:20:08.680 like this M cherry one on there where it's got 01:20:08.680 --> 01:20:11.480 kind of crawling graphs through these triangle 01:20:11.480 --> 01:20:12.760 different states and so on. 01:20:12.760 --> 01:20:16.200 Yeah, I haven't seen any one like that before. 01:20:16.200 --> 01:20:17.040 - It's very cool. 01:20:17.040 --> 01:20:17.880 It's very cool. 01:20:17.880 --> 01:20:19.000 And it's built on top of MapPlotLib. 01:20:19.000 --> 01:20:24.000 So it's essentially the layer to do all the correct scaling 01:20:24.360 --> 01:20:26.300 and things like that is there for you. 01:20:26.300 --> 01:20:29.560 So yeah, Python ternary is really cool. 01:20:29.560 --> 01:20:31.840 - Yeah, fantastic. 01:20:31.840 --> 01:20:32.680 Grant. 01:20:32.680 --> 01:20:36.920 - So I think the library I would choose is, 01:20:36.920 --> 01:20:38.340 it's called Traces. 01:20:38.340 --> 01:20:39.980 It's a small library. 01:20:39.980 --> 01:20:42.920 I don't know if you've heard of it before. 01:20:42.920 --> 01:20:43.920 I got the link here. 01:20:43.920 --> 01:20:51.080 It's one thing, yeah, it does one thing and one thing good. 01:20:51.080 --> 01:20:55.760 it takes moving averages over irregular time intervals. 01:20:55.760 --> 01:20:58.080 And it was a problem which I thought I had 01:20:58.080 --> 01:21:00.400 until I found this, and then it just made life easier. 01:21:00.400 --> 01:21:01.880 I liked it. 01:21:01.880 --> 01:21:02.840 - Yeah, very cool. 01:21:02.840 --> 01:21:03.680 Okay. 01:21:03.680 --> 01:21:05.960 - I think it's the next link. 01:21:05.960 --> 01:21:07.360 - Fantastic. 01:21:07.360 --> 01:21:08.280 This one right here? 01:21:08.280 --> 01:21:09.360 Not that one. 01:21:09.360 --> 01:21:10.400 This one? 01:21:10.400 --> 01:21:11.240 - There it is. 01:21:11.240 --> 01:21:13.600 - Yes, the uneven time series. 01:21:13.600 --> 01:21:14.440 Yeah, perfect. 01:21:14.440 --> 01:21:15.880 Okay. 01:21:15.880 --> 01:21:17.340 Oh yeah, that's great. 01:21:17.340 --> 01:21:20.200 - It does one thing quite well. 01:21:20.200 --> 01:21:21.200 Yeah. 01:21:21.200 --> 01:21:24.360 And yeah, that's often just what you need. 01:21:24.360 --> 01:21:26.920 Put a link to both of those in the show notes. 01:21:26.920 --> 01:21:29.200 Thank you so much. 01:21:29.200 --> 01:21:34.440 So people, people are interested in your book or maybe exploring some of these problems. 01:21:34.440 --> 01:21:36.440 What do you tell them? 01:21:36.440 --> 01:21:38.400 Where do they go? 01:21:38.400 --> 01:21:42.320 I think if they're interested in the book, that's, that's great. 01:21:42.320 --> 01:21:47.680 I think I, I, I'd more kind of emphasize just, just mathematics is so incredibly powerful 01:21:47.680 --> 01:21:50.400 And it really, really is. 01:21:50.400 --> 01:21:55.400 And it's kind of like, I feel that code, open source code, 01:21:55.400 --> 01:22:00.400 Python, kind of an order of how important each other is, 01:22:00.400 --> 01:22:03.400 with mathematics really, really gives you superpowers. 01:22:03.400 --> 01:22:07.720 And so, I'd encourage people to investigate those things 01:22:07.720 --> 01:22:09.440 and you can do amazing things with mathematics 01:22:09.440 --> 01:22:10.340 and a bit of code. 01:22:10.340 --> 01:22:12.960 That'd be mine. 01:22:12.960 --> 01:22:14.800 I don't know what you think, Gary. 01:22:14.800 --> 01:22:17.000 - No, no, yeah, I second that. 01:22:17.000 --> 01:22:20.760 I think my main message is the maths and the software 01:22:20.760 --> 01:22:25.000 are separate things and they complement each other 01:22:25.000 --> 01:22:27.280 really, really well, but they are separate things. 01:22:27.280 --> 01:22:29.520 - They are separate things, yeah, that's the thing. 01:22:29.520 --> 01:22:31.400 - Yeah, fantastic. 01:22:31.400 --> 01:22:34.400 All right, like I said, your book is on GitHub, 01:22:34.400 --> 01:22:37.600 so people can go poke around some of the examples 01:22:37.600 --> 01:22:40.680 and some of the notebooks and see what we're talking about. 01:22:40.680 --> 01:22:41.660 Make it a little more concrete. 01:22:41.660 --> 01:22:43.620 Make it a little more applied, maybe. 01:22:43.620 --> 01:22:45.400 - Yes. 01:22:45.400 --> 01:22:47.820 (laughing) 01:22:47.820 --> 01:22:49.660 - All right guys, thanks for being here. 01:22:49.660 --> 01:22:50.500 Thanks for sharing your work. 01:22:50.500 --> 01:22:51.320 - Thank you so much. 01:22:51.320 --> 01:22:52.160 - It's been a lot of fun. 01:22:52.160 --> 01:22:53.000 Yeah. 01:22:53.000 --> 01:22:53.820 - Thank you very much. 01:22:53.820 --> 01:22:54.660 - Thank you. 01:22:54.660 --> 01:22:55.500 - You bet.