Bayesian Statistics
Transcript
In this special episode, the roles are reversed. as I step into the guest seat to explore the intriguing world of Bayesian stats. Originally aired as episode 793 on the fantastic Super Data Science podcast hosted by John Crone, this conversation is too good not to share with all of you here on learning Bayesian statistics. So join us as we delve into how Bayesian methods elegantly handle complex problems, make efficient use of prior knowledge and excel with limited data.
the foundational concepts of patient statistics, highlighting their distinct advantages over traditional methods, particularly in scenarios fraught. with uncertainty and sparse data. A highlight of our discussion is the application of Gaussian processes where I explain their versatility in modeling complex, non -linear relationships in data. I share a fascinating case study involving an NGO in Estonia illustrating how Bayesian approaches can transform limited polling data into profound insights.
So whether you're a seasoned statistician or just starting out, this episode is packed with practical advice on embracing Bayesian stats and of course I strongly recommend you follow the Super Data Science Podcast. It's really a can't -miss resource for anyone passionate about the power of data. This is Learning Vision Statistics, episode 113, originally aired on the Super Data Science Podcast. Welcome to Learning Bayesian Statistics, a podcast about Bayesian inference, the methods, the projects, and the people who make it possible. I'm your host, Alex Andorra. You can follow me on Twitter at alex -underscore -andorra.
like the country. For any info about the show, learnbasedats .com is Laplace to be. Show notes, becoming a corporate sponsor, unlocking Bayesian Merge, supporting the show on Patreon, everything is in there. That's learnbasedats .com. If you're interested in one -on -one mentorship, online courses, or statistical consulting, feel free to reach out and book a call at topmate .io slash alex underscore and dora. See you around, folks. and best patient wishes to you all. And if today's discussion sparked ideas for your business, well, our team at PIMC Labs can help bring them to life. Check us out at pimc -labs .com.
Hello my dear Vagans! A quick note before today's episode, STANCON 2024 is approaching! It's in Oxford, UK this year from September 9 to 13 and it's shaping up to be an incredible event for anybody interested in statistical modeling and vaginal inference. Actually, we're currently looking for sponsors to help us offer more scholarships and make STANCON more accessible to everyone and we also encourage you to buy your tickets as soon as possible.
Not only will this help with making a better conference, but this will also support our scholarship fund. For more details on tickets, sponsorships, or community involvement, you'll find the Stencon website in the show notes. We're counting on you. Okay, on to the show now. Alex, welcome to the Super Data Science podcast. I'm delighted to have you here. Such an experienced podcaster. It's going to be probably fun for you to get to be the guest on the show today. Yeah. Thank you, John. First, thanks a lot for having me on. I knew about your podcast. I was both honored and delighted when I got your email to come on the show. I know you have had very... Honorable guests before like Thomas Vicky.
so I will try to, to, to be on board, but, I know that it's going to be hard. Yeah. Thomas, your co -founder at, Pi MC labs is, was indeed a guest. was on episode number 585. but that is not what brought you here. Interestingly, the connection. So you asked me before we started recording how I knew about you. And so a listener actually suggested to you as a guest. So. Doug McLean. Thank you for the suggestion. Doug is lead data scientist at Tesco bank in the UK.
And he reached out to me and said, can I make a suggestion for a guest? Alex Andora, like the country, I guess you say that you say that. Cause he put it in quotes. He's like, Andora, like the country hosts the learning patient statistics podcast. It's my other all time favorite podcast. So there you go. my God. Doug, I'm blushing. says he'd be a fab guest for your show and not least because he moans from time to time about not getting invited onto other podcasts. Did I? my God.
I don't remember. But maybe that was part of a secret plan, Maybe a secret marketing LBS plan and well. That works perfectly. When I read that, I immediately reached out to you to see if you'd want to go, but that was so funny. And he does say, says, seriously though, he'd make a fab guest for his wealth of knowledge on data science and on Bayesian statistics. And so, yes, we will be digging deep into Bayesian statistics with you today. you're the co -founder and principal data scientist of the popular Bayesian statistical modeling platform, PI MC, as we already talked about with your co -founder Thomas Wiki. That is an excellent episode. If you want to go back to that and get. different perspective, obviously different questions we've made sure. But so if you're really interested in Bayesian statistics, that is a great one to go back to.
Yeah, in addition to that, you obviously also have the Learning Bayesian Stats podcast, which we just talked about, and you're an instructor on the educational site, Intuitive Bayes. So tons of Bayesian experience. Alex, through this work, tell us about what Bayesian methods are and what makes them so powerful and versatile? Yeah. so first, thanks a lot. Thanks a lot, dog, for the recommendation and for listening to the show. am, I am absolutely honored.
and, yeah, go and listen again to Thomas's episode. Thomas is always a great guest. So I definitely recommend anybody to, to go and listen to him. now what about Bayes? Yeah. You know, it's been a long time since someone has asked me that, because I have a Bayesian podcast. Usually it's quite clear I'm doing that. people are like afraid to ask it at some point. So instead of giving you kind of like a, because our two avenues here, usually I could give you the philosophical answer and why epistemologically Bayes stats makes more sense. but I'm not going to do that. That sounds so interesting. Yeah, it is, we can go into that. I think a better introduction is just a practical one. And that's the one that most people get to know at some point, which is like you're working on something and you're interested in uncertainty estimation and not only in the
point estimates and your data are crap and you don't have a lot of them and they are not reliable. What do you do? And that happens to a lot of PhD students. That happened to me when I started trying to do electoral forecasting. was at the time working at the French Central Bank doing something completely different from what I'm doing today. But I was writing a book about the US at the time, 2016 it was, and it was a pretty consequential election for the US. was following it.
really, really closely. And I remember it was July 2016 when I discovered 538 models. And then the nerd in me was awoken. It was like, my God, this is what I need to do. You know, that's my way of putting more science into political science, which was my background at the time. And when you do electoral forecasting polls are extremely noisy. They are not a good representation of what people think, but they are the best ones we have. are not a lot of them, at least in France, in the US much more.
It's limited. It's not a reliable source of data basically. And you also have a lot of domain knowledge, which in the Bayesian Royal realm, we call prior information. And so that's a perfect setup for Bayesian stats. So that's basically, I would say what Bayesian stats is. And that's the powerful, the power of it. You don't have to rely only on the data because sure you can let the data speak for themselves, but what if the data are unreliable?
Then you need something to guard against that and patient stats are a great way of doing that. And the cool thing is that it's a method. It's like you can apply that to any topic you want, any field you want. that's what... I've done at PMC Labs for a few years now with all the brilliant guys who are over there. You can do that for marketing, for electoral forecasting, of course. Agriculture, that was quite ironic when we got some agricultural clients because historically, agriculture is like the field of frequency statistics. That's how Ronald Fisher developed the p -value, the famous one. So when we had that, we're like, yes, we got our revenge. And of course, it's also used a lot in sports, sports modeling, things like that. So yeah, it's like that's the practical introduction. Nice. Yeah.
A little bit of interesting history there is that sub -Asian statistics is an older approach than the frequentist statistics that is so common and is the standard that is taught in college, so much so that is just called statistics. You do an entire undergrad in statistics and not even hear the word Bayesian because Fisher so decidedly created this monopoly of this one kind of approach, which for me,
learning for Quenta statistics say, I think I guess it was first year undergrad in science that I studied and in that first year course, that idea of a P value always seemed odd to me. Like how is it that there's this art? This is such an arbitrary threshold of significance to have it be, you know, that this is a one in 20 chance or less that this would be observed by chance alone. And this means that therefore we should rely on it, especially as we are in this era of large data sets and larger and larger and larger data sets. You can have no meaningful if with very large data sets like we typically deal with today, no matter, you're always going to get a significant P value because the slightest tiny change, if you take, you know, web scale data, everything's going to have be statistically significant. Nothing won't be.
so it's such a weird paradigm. And so that was discovering Bayesian statistics and machine learning as well. And seeing how Those areas didn't have P values interested me in both of those things. it's a, yeah, Fisher. It's interesting. mean, I guess with small data sets, eight, 16, that kind of scale, guess it kind of made some sense. And you know, you pointed out there, I think it's this prior that makes Bayesian statistics so powerful being able to incorporate prior knowledge, but simultaneously that's also what makes for Quentus uncomfortable. They they're like, we want only the data. As though, you know, the particular data that you collect and the experimental design, there are so many ways that you as the human are influencing, you know, there's no purity of data anyway.
And so priors are a really elegant way to be able to adjust the model in order to point it in the right direction. And so a really good example that I like to come to with Bayesian statistics is that you can You can allow some of your variables in the model to tend towards wider variance or narrower variance. So if there are some attributes of your model where you're very confident, where you know this is like, you know, this is like a physical fact of the universe.
Let's just have a really narrow variance on this and the model won't be able to diverge much there. But that then gives a strong focal point within the model. around which the other data can make more sense, the other features can make more sense, and you can allow those other features to have wider variance. And so, I don't know, this is just one example that I try to give people when they're not sure about being able to incorporate prior knowledge into a model. Yeah, yeah, no, these are fantastic points, John. So, yeah, to build a net, I'm... I'm a bit, of course, I'm a nerd. So I love the history of science. I love the epistemological side. A very good book on that is Bernoulli's Fallacy by Aubrey Clayton. Definitely recommend his book. He was on my podcast, episode 51. So if people want to give that a listen. Did you just pull that 51 out from memory? Yeah, yeah, I kind of know like, but I have less episodes than you.
So it's like, you know, each episode is like kind of my baby. So I'm like, yeah, 51 is Aubrey Clayton. Yeah. my goodness. That's crazy. That's also how my brain works. numbers. But yeah. And actually episode 50 was with Sir David Spiegel Halter. I think the only night we got on the podcast and David Spiegel Halter exceptional. exceptional guest, very, very good pedagogically. Definitely recommend listening to that episode two, which is very epistemologically heavy so far for people who like that, the history of science, how we got there. Because as you were saying, is actually older than Stantz, but people discovered later. So it's not because it's older, that's better, right? But it is way older actually by a few centuries.
So yeah, fun stories here. could talk about that still, but to get back to what you were saying, also as you were very eloquently saying, data can definitely be biased. Because that idea of like, no, we only want the data to speak for themselves. as I was saying, yeah, what if the data are unreliable? But as you were saying, what if the data are biased? And that happens all the time. And worse. I would say these biases are most of the time implicit in the sense that either they are hidden or most of the time they just like you don't even know you are biased in some direction most of the time because it's a result of your education and your environment. So the good thing of priors is that it forces your assumptions, your hidden assumptions to be explicit.
And that I think is very interesting also, especially when you work on models which are supposed to have a causal explanation and which are not physical models, but more social models or political scientific models. Well, then it's really interesting to see how two people can have different conclusions based on the same data. It's because they have different priors. And if you force them to explicit these priors in their models, they would definitely have different priors. then... then you can have a more interesting discussion actually, think. So there's that. And then I think the last point that's interesting also in that, like why would you be interested in this framework is that also, causes are not in the data. Causes are outside of the data. The causal relation between X and Y, you're not going to see it in the data because if you do a regression of
education on income, you're going to see an effect of education on income. But you as a human, you know that if you're looking at one person, the effect has to be education has an impact on income. But the computer could like might as well just do the other regression and regress income and education and tell you, income causes education. But no, it's not going that way. the statistical relationship goes both ways, but the causal one only goes one direction.
And that's a hidden reference to my favorite music band. But yeah, it only goes one direction, and it's not in the data. And you have to have a model for that. And a model is just a simplification of reality. We try to get the simple enough model that's usually not simple, but that's a simplification. If you say it's a construction and simplification, that's already a prior in a way. you you might as well just go all the way and explicit all your priors. Well said. Very interesting discussion there. You used a term a number of times already in today's podcast, which maybe is not known to all of our listeners. is epistemology? What does that mean? right. Yeah, very good question. Yeah. So epistemology in like, in a sense that's the science of science. It's understanding
how we know what we say we know. So, for instance, how do we know the earth is round? How do we know about relativity? Things like that. it's the scientific discipline that's actually very close to also philosophy. That's, think, actually a branch of philosophy. And that's trying to... come up with methods to understand how we can come up with new scientific knowledge. And by scientific here, we usually mean reliable and reproducible, but also falsifiable.
Because for hypothesis to be scientific, it has to be falsifiable. so yeah, basically that's that. Lots of extremely interesting things here, but yeah, that's like basically how do we know? what we know, that's the whole trying to define the scientific method and things like that. Going off on a little bit of a tangent here, but it's interesting to me how I think among non -scientists lay people in the public.
Science is often seen to be infallible, as though science is real. Science is the truth. There's a lot of, since that 2016 election, there are lots of, people have lawn signs in the US that say, that basically have a list of liberal values, most of which I'm a huge fan of. And of course I like the sentiment, this idea, you know, that they're supporting science on this sign, on the sign as well. But it says the sign, the way that they phrase it is science is real.
And the implication there for me, every time I see the sign is that, you know, and I think that could be, for example, related to vaccines, I think, you know, around, you know, there was a lot of conflict around vaccines and what their real purpose is and, you know, and then so. the lay liberal person is like, you know, this is science, know, trust science, it's real. Whereas from the inside, it's, you you pointed it out already there, but it's this interesting irony that the whole point of science is that we're saying, I'm, I'm, I'm never confident of anything. I'm always open to this being wrong. Yeah. Yeah. No exactly. and I think that's, that's kind of the distinction. That's often made in epistemology actually between science on one hand and research on the other end, where research is science in the making.
Science is like the collective knowledge that we've accumulated since basically the beginning of modern science, at least in the Western hemisphere, so more or less during the Renaissance. Then research is people making that science because... people have to do that and how do we come up with that? so, yeah, like definitely I'm one who always emphasizes the fact that, yeah, now we know the Earth is round. We know how to fly planes, but there was a moment we didn't.
And so how do we come up with that? And actually, maybe one day we'll discover that we were doing it kind of the wrong way, you know, flying planes, but it's just like, for now it works. We have the best model that we can have right now with our knowledge. But maybe one day we'll discover that there is a way better way to fly. And it was just there staring at us and it took years for us to understand how to do that.
yeah, like as you were saying, but that's really hard line to walk because you have to say, yeah. Like these knowledge, these facts are really trustworthy, but you can never trust something 100 % because otherwise mathematically, if you go back to base formula, you actually cannot update your knowledge. you, if you have a 0 % prior or 1 % prior, like mathematically, you cannot apply base formula, which tells you, well, based on new data that you just observed the most
rational way of updating your belief is to believe that with that certainty. But if you have zero or 100%, it's never going to be updated. So you can say 99 .9999 % that what we're doing right now by flying is really good. But maybe, like, you never know. There is something that will appear. And physics is a real... We've all seen UFOs, Alex. We know that there's better ways to fly. Yeah. Exactly. Yeah, but yeah, think physics is actually a really good field for that because it's always evolving and it's always coming up with really completely crazy paradigm shifting explanation like relativity, special relativity, then general relativity just a century ago that didn't exist. And now we start to understand a bit better, but even now we don't really understand how to how to blend relativity and gravity. so that's extremely interesting to me.
But yeah, I understand that politically from a marketing standpoint, it's hard to sell, but I think it's shooting yourself in the foot if you're saying, yeah, is always like, science works, I agree, science works, but it doesn't have to be 100 % true and sure. for it to work. That's why placebo works. Placebos work, right? It's just something that works even though it doesn't have any actual concrete evidence that it's adding something, but it works.
yeah, like I think it's really shooting yourself in the foot by saying that no, that's 100%. Like if you question science, then you're anti -science. No. Actually, it's the whole scientific methods to be able to ask questions all the time. The question is how do you do that? Do you apply the scientific method to your questions or do you just question anything like that without any method? And just because you fancy questioning that because it goes against your belief to begin with.
So yeah, that's one thing. And then I think another thing that you said I think is very interesting is, unfortunately, I think the way of teaching science and communicating around it, is not very incarnated. It's quite dry. You just learn equations and you just learn that stuff. Whereas science was made by people and is made by people who have their biases, who have extremely violent conflicts. Like you were saying, Fisher was just a huge jerk to everybody around him. I think it would be interesting to get back to a bit of that human side to make science less dry and also less intimidating thanks to that.
Because most of the time when I tell people what I do for a living, they get super intimidated and they're like, my God, yeah, I hate math, I hate stats and stuff. But it's just numbers. It's just a language. it's a bit dry. For instance, if there is someone who is into movies, who does movies in your audience. I want to know why there is no movie about Albert Einstein. There has to be a movie about Albert Einstein. Like not only huge genius, but like extremely interesting life.
Like honestly, it makes for great movie. was working in a a dramatized biopic. mean? Yeah. Yeah. I mean, it's like his life is super interesting. Like he revolutionized the field of two fields of physics and actually chemistry. In 1905, it's like his big year, and he came up with the ideas for relativity while working at the patent bureau in Bern in Switzerland, which was an extremely boring job. In his words, it was an extremely boring job.
Basically, having that boring job allowed him to do that being completely outside of the academic circles and so on. It's like he makes for a perfect movie. I don't understand why it's not there. And then I sing on the cake. He had a lot of women in his life. So it's like, you know, it's perfect. Like you have you have the sex you have, you have the drama, you have revolutionizing the field, you have Nobel prizes. And he and then he became a like a pop icon. I don't know where the movies.
Yeah, it is wild. Actually, now that you pointed out, it's kind of surprising that there aren't movies about him all the time. Like Spider -Man. Yeah, I agree. Well, there was one about Oppenheimer last year. Maybe that started to trend. see. Yeah. So in addition to the podcast, you also, I mentioned this at the outset, I said that your co -founder and principal data scientist of the popular Bayesian stats modeling platform, PyMC.
So like many things in data science, it's uppercase P, lowercase y for Python. What's the MC, PyMC, one word, and C are capitalized. Yeah. So it's very confusing because it stands for Python and then MC is Monte Carlo. So I understand. But why Monte Carlo? It's because it comes from Markov chain Monte Carlo. So actually it should be pie MCMC or pie MC squared, which is what I'm saying since the beginning. anyways, yeah, it's actually, it's actually buying C squared. so for Markov chain Monte Carlo and Markov chain Monte Carlo is one of the main ways that all of their algorithms now, new ones, but like the blockbuster algorithm to run a patient models is to use MCMC. Yeah.
So in the same way that stochastic gradient descent is like the de facto standard for finding your model weights in machine learning, Markov chain Monte Carlo is kind of the standard way of doing it with a Bayesian network. Yeah. Yeah. Yeah. And, so now there are newer versions, more efficient versions. That's, that's basically the name of the game, right? Making the efficient, the algorithm more and more efficient. but the first algorithm. days back, I think it was actually invented during the project Manhattan. during the world during World War Two. Game of the day. Yeah. And lots of physicists actually, statistical physics is a film that's contributed a lot to MCMC. so yeah, like physicists who came to the field of statistics and trying to make the algorithms more efficient for their models. And yeah, so they buy They have contributed a lot.
The field of physics has contributed a lot of big names and people to great leaps into the realm of more efficient algorithms. I don't know who your audience is, but that may sound boring. Yeah, the algorithm, it's like the workhorse. But it's extremely powerful. And that's also one of the main reasons why patients' statistics are increasing in popularity lately because
I'm going to argue that it's always been the best framework to do statistics, to do science, but it was hard to do with pen and paper because the problem is that you have a huge nasty integral on the numerator, on the denominator, sorry. And this integral is not computable by pen and paper. So for a long, long time, patient statistics combined to features, you know, like campaigns. PR campaigns, patients S6 was relegated to the margins because it was just super hard to do.
so for other problems, other than very trivial ones, it was not very applicable. But now with the advent of personal computing, you have these incredible algorithms like, so now most of time it's HMC, Hamiltonian Monte Carlo. That's what we use under the hood with PIMC. But if you use Stan, if you use NumPyro, it's the same. And thanks to these algorithms, now we can make extremely powerful models because we can approximate the posterior distributions thanks to, well, computing power.
A computer is very good at computing. I think that's why it's called that. Yes. And so that reminds me of deep learning. It's a similar kind of thing where the applications we have today, like your chat GPT or whatever your favorite large language model is these amazing video generation like Sora, all of this is happening thanks to deep learning, which is an approach we've had since the fifties, certainly not as old as Bayesian statistics, but similarly it has been able to take off with much larger data sets and much more compute. Yeah. Yeah. Yeah.
Yeah, very good point. And I think that's even more the point in deep learning. for sure. Because Beijing stats doesn't need the scale, but the way we're doing deep learning for now definitely need the scale. Yeah yeah. Scale of data. Yeah exactly. Yeah sorry. Yeah, the scale. Because there two scales, data and... Yeah, you're right. Yeah, and for like model parameters. And so that has actually, I mean, tying back to something you said near the beginning of this episode is that actually one of the advantages of Beijing statistics is that you can do it with very few data. Yeah. maybe fewer data than with a frequentist approach or machine learning approach. Because you can bake in your prior assumptions and those prior assumptions give some kind of structure, some kind of framework for your data to make an impact through. Yeah completely.
So for our listeners who are listening right now, if they are keen to try out Bayesian statistics for the first time, why should they reach for PyMC? Which, as far as I know, is the most used. Bayesian framework, period. And certainly in Python. and then the second I'm sure is Stan. yeah. Yeah. And, so, yeah, why, should somebody use pyMc and maybe even more generally, how can they get started if they haven't done any Bayesian statistics before at all? Yeah. Yeah. Yeah. Fantastic question. I think it's a, yeah, it's a very good one because, that can also be very intimidating. And actually that can be a paradox of choice. know, where now we're lucky to live in a world where we actually have a lot of probabilistic programming languages.
So you'll see that sometimes that's called PPL and that's what's a PPL. It's basically PINC. It's a software that enables you to write down Bayesian models and sample from them. Okay. So it's just a fancy word to say that. Yeah, my main advice is don't overthink it. Like if you're proficient in R, then probably you want to try, I would definitely recommend trying BRMS first because it's built on top of Stan and Stan is extremely good. It's built by extremely good modelers and statisticians. Lots of them have been on my podcast. So if you're curious, just, just go there and you go on the website, you look for Stan and you'll get a lot of them.
the best one is most of the time, Andrew Gellman, absolutely amazing to have him on the show. He, he always explains stuff extremely clearly. but I also had Bob Carpenter, for instance, Matt Hoffman. so anyways, if you know, or. yeah. Have you ever had Rob Tran Gucci on the show, or do you know who he is? I know, but I have never had him on the show. So, but I'd be happy to. Yeah. If you know him, I'll make an introduction for you. He was on our show in episode number 507.
And that was our first ever Beijing episode. And it was the most popular episode of that year, 2021, the most popular episode. And it was interesting because also up until that time, at least with me hosting, 2021 was my first year hosting the show. And it was by far our longest episode. I was like, that was kind of concerning for me. was like, this was a super technical episode, super long. I was like, how is this going to resonate? It turns out that's what our audience loves.
And that's something we've been leaning into a bit in 2024 is more technical, longer. Well, that's good to know. Yeah. I'll make an intro for Rob. Anyway, you were saying I could do an intro for you. Yeah, I know. But yeah. Great, great interruption for sure. I'm happy to have that introduction made. a lot. Yeah, so I was saying, if you're proficient in R, definitely give a try to BRMS. It's built on top of Stan. Then when you outgrow BRMS, go to Stan. If you love Stan, but you're using Python, there is PyStan.
I've never used that personally, but I'm pretty sure it's good. and then, but I would say if you're proficient in Python and don't really want to go to R then yeah, like you probably want to give a try to, to PIMC or to NumPyro. You know, give that a try, see what, what resonate most with you, the, API most of the time, because if you're going to make models like that, you're going to spend a lot of time on your code and on your models. And, as most of your audience probably know, like The models always fail unless it's the last one.
So, yeah, you have to love really the framework you're using and find it intuitive. Otherwise, it's going to be hard to keep it going. If you're really, really a beginner, I would also recommend on the Python realm, give a try to Bambi, which is the equivalent of BRMS, but in Python. So Bambi is built on top of Climacy. And what it does, it does a lot of the choices for you. It makes a lot of the choices for you under the hood.
So priors, stuff like that, which can be a bit overwhelming to beginners at the beginning. But then when you outgrow Bambi, you want to make more complicated models, then go to BiMC. Bambi, that's a really cute name for a model that's just like, it just drops out of its mother and can barely stand up straight. Yeah, And the guys working on Bambi, so Tommy Capretto, Osvaldo Martino. So they are like, yeah, really great guys. Both Argentinians, actually.
And yeah, like they are fun guys. I think the website for Bambi is bambinos .github .com. yeah, like these guys. These guys are fun. But yeah, it's definitely a great framework. And actually, this week, we released with Tommy Capretto and Ravin Kumar. We actually released an online course, our second online course that we've been working on for two years. So we are very happy to have released it. But we're also very happy with the course. That's why it took so long. It's a very big course.
And that's exactly what we do. We take you from beginner. We teach you Bambi, teach you Pinsene and you go up until advanced. That's called advanced regression. So we teach you like all things regression. What's the course called? Advanced regression. Yeah. Advanced regression on the intuitive base platform that you were kind enough to mention at the beginning. Nice. Yeah. I'll be sure to include that in the show notes. And so even though it's called advanced regression, you start us off with an introduction to Bayesian statistics and we start getting our with Bambi before moving on to PyMC, yeah? Yeah yeah yeah. So you have a regression refresher at the beginning. If you're a complete, complete beginner, then I would recommend taking our intro course first, which is really here. It's really from the ground up. The advanced regression course, well, ideally you would do that after the intro course.
But if you're already there in your learning curve, then you can start with the intro course. It makes a bit more assumption on on the student's part, like, yeah, they have heard about Bayesian stats. They are aware of the ideas of priors, likelihood, posteriors. But we give you a refresher about the classic progression. it's like when you have a normal likelihood. And then we teach you how to generalize that framework to data that's not normally distributed. And we start with BAMBEE.
We show you how to do the equivalent models in PIMEC. And then at the end, the model became, becomes, become like much more complicated, then we just show it in point C. Nice. That is super, super cool. I hope to be able to find time to dig into that myself soon. It's one of those things. yeah. You and I were lamenting this before the show, podcasting of itself can take up so much time on top of, in both of our cases, we have full -time jobs. This is something that we're doing as a hobby.
And it means that I'm constantly talking to amazingly interesting people like you who have developed fascinating courses that I want to be able to study. And it's like, when am going to do that? Like book recommendations alone. Like I barely get to read books anymore. That was something like since basically the pandemic hit. I, and it's, it's so embarrassing for me because I, I identify in my mind as a book reader. And sometimes I even splurge. I'm like, wow, I've got to get like these books that I absolutely must read. And they just collect in stacks around my apartment. Like yeah. Yeah. Yeah. I mean, that's hard for sure. yeah, it's something I've also been trying to, get under control a bit. yeah, like I find, so a guy who does good work, I find on that is, can you port Yes, Cal Newport, of course. I've been collecting his books too. Yeah, that's the irony. So he's got a podcast.
don't know about you, but me, I listen to tons of podcasts. So the audio format is really something I love. So podcasts and audio books. yeah, that can be your entrance here. Maybe you can listen to more books if you don't have time to write. Yeah, it's an interesting... don't really have a commute. and I often, use like, you know, when I'm traveling to the airport or something, I use that as an opportunity to like do catch up calls and that kind of thing. So it's interesting. I, I, I almost listened to no other podcasts. The only show I listened to is last week in AI. I don't know if you know that show. Yeah. Yeah. Yeah. Great show. I like them a lot. put a lot of work into Jeremy and Andre do a lot of work to get.
Kind of all of the last week's news constant in there. so it's impressive. It allowed me to flip from being this person where prior to finding that show and I found it cause Jeremy was a guest on my show. was an amazing guest by the way. don't know if he'd have much to say about Bayesian statistics, but he's an incredibly brilliant person is so enjoyable to listen to. and, and someone else that I'd love to make an intro for you. He's, he's become a friend over the years. Yeah, for sure. But yeah, last week in AI, they, I don't know why I'm talking about it so much, but they, I went from being somebody who would kind of have this attitude when somebody would say, if you heard about this release or that, or, I'd say, you know, just because I work in AI, I can't stay on top of every little thing that comes out. And now since I started listening to last week in AI about a year ago, I don't think anybody's caught me off guard with some, with some new release. I'm like, I know.
Yeah, well done. Yeah, that's good. Yeah, but that makes your life hard. Yeah, for sure. If you don't have a commute, come on. But I'd love to be able to completely submerge myself in Bayesian statistics. is a life goal of mine, is to be able to completely, because while I have done some Bayesian stuff and in my PhD, I did some Markov chain Monte Carlo work. And there's just obviously so much flexibility and nuance to this space. can do such beautiful things. I have a huge fan of Bayesian stats. And so yeah, it's really great to have you on the show talking about it. So, Pi MC, which we've been talking about now, kind of going back to our, back to our thread. Pi MC uses something called Pi tensor to leverage GPU acceleration and complex graph optimizations.
Tell us about PyTensor and how this impacts the performance and scalability of Bayesian models. Yeah. Great question. basically the way PyMAC is built is we need a backend. And historically this has been a complicated topic because the backend, then we had to do the computation. Otherwise you have to do the computations in Python. And that's slower than doing it in C, for instance. And so we have still that C backend. That's kind of a historical remnant, but more and more we're using. when I say we, I don't do a lot of PyTensor code to be honest. mean, contributions to PyTensor. I mainly contribute to PyC.
PyTensor is spearheaded a lot by Ricardo Viera. Great. great guy, extremely good modeler. basically the idea of PyTensor is to kind of outsource the computation basically that PymC is doing. And then, especially when you're doing the sampling, PyTensor is going to delegate that to some other backends. And so now instead of having just the C backend, you can actually sample your PIMC models with the number backend. How do you do that?
You use another package that's called nutpy that's been built by Adrian Seybold, extremely brilliant guy again. I'm like surrounded by guys who are much more brilliant than me. And that's how I learned basically. I just ask them questions. That's what I feel like in my day job at Nebula, my software company. just like, Yeah, sorry. I'm just completely interrupting you. Yeah no same. And so, yeah. So Adrian basically re -implemented HMC with NutPy, but using Numba and Rust.
And so that goes way faster than just using Python or even just using C. And then you can also sample your models with two other backends that we have that's enabled by PyTensor that then basically compiles the graph of the model and then delegates these operations, computational operations, to the sampler. And then the sampler, as I was saying, can be the one from NutPy, which is in Rust and Numba. And otherwise, it can be the one from NumPyro. actually, you can call the NumPyro sampler with a PIMC model. And it's just super simple.
Like in pm .sample, you're just like, there's a keyword argument that's nuts underscore sampler and you just say nutpy or NumPyro. And I tend to use NumPyro a lot when I'm doing Gaussian processes because I don't know why, but so most of the time using nutpy, but when I'm doing Gaussian processes somewhere in the model, I tend to use NumPyro because like for some reason in their routine, in their algorithm, there is some efficiency they have in the way they compute the matrices.

Ask anything
We've read this whole study set, so questions about it get the best answers.