‌

Listen on your favorite platform:

Enjoying the episode? Get the next one in your inbox

New episodes, blog posts and Bayesian modeling resources — roughly once a month.

Featuring Quan Nguyen

The last time Quan Nguyen came on the show, he was a PhD student and we were organizing PyMCon together. Now he teaches computer science at Fulbright University Vietnam, works on Bayesian experimental design and optimization, and has written his second book for Manning, Grokking Bayes -- a book I liked enough to write its foreword!

Quan managed to find the middle ground he couldn't find when he started out in Bayesian machine learning -- enough math to actually understand what your model is doing, and then all the way to what you do with a posterior.

Letting Models Fail on Purpose

One of my favorite things in the book is that the models don't always work. In the Bayesian linear regression example, a conjugate normal prior gives you beautifully clean updates... but also prior predictive samples that happily put probability on negative house prices -- oops!

When Quan started out, the debugging threads on the PyMC Discourse taught him so much that he wanted readers to get that experience rather than a parade of polished models that never misbehave.

Being Bayesian doesn't make your model good. If anything, all that flexibility means you have to work harder to make it behave: you propose a model, check, revise, repeat -- as I say in the foreword: statistical modeling is a contact sport.

From Posteriors to Decisions

A posterior tells you what might be true, but it doesn't tell you what to do. For that, you need a utility function describing how much you care about each outcome, and Bayesian decision theory then tells you to pick the action with the highest expected utility. Quan contrasts this with deciding by p-value threshold, which says nothing about what being wrong would cost you.

What I find elegant is how far that idea stretches: Bayesian experimental design isn't a new framework stacked on top -- it's decision theory where the utility measures how much you expect to learn, used to choose which expensive experiment to run next!

Bayesian optimization switches the goal from learning the whole function to finding its maximum, but frame that as learning where the optimum is. Adam Foster and Desi Ivanova went deep on it on the show, and Quan recommends the experimental design module in Pyro and Bob McMichael's lightweight optbayesexpt as places to start.

Start simple, and build from there

One connection I wanna emphasize, as many beginners ask me about this, is that regularization comes for free in a well-specified Bayesian model. Ridge regression is what you get from the posterior mode under a zero-mean normal prior on the coefficients. And dropout, invented to keep neural networks from overfitting, can be read as approximate variational inference -- keep it switched on at prediction time and your ordinary PyTorch model becomes a rough Bayesian neural network. Isn't this beautiful??

That doesn't make Bayesian neural networks a default though. Without conjugate priors, you're down to MCMC or variational inference for small networks and dropout for big ones, so Quan's advice is to check whether a simpler model captures your data first.

Is it still worth learning all this, though, now that an AI assistant can write the PyMC code for you? Well, the code may run and the diagnostics may look clean, but someone still has to choose the assumptions, the priors and the utility function. AI is shifting the bottleneck from implementation to judgment -- which, if you ask me, makes the concepts and fundamentals more valuable, not less.

Check out the full episode above, and the show notes for links to Grokking Bayes, Quan's research, and the packages we mentioned.

You can also interact with the episode on NotebookLM! Ask questions, generate flashcards, and more.

Hope you enjoyed it, and see you in two weeks, my dear Bayesians!

Chapters

11:38 Why does Bayesian statistics treat uncertainty as something to use, not just report?

30:22 Why does variational inference optimize the ELBO instead of the KL divergence?

42:31 What can a failed prior predictive check teach you about Bayesian modeling?

47:09 How do you go from a posterior distribution to an actual decision?

56:09 What is Bayesian experimental design and how does it relate to decision theory?

01:01:00 How is Bayesian optimization different from Bayesian experimental design?

01:04:09 Which open-source packages can you use for Bayesian experimental design?

01:07:18 Why can you keep updating a Bayesian experiment as new data arrives?

01:11:35 When are Bayesian neural networks worth it in practice?

01:15:13 How do you build Bayesian neural networks, and how does dropout fit in?

01:17:19 How is regularization a Bayesian prior in disguise?

01:25:06 Is learning statistics still worth it now that AI can write the models?

01:31:52 What are the risks of letting AI agents run your research analysis?

01:33:45 How can Bayesian decision theory be tailored to scientific discovery problems?

Let me show you how to be a good Bayesian.

Alex Andorra: My guest today is Quan Nguyen, a computer science faculty member at Fulbright University Vietnam,

where he works at the intersection of Bayesian machine learning, experimental design, and decision-making under uncertainty.

Some of you may remember him from his first time on the show, back when he was a PhD student and we were organizing PyMCon together.

Quan is back with a new book

Grokking Bayes

published by Manning

and full disclosure

I had the honor of writing its foreword

the book threads a very hard needle

building real intuition for Bayesian methods

without drowning you in measure theory

but without sweeping all the math under the rug either

I know that's hard

but somehow Quan made it

and we go from posteriors

to actual decisions with Bayesian decision theory, dig into Bayesian experimental design

and how it connects to Bayesian optimization.

And we discuss when Bayesian neural networks are worth the trouble and why dropout can

be read as Bayesian inference.

And of course, we ask whether learning all of this is still worth it now that AI can

write the models for you.

This is Learning Bayesian Statistics, episode 170, recorded October 13, 2026.

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, learnbayesstats.com is Laplace to be.

Show notes, becoming a corporate sponsor, unlocking Bayesian merch,

supporting the show on Patreon, everything is in there.

That's learnbayesstats.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/alex_andorra.

See you around, folks.

And best Bayesian wishes to you all.

Quan Nguyen, welcome to Learning Bayesian Statistics.

Quan Nguyen: Thank you, Alex.

It's nice to be back.

Correct me if I'm wrong.

Am I...

Oh, it's definitely not a correction, but just a question.

Am I like the recurring guest with the biggest gap between appearances on your podcast?

Alex Andorra: That's a good question.

Quan Nguyen: Someone should do that summary.

Alex Andorra: Yes, if somebody wants to do that.

I think, so my bet is that you're very close, but that probably the title goes to Osvaldo Martin.

Quan Nguyen: Oh, yeah.

Alex Andorra: because he was in episode one.

And then, but I'm not sure

because then he was again on the show.

I think the second one was with

Ravin Kumar and Junpeng Lao

for their book.

So I think it's close between you two.

That's actually a great question.

So we'll see.

We'll see.

Maybe, maybe.

If somebody in the audience

want to run that check,

I will definitely give you a shout out

if you do.

That's very nice.

Alex Andorra: Welcome back.

As you were saying,

Um, that's funny because last time you were on the, on the podcast, you were a PhD student, right?

Quan Nguyen: I was a PhD student.

Yeah, it was, uh, seven years ago.

Amazingly.

Alex Andorra: Yeah.

Wow.

Damn.

Yeah, it was a very beginning.

So, um, and that was for PyMCon, so 2020.

Um, and, um, now you finished your PhD.

You haven't finished a postdoc and now you're even working.

So yeah, update us on that.

You know, what are you doing nowadays?

And we'll get to your origin story.

But yeah, what are you doing nowadays and how did you end up doing that?

Quan Nguyen: Yeah, I am functioning for adult now, basically.

So I am currently working as a faculty at a university called Fulbright University Vietnam.

And it's like a rank equivalent to an assistant professor in the U.S.

and, you know, doing what professors do.

So I teach and I do research.

Most of the time, it's a balance between the two

and sometimes you get to, like, talk your students

that you're teaching into doing research with you

and that's, like, a really big add-on

where you get to work with them and you get to teach them.

So it's a really rewarding experience, too.

Alex Andorra: Yeah, yeah, I can definitely guess that.

I was at Princeton the other day and yeah, definitely makes you want to become a professor.

I was really awesome giving a seminar over there.

So, Jörg, if you're listening, thank you so much for the invitation.

I'll publish some of that on the YouTube channel at least very soon for people who are curious.

But yeah, I understand that.

That is a fun occupation, I have to say.

and how did you end up doing that?

You know, what did you start studying when you were younger?

Quan Nguyen: Yeah, I think when I was going to school,

I always had an inkling that I wanted to be an educator.

My parents, both of my parents, they were teachers.

So they were high school teachers.

So when growing up, I thought that, you know,

it's a really, it can be tiresome sometimes, you know, teaching, it takes a lot out of you,

but it's such a rewarding process in the end. You know, you get to see people that you guide

grow up and take on their own expertise and be successful in their own ways. And I think that

that is something that I personally appreciate a lot. So, you know, towards the end of my

PhD and my postdoc, I kind of shopped around a little bit at institutions in the US and Asia,

but then I decided that I would end up at this university in Vietnam. From my perspective,

it seems like there is a growing, a really exciting growing academic environment in Vietnam.

So we are still trying to set up a lot of different educational and research infrastructures at different universities.

So there are a lot of things happening.

And a plus is that I get to be close to my parents and my partner, which, you know, always helps with work-life balance.

Alex Andorra: Yeah, that's for sure.

uh damn okay so you were you were thinking of becoming a professor very early Quan Nguyen: oh yes I I should

also mention that um in the middle during high school and in college I I decided that I would

not want to be a professor after all but then you know during the process of doing a PhD I

I re-evaluate my considerations just because um you know at that time it seemed to me like

being at a university

really gives you

a certain level

of academic freedom

that you get to do

kind of

whatever you want to do

within reasonable boundaries.

So you get to explore

different things

that you're interested in,

teach the courses

that you want

as long as you're

fulfilling your responsibility.

That is something

that, you know,

only universities

or like really established

tech companies

like yours

get to do

and that is something

that I really appreciate.

Alex Andorra: Mm-hmm. Yeah. And what were you thinking of doing, you know, when you were updating your beliefs in high school?

Quan Nguyen: so I thought that um you know I was too socially awkward to work with too many students too many

people at the same time I just want to like focus on my own thing focus on the technical details

um report to my manager if I have to once a week just get all the details done um so so so that was

going through my mind like just I just want to like push the boundary of what is possible and

don't I didn't want to um I guess concern myself with the idea of teaching uh but you know that

is just um you know when when we're going through different phases in our lives we are like you said

our beliefs change we see new data and we update our beliefs accordingly um now I see teaching as

another form of learning in fact as as I'm sure you would agree you know when you um teach something

and you gather material content to for that um for that teaching experience you yourself have to do a

lot of learning and while teaching the students also um also end up giving you a lot of opportunity

to do further learning so that's that's like a two-way street Alex Andorra: yeah yeah yeah okay I was I was

kind of fishing and see if you were gonna say something you know I think more um like completely

opposite to like oh yeah I wanted to become an actor or or a dancer or a basketball player that

that would have been Quan Nguyen: so you know I briefly considered um a career in uh bartending just

because I really love the aesthetics of being a bartender mixing up drinks and whatnot uh but then

I tried it out a little bit.

I found out that I wasn't very good at it, but the passion is still there.

So in my own free time, if I do have some free time, I try to kind of do some of the stuff that we will be talking about today.

A Bayesian experimental design, Bayesian optimization to kind of like come up with new drink recipes to maximize my enjoyment of them.

So that is something that I've been trying to look into.

Alex Andorra: Wow.

Okay.

Damn.

That is cool.

Makes me want to open a bar where all the cocktails would be Bayes inspired.

Quan Nguyen: I know.

And the name of the bar obviously would have to be something of a pun.

Alex Andorra: Right.

Yeah.

Yeah.

I have to think about that.

But like, yeah.

Something like the Bosmopolitan or something like that.

Oh.

That'd be the first cocktail.

Yeah.

Alex Andorra: next time I'm in Vietnam

definitely have to take you up on that

and try some of your cocktails

I'm sorry but that's how it goes

Quan Nguyen: I would love to

Alex Andorra: and now everybody knows about it

so you don't have to do it

Quan Nguyen: and everyone's gonna

come visit Vietnam

and how happily they should

Alex Andorra: they should for sure

and actually so talking about Bayes

what drew you to Bayesian stats

specifically

Quan Nguyen: I think what I really enjoy

I don't remember specifically at the beginning

what drew me to it first

but now taking a step back

in the overall picture

I think I really enjoy one specific aspect of it

and it's the fact that it really embraces uncertainty

you know

so in perhaps in other frameworks

you might not care about uncertainty that much

or you might say

oh we do have uncertainty quantification which is something that adds to the end of our report or

whatever but with Bayes you you truly embrace it it is part of your model it's part of your identity

and you use it actively to uh make to um to uh design your models and make decisions so one

example that um well I guess we'll have more opportunity to talk about in the book is you know

considering two different options.

And one could have a really high expected payoff,

but there could be scenarios

where it leads to a negative utility,

like a cost that you have to pay.

But the other option could have,

in comparison, a lower expected payoff,

but almost all of it is a net positive.

So, you know, balancing between those two options

and figuring out which one you would like

is a really important question.

And Bayesian reasoning,

Bayesian decision theory,

Bayesian probability

gives you kind of a really principle

way of approaching it.

So I really appreciate the fact that,

you know, it's the entire framework

and the combination of the different tools

is like really coherent.

So you start out with some assumption,

you have to be very explicit

about those assumptions.

and then you combine that assumption

with the data that you actually observe in the real world

and then update your resulting belief

and then in that process,

you update your uncertainty about what you know about the world.

So it's like everything works in contention with one another

and I really love that fact.

I was thinking about the difference between that

and some other frequentist tools

that people might be familiar with.

You know, we teach these tools in college,

like t-tests or ANOVA analyses and whatnot.

And I remember when I was taking those courses,

and I don't want to, you know,

talk badly about these tools too much

because that could seem quite mean,

but they could sometimes feel unnatural and mechanical, right?

Like specific steps that you have to go through.

And regardless of which situation you're in,

you always apply them.

And if there's something that happens, then it's quite hard to kind of get to the final step that you want.

So it's unflexible in that, or it can be unflexible in that way.

So I really enjoy the fact that Bayesian methods are, they require you to be more explicit and to work harder to set things up.

But once you have things working, then everything just naturally flows from predictions, uncertainty quantification, and decision making.

Everything flows in the same direction.

So that is really nice.

So I guess another thing that I should mention is that I don't want to make it sound like Bayesian methods are always better.

Because like we just talked about, it takes a lot of effort to set things up.

You have to be very explicit about your prior, your assumptions.

And sometimes it's really hard to encode those assumptions too.

Sometimes you have this prior knowledge about the data

and you can't really find a prior distribution

that exactly encodes that knowledge.

Sometimes people disagree on what priors are appropriate.

So that is also a big contentious point in the Bayesian community too.

but despite all of that I feel like if we um if we have a way to set things up correctly then

um everything else would feel very natural Alex Andorra: yeah yeah yeah um completely completely resonate with

that uh for sure and and I think it's it's also something you um you evacuate in your new book

because you have a new book out. That's also why you're here today. Your new book is called

Grokking Bayes with Manning. So congratulations. I know this is so much work. So yeah,

congratulations on doing that. This must have been a multi-month project, I'm sure.

Quan Nguyen: I think it started last year.

Yeah.

Sometime around the summer last year.

Alex Andorra: Mm-hmm.

Well, damn.

Yeah.

So it's always like that.

And yeah, congrats on doing that.

This is absolutely awesome.

I had the privilege to read the book because you were kind enough to ask me to write the foreword of the book,

which I think is very smart from you because, you know,

people will read my foreword and then they will read your prose

and then in comparison, you'll look like a much, much better writer.

So this very smart one, well done, is quite a nice inception.

Quan Nguyen: I did have an idea in mind that I thought was smart,

but it's definitely not what you just described.

And that is, I wanted you to be, you know, the, the, the recommender of the book.

You would, you would vouch for the book, right?

So if it completely fails, then, uh, your reputation, Alex, it's on the line.

And, uh, so I will have like a much bigger figure in the Bayesian community to gonna stand

next to me and vouch for me.

So that's like a way to kind of hedge my bet that way.

Alex Andorra: Well, thank you, Quan.

Yeah, I appreciate that.

And, uh, and yeah, definitely loved your book.

So recommend people check it out.

I think there's so many great things in it that we're going to talk about that today as we talk also just about the work you do and the way you teach.

Before that, though, you know, I always love learning how things started.

So can you tell us more about why you wanted to write the book and for whom?

Quan Nguyen: Yeah, and I think this is the case for many authors

where they, you know, when they first started out learning about something

and they saw that, yeah, there are a lot of resources out there

and this is especially true for Bayesian methods

the Bayes theorem, Bayesian models

there are a lot, there have been a lot of great resources out there

but for my own purposes

there seemed to be somewhat of a gap

you know, I, my background is in

Bayesian machine learning.

So we try to leverage the Bayes theorem

in Bayesian machine learning models,

prediction tests, decision-making tests.

And when I was first starting out,

it seemed to me like there were great resources

at two extremes.

So there are great resources that focus

on the mathematical aspects of it.

So you really dig deep into measure theory, really complicated integrals, how priors can be designed and whatnot.

They weren't what I was looking for because I just wanted to kind of leverage Bayesian methods for my own purposes for machine learning models.

So I wanted to kind of shy away from the math a little bit.

And there were other resources that were at the other extreme, you know.

So these would be really hands-on tutorials that teach you how to use really common libraries like PyMC or Stan.

And they just dig deep into the code and tell you, oh, if this happens, then set this parameter this way.

If the other thing happens, then you do label switching or whatever, yeah.

um but um to in order to do that you kind of have to sacrifice a little um some math a little bit

you kind of have to sweep that math in the under the rug to really focusing focus on the hands-on

stuff so those were the things at the other extreme and uh I wanted something in the middle

right so so I wanted to kind of still build my mathematical intuition so that I truly understand

what these Bayesian models are doing,

but I want to understand them

to the extent that I can effectively use them

in my own work,

as opposed to actually dig deep into the research

and propose new models, for example.

So this is something that I wanted for myself,

and I hope that some people will be able to benefit from

where they want to have a working intuition

about Bayesian methods,

but they don't want to dig too deep into the math

because they don't have the time and don't have the resources to do it.

So that is my ultimate goal.

But, you know, on a higher level,

this is also an effort to kind of convert more people to Bayesianism.

You know, in my own personal opinion, I think you would also agree

there is a little Bayesian in all of us, right?

like a little intuition that works in the same way as Bayesian statistics,

where we all form prior opinions based on previous knowledge

or what we thought was good, what we thought was correct,

and then we see new data, and then we update what we believe about the world,

and then we use that updated knowledge to make decisions.

So like that very natural intuition and natural intuition and process is what Bayesian methods help us do in a more formal context.

So I just wanted to kind of connect that innate mental model to what we have as a mathematical model that is Bayesian methods.

So that is like my contribution, I guess, or what I hope would be a contribution to the Bayesian community to get us more converts to join our club, basically.

and and and one thing that I also wanted to do is to kind of um go a step further and talk about

decision making because that is a crucial step while um do using any models at all building a

predictive model most of the time when you train um and predict with a with a learning models you

kind of don't want to stop at just making those predictions right you most of the time you use

those predictions to make new decisions. So that is a big part of what you can do really naturally

with posterior distribution too. You can use that posterior distribution to evaluate what

is possible and what is plausible and what's unlikely to happen. And then based on that,

you can make decisions about which action to take, which data to collect, which

input function,

which input we should evaluate a function

at to do whatever you want

to do. So this, I think,

really showcases

the flexibility of these Bayesian

methods where they allow us to

very

flexibly express what we know and what we

don't know, and based on that, we can

make decisions. So it gives us a really

coherent framework.

Alex Andorra: Yeah.

Yeah, of

of course, I agree with that. And I'm also biased as you were saying so for sure. But I think it's great that you come with this background and this need that you have and usually writing the book that you wish existed is a good reason and motivation for doing so.

So, yeah, and I think it shows definitely in the book that you do it from a very practical perspective.

And as you were saying, you don't assume that people are math experts to pick it up.

I'm curious now, how did you decide what math to keep and what math to leave out?

Because for me, it's always a difficult needle to thread when I'm teaching where, well, you know, I want students to understand the details, but I don't want them to feel overwhelmed.

And you still want them to be slightly uncomfortable because that's where growth is.

Oh, yeah.

And at the same time, you don't want them to feel completely discouraged.

So, yeah, I'm curious, how did you think about these topics for your book?

Quan Nguyen: Yeah, I'd love to answer that question.

But before that, I would love to ask you a question too.

Have you ever gotten yourself into the same situation where you thought a resource that you want to exist didn't exist and you were entertaining considerations of writing a book yourself?

Alex Andorra: Yeah, yeah.

So the podcast is exactly that.

yeah I started the podcast because I wanted to learn

Bayesian statistics and I learned a lot through

podcasts and at the time

no podcast existed about that and so

then I was like huh maybe I can start

one

Quan Nguyen: I imagine doing a podcast

harder than writing

Alex Andorra: to me it's not

to me writing a book is much harder

I actually started

writing a book I think in 2020

but then I stopped

It was, yeah, it was too much work for me at the time.

But yeah, I mean, I do, I mean, I wrote a book already in 2016, but it's just not about statistics.

So I know it's a grinding process.

I would say I prefer the grinding process of teaching live and podcasting and video courses than the grinding process of writing a book.

but I mean I'm definitely curious about writing one at some point and we'll see when that happens

about what it happens to be and and and how I like that that process you know so so we'll see um

night the the door is always open he's just saying I need to open it at some time at some point when

I feel like it. Quan Nguyen: Oh yeah. And obviously time is of great importance to you and being able to

find the time to do it would be a big, big challenge. Okay. So getting back to your

question about, you know, choosing which math to keep and which math to leave out,

that is definitely an important consideration. And I don't want to make it sound like I,

hold the key to

figuring this out. I still

don't know how to do this

100% well.

The book just came back

from the third round of review,

which is the last round

of review, hopefully.

And there,

fortunately and

unfortunately, maybe, were so

many comments and questions

about the level of

math that the book

exhibits. So our reviewers have really strong, and this is a good thing that they do,

really strong opinions about whether I should keep more math and whether I should leave out

more math. So it's an ongoing process for sure. But a goal that I set up for myself is to kind of

only introduce math when it helps the readers to kind of understand something concrete.

So, for example, when someone is introduced to Bayes' theorem,

they should know about conditional probability

and the fact that we have to normalize all these unnormalized posteriors

when we multiply the prior and the likelihood together

so that the

probability sums to one

that is a

rule in probability that we need to

uphold but there is

so much more

complicated math that is associated

with Bayes like

measure theory or really complicated

integrals and as tempting

as they sound

you know

it might not be necessary

for a complete beginner to

really dig into that math just like

how I myself didn't really need to dig into all that math when I was doing my own work.

So I think that kind of takes us to this real difference between understanding what a math,

what a mathematical object means and being able to like take that object and go do your own work,

manipulating it and developing new theory with it.

So for me, I think for a complete beginner who's just starting out learning about all these things, just understanding the intuition behind that mathematical object, the mathematical expression is valuable enough so that they can gain a working knowledge about how these models are learning.

so I think that is what I was trying to do

to kind of keep the math that kind of gives us an insight

into what is truly going on

so one example that I was thinking about is

when you use variational inference to train a Bayesian model

this is when you don't have conjugate prior

and you don't want to run MCMC because it might take a long time

so an alternative is you use variational inference

and in order to do this you kind of want to optimize the KL divergence between

the distribution that you're using to approximate your posterior and the true posterior that you

cannot get to so you want to kind of minimize the mismatch between these two things because you want

your your approximator to be as close as possible to what you're approximating

but you know that KL divergence quantity it's quite difficult to calculate it's quite difficult

to approximate so I went into the math a little bit to kind of show why it is so difficult to

compute and then we started talking about in the book this ELBO quantity which is this lower bound

for this KL divergence.

So it kind of opens up a new way

to optimize this KL divergence

by not directly optimizing for it,

but optimizing for a lower bound of it.

So it not only gives a working understanding

of how variational inference works,

but also builds up to a larger theme

about what many people are trying to do,

which is, oh, they have an objective that they want to achieve.

They tried to do it and they couldn't.

So they came up with an approximate way to do it.

And even that we wouldn't be able to achieve directly either.

So we approximate, approximate.

So it showcases a larger theme, I think, in math and probability in general,

which is the fact that there are things that we cannot get to,

but we can try really hard to approximate it,

and that might give us something that we can use.

And then, you know, other times,

maybe a high-level intuition would be enough.

So there's a really cool thing that I think is really cool.

It's the fact that a neural network,

just a regular neural network trained with dropout,

which is a particular technique of regularization,

for deep learning models.

So if you have a neural network

trained with dropout,

you can enable dropout

while making predictions.

And that will give you, amazingly,

a Bayesian neural network in some way.

So that is something that I found super cool.

And there have been people that wrote papers

that proved the fact that,

oh, a neural network would drop out during inference

is indeed a Bayesian network.

and there are various interesting mathematical properties that you can prove.

But just that fact alone, I think, is enough to really amaze people.

And that is the high-level idea that I wanted to focus on

so I cannot hit away all the different math involving it.

But I hope that just that fact alone is enough to keep people interested.

Alex Andorra: yeah yeah definitely I mean it's super interesting and do you want to talk a bit more about why that

why that's the case you know what does that mean for uh a neural network to be trained with

uh dropout and why that would converge to um to I mean a be equivalent to a Bayesian neural network

I think it's a fun uh yeah I think it's a fun part of the of the conversation we can

Quan Nguyen: actually I do

I did like add

one extra question to your list

where I

also like put in some

stuff about regularization that also

included neural networks so if

that is like

more convenient to talk about

at that point

I think it's like it's later

in the conversation we can talk about that

then too if that makes more sense

Alex Andorra: sure sure let's do that

and

so actually

something I wanted to

ask you about also is your

first real model

in the book

it's not about the coin

so yes

it's about five co-workers

Quan Nguyen: such a big breakthrough

Alex Andorra: yes exactly

and you took an example with five co-workers

and whether they prefer tea or coffee

which I have to say is weird to me

because I absolutely don't know who would prefer tea.

Quan Nguyen: What do you mean?

Alex Andorra: Tea just leaves with hot water.

Quan Nguyen: That is the beauty of it.

Coffee is what?

The equivalent of hot water with beans?

Alex Andorra: Yes, but the process is much nerdier.

So, you know, that's what I love in coffee.

no but kidding aside

yeah I thought that was

that was great

so why did you want to start

the book here

Quan Nguyen: yeah thanks for the comment

so I would

love to take all the credit but no

the credit goes to my

PhD advisor Roman Garnett

he was the first to

introduce me to this beta

binomial for the listeners

this is a beta-binomial

model that we're talking about

And he framed the context of this model under an even more contentious debate, which is the Coca-Cola versus Pepsi debate.

So it's a whole thing.

Anyway, so this classical inference problem that some tech companies are still using to interview their candidates,

where we want to estimate the bias of a coin.

So a regular coin, when you flip it, there's a 50-50 chance that it will land on heads versus tails.

But here we are saying, oh, this coin might be biased, but we don't know the bias.

But we flip it a bunch of times and we observe how many times it lands on heads and how many times it lands on tails.

And then we use that data to kind of try to estimate the bias of a coin.

Which I've always found to be a bit abstract.

I never found myself really wondering about the bias of a coin in my real life.

It's just something that I'm not really interested in.

But the tea versus coffee example, I feel like,

similar to Coke versus Pepsi,

is contentious enough that gets people wondering and thinking about.

And it's what we all want to do with probability and statistics,

to answer questions that we truly care about.

I first came up with the idea when I was, this is slightly off topic, but there was this really cool thing that you can do with Gaussian processes, which is a specific kind of Bayesian models.

where usually it's a regressor,

so you train it with real value labels

and then you use that to perform regression.

But there's a special form of Gaussian process,

a special way to train it,

where you train it on pairwise comparisons.

So you just say, oh, point A is better than point B,

point 1 is better than point 1.5 or whatever,

and you can totally train a Gaussian process regressor

on pairwise comparison data in that way.

And that's super cool.

Anyway, I was thinking about giving a talk

on that topic at PyData.

And I talked about how much sugar to put into my coffee.

And because whenever we drink coffee,

our mood changes from day to day.

So it's really pretty difficult to score the coffee

that you drink consistently in terms of how good it is

if you put this amount of sugar in it and how good it is if you put a different amount of sugar.

But the next best thing you can do is to compare different amounts of sugar in terms of how much

it agrees with your personal taste. Anyway, all of this is to say that from that experience,

I found that, you know, beverage is, you know, a really big topic among people like us who

all have very strong opinions about which drink to uh which drink other people should drink just

like you Alex have you also have very strong opinions anyway so the idea is we want to

ask use probability and statistics to answer questions about people and try to infer something

about people from data so what do we think is the proportion of people that prefer tea over coffee

you know if I ask your prior Alex that's probably a really small one you know uh 0.001 out of

everyone would prefer tea over coffee you know how and then we observe some data from a survey

and then we can estimate that proportion but then we can ask how uncertain we are about that

prediction um as we're building the model which assumptions that we're making and um what

conclusions would we draw if we were to see more data right so as 20 more uh data points come in

from our survey or 200 more 2000 more how are some how how our conclusions would change based

on that so that is quite that is something that many people many um scientists many researchers

deal with every day, right?

They work with something they're interested in.

They have questions about them.

They observe some data and then they ask more.

They can answer those questions to some extent

and then they observe more data.

They can answer those questions to even a bigger extent.

So the idea here is just trying to frame it

under a context where many people have strong opinions about

So they get them to start thinking about these things and then they get to generalize to other things that they themselves are interested in.

So when I was teaching this model at my university, I changed the objective from tea versus coffee to whether a student is a CS major or not.

So the goal here is to estimate the proportion of computer science majors within the student body.

And hopefully that's something that my students find more interesting to think about than conflicts, too.

So all of this is to say that I guess I like to stir the pot and try to get people talking about what they feel strongly about.

The bias of a coin is like the gold standard, right?

That's something that every one of us could think about.

And that's a really clean example.

but to get people really thinking

and being interested in the conversation,

it helps a little bit to be more controversial

and touch on something that they really care about.

Mm-hmm, mm-hmm.

Alex Andorra: Yeah, yeah.

That's actually very smart

because that's where you grab the attention of the students

and what counts is not really the actual answer

but the whole process of how you get to the answer.

which is what you want to teach.

So, yeah, I really love that.

And I encourage people to do that also sometimes

when they want to teach something.

And another thing I loved in your book is that you let the models fail,

which is awesome, like something I really love

because I do that all the time when I teach.

that's also why I have the podcast

is to show people

the messy reality of

modeling

I remember in the book you have

a prior predictive checks on

prices and

the first one

the first check you do on this is

you get negative prices

you get some weight

some probability mass of the negative prices

and then you go back and

fix that so

So why was that important to you to do that?

Quan Nguyen: Yeah, I think just like you, when I first started out,

I myself encountered those questions, those problems.

So what I did was just to go to the PyMC discourse forum

and I saw so many different insightful and illuminating conversations.

And I really wanted to kind of recreate that experience in the book.

because I don't really have the need for my book to be academic,

so I just want it to be as approachable as possible.

So for our listeners,

we are talking about this Bayesian linear regression model

where if you have a normal prior,

then you can get a conjugate prior,

and then that will give you a really nice, clean way to update your model.

But the thing about a normal distribution

is that it inevitably puts probability on negative values,

So that is something that is quite intuitive if you are using it to model housing prices like Alex was saying.

So there aren't really negative prices out there.

So that is something that we need to flag for our model if we want it to truly, truly follow our intuition in that way.

So we can use a prior predictive check to kind of discover these problems with a Bayesian model before we even see data.

So we can use a predictive check to determine the model is describing a word that we find possible or not.

So I think that that goes a long way, or I hope it goes a long way, in showing this iterative nature of Bayesian modeling.

You know, you come up just like the iterative nature of Bayes' theorem itself.

You know, you have some prior, you update it on data, and then you rinse and repeat.

Here you come up with a model, you test it out, you see some things that you don't like,

you revise it to address it, and then you keep repeating it until you are happy with

what your model is doing.

So I think that, yes, it shows that, you know, there are things that you can do to address

the things that you find in a predictive check

and it builds up to a larger overarching idea

of that is the iterative nature of Bayesian model.

Alex Andorra: Yeah.

Yeah.

And also I think it's great because it shows people

it's completely normal to not have the,

a good enough answer from the beginning.

Oh yeah.

And then the,

that

modeling is

an inherently iterative process

and that it's a contact sports, if you want,

where you really have to get

your hands dirty with the data

and a few first models

and bang your head against the wall

for these first few iterations

and then at some point you'll get to something

that's good enough and you're satisfied with,

but it's going to take time and persistence.

Quan Nguyen: And it's very rewarding.

I still run into problems nowadays

where I see some error that I haven't seen before from PyMC

and it's just like, oh, now I have to Google these errors

and see what I can do with it.

At the time, I didn't feel that excited about debugging my model,

but, you know, on a grander scheme of things,

it is really good that, you know,

we are able to iteratively adjust our model

and then there exists a community of PyMC developers

and users that are always ready to help us out.

Alex Andorra: Yeah, yeah, yeah, exactly.

And another chapter I was really interested in

in your book is the one about Bayesian decision theory,

which is always something I find very important in practice in industry.

So, yeah, and you tell us how you recommend people go from a posterior to an actual decision.

Quan Nguyen: This is a topic that I'm greatly interested in.

So do let me know if I'm like taking too much time and we're just going over a lot

and we're running out of time.

But the idea here is that a model can't really tell you what you should do on its own.

So you get some prior, you update it to a posterior, and you can use that posterior to make predictions about what is likely to happen, what is not likely to happen, what is the average case, whatnot.

So it gives you information about what might be true, but unfortunately, that is not enough to tell you which action to take.

So another crucial part of decision making is to think about the consequences of the different actions, different scenarios.

We take those actions.

This is what a utility function comes in.

So utility function is a really common object in decision theory, reinforcement learning, all that stuff, because it kind of separates out what we believe and what our preference is for individual outcomes.

So we combine these two things, and that gives us a clean framework of how we can make decisions under uncertainty.

So we were talking a little bit about that example of choosing the two different options.

The first one has a higher expected utility outcome, where they say that, oh, on average, if we take the average case, then it has a higher utility than the other option.

But there are scenarios where you might incur some cost.

While the second case, the average scenario, you don't gain as much utility,

but most of the time, your utility is a net positive.

So there is a real trade-off between how much of what you believe

would lead to a good scenario

and how good exactly are those different scenarios.

So using Bayesian decision theory,

you have a way to kind of take all of that in

and formalize that process.

And we do that by we consider the different outcomes

that might happen under each decision

and then we weigh the utilities by their probabilities

and then we choose the action with the highest expected utility.

and I think it's

such a mathematically satisfying

process where you

just like oh I have this

I can just try to apply it

to many different scenarios

and maybe

I promise this will be

the last time that I

say something mean about

frequentist statistics but

the idea here is I'm thinking about

this p value

that many people use

I also use it in many situations, but many people use it to make decisions too, right?

So you say p-value is below a certain threshold, then we take some action that is in alignment

with the alternative hypothesis that whether null hypothesis has been rejected, things like

that.

But that is not something that is pretty straightforward to me.

it seems like regardless of how much we can disregard a hypothesis,

there is still a separate issue with how much it would cost us if we're wrong

and how much it would benefit us if we're right.

So that comes down to the behavior of our utility function.

And this is nice because I think it also models what we usually see in real life.

So you can imagine two people agreeing on their knowledge of the world.

So basically they have the same posterior distribution.

So they think what is likely to happen.

So the first person thinks what is likely to happen is the same thing that the second person thinks is likely to happen.

But they can still rationally choose different actions because they have different utilities, they have different preferences.

So that is a really satisfying thing to see where your mathematical model simulates the real world.

So I really love that framework.

And on a personal note, I also hope that by living it, you know, I get to be, I become, I can become more tolerant and understanding of people's preferences and how even if we agree on the data, we agree on our predictions, we can still come to different decisions.

Alex Andorra: Yeah, yeah, exactly.

that's something I use a lot

to explain

to people also why

you can observe the same

data and reach different conclusions

and in this case

try and pivot the conversation more

to the priors and you'll see

that it will

usually move things along

but yeah

I think it's really

awesome you have that chapter

in the book to be honest

because usually the books that try to teach Bayesian stats from scratch

don't have these kind of decision-oriented chapters

because they are usually regarded as a more advanced topic.

But weirdly, I don't think they are that advanced

and more than anything,

I think they are extremely important

because as you were saying,

they allow you to go from model results

to actually making decisions based on the model.

And in the end, that's really what you want to do

and want people to do

because otherwise your model ends up not being used.

So I think it's really awesome

that you have that in the book.

Quan Nguyen: Thank you.

Yeah, and I think I really agree with you

that, you know, sometimes it feels to me like Bayesian decision theory is even more natural

to think about than Bayes' theorem sometimes, right? Like when I teach Bayes' theorem, I

tell my students, hey, you have to multiply the prior by the likelihood and you have to

normalize them. And normalization is really hard if you're working with sufficiently complex

model. But the idea of, you know, just calculating the expected utility of an action by just

summing their utilities by their probabilities and just getting out the action that gives you

the highest expected utility, that is something I feel like most people would naturally agree with,

right? It's like, oh, I'm making decisions under uncertainty. I don't know which outcome I might

get. But I can specify what I would enjoy if it's this outcome and I take this action or

the other outcome and I take another action

and then I just try to

do well on the average case

that is something I feel like most people would agree with

Alex Andorra: yes

yeah exactly

the

way the decisions are

computed

from the posterior samples

is usually something that's very

intuitive

because

people end up making a ton of decisions

all the time and so

they do have that calibration that's better um and and they understand also the idea of loss

functions and and things like that so yeah um I completely agree with you Quan Nguyen: this goes to show that

there is indeed a little Bayesian in all of us after all Alex Andorra: oh yes yeah yeah I think so uh and I

think to a lot of people it's actually more intuitive than you know a lot of different

kinds of models like beta, beta-binomial for instance, not very intuitive to people.

That linear regression is not at all intuitive, and things like that, whether that kind of stuff

relates much more to what people actually do day to day. And so I think it's something we can we

can definitely leverage when teaching. Time is flying by and I do want to talk about well, the

the neural networks, as we were saying, but also experimental design, because I know it's

a topic.

It's a topic of your PhD thesis.

So you know a lot about that.

Obviously, the book ends on that, Bayesian experimental design.

We've talked about that already on the show with Desi Ivanova, with Adam Foster.

I'm sure I'm creating some episodes, but we've talked about that already.

So if folks are curious, definitely give these episodes a listen.

I'll put them in the related episodes for this one.

Quan Nguyen: And Desi and Adam, they are the true experts in the field.

So they would have many more things to say.

Alex Andorra: I think you are too hard on yourself, Quan.

Not at all.

You have a lot of things to say.

Well, actually, can you tell us more about that and how it connects to Bayesian optimization,

which is a topic we just talked about.

Quan Nguyen: And again, right, like you have had these amazing conversations already,

so I would love to just touch on the high-level idea.

The thing is, you know, for traditional statistics or Bayesian statistics,

most when you take these courses in university, for example,

and you read resources online,

people

we usually

stop at

just framing it

as a learning

or inference

problem

where you

start with

some data set

and you

train a model

and then you

make predictions

maybe you

take actions

from it

but in real life

we

in some

situations

the setting

is a bit

more complicated

in the sense

that we

don't only

get to

take action

but these

actions actually

affect which

data points

we actually

see in the

future

so imagine

this like

a loop where you start out with a model and then you make some predictions and using those

predictions you choose new data to observe and that new data will be appended to your

to your training data set your observed data set and that will get to will um will

will use it to update your your new model and the whole process repeats for a number of times so

So this is really prevalent in scientific discovery specifically, where you're a scientist and you want to understand a phenomenon of interest, like whether this material will produce, sorry, these molecules will produce a material that they are looking for with durability or they can produce a drug that will fight cancer or whatnot.

right um but they have a really big database of molecules that they can search for but every time

you you they take a molecule to produce to perform experiments on to produce drugs with um to produce

new materials with it's really time consuming um or really expensive to do so they cannot

exhaustively search through the entire database so they can only get to choose a small number of

experiments out of it. So what we want to do is we want to choose the most valuable data points

to label in order to best do what we do. So this is where the name comes from, right? You're

designing your experiments so that you achieve what you want to achieve. So you're doing

experimental design that way. So one thing that people usually do is just randomly choose

different experiments. But as you can imagine, if you have a model that reasons about what you know

and what you don't know, you can leverage that model to identify the most informative data

points for you to learn from. So Bayesian Experimental Design, or BED, is this framework

for you to do it, where you apply a model, and then you think about where your model is most

uncertain about, or which data points will get you to learn the most or gain the most information

about what you're interested in, and you choose

those data points you label, and you

do it repeatedly until

you're satisfied with

the scenario.

And what I really love about it is that

it's not something new, it's not a new

framework that you have to learn in addition to

Bayesian stats and Bayesian decision theory.

It's literally just

raw Bayesian decision theory

applied to a particular utility function

which quantifies how much knowledge

you have about the unknown quantity, and

there you go. You just

do that for that utility function called entropy and then you have Bayesian experimental design

BED out of it. Super clean, super satisfying and I just love it so much. So let me also quickly

talk about, answer the second part of your question which is about Bayesian optimization.

So it's slightly different from BED where the goal isn't to like exactly gain information

and learn as much as possible,

but it's about finding an input of the function

that produces the best outcome.

So you can imagine finding the best architecture

for your neural network that maximizes accuracy,

or finding, some people have been using Bayesian optimization

for scientific discovery too.

So they find materials with the highest durability,

materials that react to stimuli in a certain way.

So those are the scenarios where you can apply Bayesian optimization, where the settings

are the same.

You cannot really obtain too many labels out of your objective function because it's super

expensive or time consuming to do.

So you want to just pick out a couple of data points to evaluate the function on, but you

still want to maximize that function.

So it's different from Bayesian experimental design in the sense that you're not trying to learn about the entire function, the entire surface response, but you are learning about or you want to learn about it sufficiently so you can identify the functions maximum.

But that is not to say that the two topics are completely unrelated.

So a lot of people take this information theoretic approach.

information theory is this subfield in math that Bayesian experimental design is based on a lot.

So a lot of people, you leverage that field for Bayesian optimization too. So as you can imagine,

one approach that you can take to optimization is that, oh, I want to frame it as a learning

problem and I want to learn the functions optimum. That is my learning objective. So I can

do Bayesian experimental design to gain information about the functions maximizer and the entire

machinery of BED would apply to Bayes R2. So that's like that's a super cool I think and there's

so many different connections to be made between these two things. I hope that now is a good time

for me to like quickly plug the book that I wrote on Bayesian optimization is called

Bayesian Optimization in Action by Manning, too, where we go deep into Gaussian processes,

which are the models that we use to do Bayesian optimization most of the time. And then there are

discussions on different decision-making heuristics. You can take an information

theoretical approach, but there are other approaches that you can do for decision-making,

too. So all of that is

discussed, hopefully

to a

satisfying extent in that

Bayesian Optimization in Action book.

Alex Andorra: Yes.

Definitely great plug,

Quan. I think it's

perfect. That fits

perfectly well.

I was also wondering

what do you

recommend, if anything,

as

open source packages that people

can use to do Bayesian experimental design?

Quan Nguyen: So there are a couple of packages

depending on the user's own use case.

So I believe in Pyro or NumPyro specifically,

there is a great Bayesian experimental design framework

that is developed by the people related to

uh, Desi, uh, Ivanova and Adam Foster.

So, uh, these folks from the same lab worked on, um, these things.

So it's like the state of the art, you know, like, um, things that appear in research papers

will be implemented in these packages, NumPyro or Pyro.

Um, so that is something that if you're looking to use that, that is the state of the art.

there is

a really

folksy, low

effort, lightweight

library that I found

a couple of years ago. I think it's called

Bayes

Experiment

Art. I'm

wrong, but let me quickly search

for it.

It's a

GitHub

repository

on, oh, that's right, it's called optbayesexpt.

It's developed by Bob McMichael, who I think is, yeah,

so he's at National Institute of Standards and Technology.

So I think it's like a personal project almost

that this guy started to use Bayesian experimental design

for his own problems, and it just turned out

to be a really good package that a lot of people can use.

So the way that you use this package is it has a bare bones structure for your Bayesian

experimental design.

And you come in and you specify your likelihood and you specify your prior and the unknown

quantity that you care about.

And then everything also goes.

So that, I guess, goes to show this coherent structure that all these Bayesian methods

have where you say oh I want to develop a framework to learn about all these things and I have all

these tools and I regardless of which setting I find myself in there's always a way to apply these

things um as long as we set up the problem correctly Alex Andorra: yeah yeah and actually so I linked

already to your first book in the show notes, but you should definitely link also to these

two packages.

So there's a package in NumPyro to do BED and that last one that you mentioned.

I will do it.

People who want to try to do some BED, that's where they are going to start.

and actually

is that something

you also recommend to people who

work in industry and do a lot

of experiments and they see

they have trouble with classic

frequentist experiments

is that something you recommend they give a try

to? Quan Nguyen: I think so

right like people in

the industry just like people in academic

research they all face their own

experimental design

problem

one way or another, right?

Because in many different situations,

obtaining labels is very expensive,

either in terms of time or money

or some other safety critical conditions.

You don't want to do it too many times.

So even if you don't think the problem that you are facing

fits nicely into the framework,

there could still be ways for you to kind of leverage

these tools to your own use cases.

and, you know, different ways for connections to be made.

And when there is a connection that is indeed made,

then it is a really satisfying thing.

Alex Andorra: Yeah, yeah, yeah.

I mean, especially because classical frequentist experimental design

can be extremely complex, you know, with the peeking problem

and the fact that you cannot do multiple comparison

in all the statistical significance issues,

and also the fact that you have to know in advance

how long you want to run the experiments for

because it depends on which magnitude of effect you want to detect.

So all these things make it extremely complex already.

and sometimes switching to BED can make people's life much easier.

Quan Nguyen: I think I agree.

And I think this is connected to the difference between a frequentist test like a t-test

and Bayesian model comparison or model evaluation or whatever, right?

Because the thing about frequentist tools is that they are super generic in a way that you,

whichever situation you're in, you can just apply those tools as is.

And as long as you follow the steps required,

you would get to the end of that step,

to get to the end of that procedure.

So it's developed in a way that you can just apply them out of the box

and that will be okay.

And the downside of that is that

it might not be as flexible as Bayesian models

where it takes more time.

Those models take more time to set up, to develop,

but they can, like you said,

you can run it however long you want.

If you decide that you want to stop early, that's okay too.

You can come up with an early stopping rule

and that will be fine.

For hypothesis testing specifically,

And this is something that we also talk about in the book where we say, oh, for a frequentist test, you kind of don't get to rerun the test multiple times as new data comes in because that is a form of data snooping or p-hacking.

But with a Bayesian model, that's totally cool to do because you can use the posterior of the previous iteration as the prior for the next iteration.

And you just repeat that loop until you find something interesting.

And that's not to say that you want to cherry pick out the data to fit into the conclusion that you want to draw.

But if you have new data come in and those new data are of good quality, they're not cherry picked or anything, then you can totally rerun your model however many times that you want and things would be okay to do.

Alex Andorra: Yeah.

Yeah.

Great.

Great summary, Quan.

Thanks.

I think it's always great to dive a bit more into that each time we have the opportunity on the show because I know it's a big topic and it's also a complex one.

I think this one is definitely an advanced topic for sure.

And well, we teased that earlier, but there is also a chapter on Bayesian neural networks in your book.

So, yeah, you want to talk a bit more about that and especially when they are worth the trouble in practice?

Quan Nguyen: Yes, thank you.

So Bayesian neural networks, I love them.

The idea here is that with Bayesian nets, you get the best of both worlds, you know, like compared to traditional models, neural networks, deep learning models.

They have more modeling flexibility and they can operate on complex data.

But with a Bayesian neural net, you also get uncertainty quantification of Bayesian models.

So that's super cool.

So the idea here is if you are working with complex data, like complex data types like text or graphs or molecules or whatever, then these customized neural networks will be able to kind of process those kinds of complex data types and then get you a representation that is really useful for predicting.

This is just because there are a lot of parameters in those neural networks, and in combination, they can offer us a lot of flexibility in modeling.

And then if you have a Bayesian neural net, that is like one extra layer of uncertainty quantification.

Because with a lot of parameters, you have a lot of flexibility in modeling, but you can also overfit to the data.

So this uncertainty quantification layer is especially useful when being used with Bayesian

neural nets.

But this is not to say that this is like the B-O-N-O of all models, right?

Because a Bayesian neural net, it takes a lot of effort to train because we don't have

a conjugate prior.

So we have to settle for some approximate inference, like MCMC or variational inference.

If your neural net is small, if it's big and you're running it on really big data, then

maybe MCMC or variational inference won't be able to be run at all.

So that's another consideration that you have to think about.

So that is a real trade-off here.

If you want more modeling power, then you have to put more effort in the setting up,

just like any other Bayesian modules, I feel like.

So in practice, I think I would recommend, I wouldn't recommend defaulting to a Bayesian

neural network in all situations.

I think it will make sense for you to kind of think about whether there are more simpler

models that you could train on your data, whether your data can be captured by more

simpler models.

And if a neural net is truly what you want, then you can try to explore whether if a sufficiently small neural network would be enough, and then you can run MCMC or variational inference.

Otherwise, then we would have to settle for an even more approximate approach, and that is neural network dropout.

So basically, it's like a scale of increasing complexity.

And the more complexity you have, the more effort you have to put into running, training, and making predictions with those models.

Alex Andorra: Yeah, yeah, yeah.

That makes sense in a good hierarchy.

In practice, same question, you know, as for BED.

How do you run Bayesian neural networks?

How do you define them and which package would you even grab?

Quan Nguyen: Thanks for the question.

So I think there are many different packages for Bayesian neural networks.

So if I am missing out on some big ones, then please forgive me.

So I usually do, I usually do, I look into NumPyro and Pyro for Bayesian neural networks.

just the same packages that we mentioned for Bayesian experimental design,

those would also have the state-of-the-art implementations

for a lot of research, a lot of models that resulted from academic research.

What's really cool is that, and we will probably talk about it more later,

is dropout, which is a common regularization technique for deep learning.

It can also be interpreted as a Bayesian inference method,

specifically variational inference on a particular type of binomial distribution for the weights.

So if you are using your PyTorch or your TensorFlow libraries to implement dropout

neural networks, then you can keep using those libraries because as long as you keep, you enable

dropout while making inference, while making predictions, then that is your way of performing

approximate Bayesian inference on those models too. Alex Andorra: Yeah, yeah, love that. That's super practical.

And I love these kind of recommendations where, well, people interested in these models, they can

go right now

try them out themselves

with these

packages so yeah thanks

I love these kind of

recommendations

and something

I wanted also to

ask you and I'll start

playing this out because you've already been very

generous with your time but

maybe if you can quickly

tell us what have been some of the

most surprising things that you noticed

while writing the book

Quan Nguyen: yeah I love to hang out more so I overall I've learned so much about um about a lot of things

while writing the book so um you know as you as I'm sure you agree with me or doing this podcast

or doing research or thinking about writing a book um just that process of doing research alone

is such an opportunity to kind of consolidate all we know what what we have known and kind of

structure that knowledge because as you as we go through that structuring process we

gain new insights just from reorganizing our thoughts and making interesting connections

and in addition to that we also have to do research into topics that we are comfortable

talking about but to write a book we need to do more research on so that is yet another

opportunity to learn. So all of these things in combination have made me into

a more knowledgeable Bayesian, I feel like. And during this process, one of the things that I've

found to be really cool is the different connections between different seemingly

separate things in the literature. So for example, we've been hinting at this throughout

this episode is the idea of regularization, especially in machine learning. So my

tagline is that regularization is a very common technique in machine learning, sometimes like an

add-on that you have to put in in your machine learning model. But this is, regularization is

automatically achieved in a well-specified Bayesian model. So if you're familiar with

linear regression or kernel regression, for example. You can do regularization like ridge

regression to avoid overfitting. So you want to encourage simpler models, coefficients that are

close to zero. This is because, you know, if you have a small data set, like a 10-point data set,

then a 9-degree polynomial regressor will be able to completely fit into it. But if there's some

noise in the data and the underlying trend is a simpler trend, then you don't want that

completely exactly fitting model.

So what you want to do is to encourage simpler models in that way.

So if you want to do ridge regression for linear regression or kernel regression, you have

to add in this extra penalty term to do regularization.

So it trades off between regularization and fitting to data.

but what's really interesting is Bayesian models do this out of the box completely so you have a

Bayesian linear regressor a polynomial regressor a Gaussian process and if you set up some data

then sorry you set up a prior that you want to use then you you are basically specifying the

present the preference for simpler models as part of your modeling process if your prior is set up

in such a way.

So the connection also extends

when you inspect the mathematical form

of the two techniques

and you see that there is a real equivalence

where the ridge regression is just a special case

when you use a zero mean normal prior

on the coefficients in your Bayesian model.

And in addition, when you're using a Bayesian model,

you get uncertainty quantification too.

so that it's like an extra add-on when doing regularization in Bayesian models.

So that is something that I think is super cool.

It's just a way to think about how non-Bayesian models have to kind of go out of their way

to encode prior knowledge, different things that they think should happen to their model.

But with a Bayesian model, we have to do this as a first step already.

So it's not like any new thing that we have to do in addition.

And finally, what I've been wanting to talk about too

is this idea of regularization in neural networks, right?

So people first develop dropout,

which is this idea where you randomly block out

nodes in your neural network while training.

So it's to regularize those weights to avoid overfitting

where the nodes become codependent to one another.

but after that

these models have been

analyzed by

Bayesian academics and they found

a Bayesian interpretation where we

can view dropout as a special

kind of Bayesian inference

via variational inference where you can

think of as you turn

each node on and off you are basically

drawing samples from a Bernoulli distribution

which is like oh a binary outcome whether I

turn this node on and off

so that is something super cool

that I think

kind of speaks to the idea that

with a traditional non-Bayesian model,

you have some idea about what you think should happen.

This is basically your prior.

So you kind of encourage that behavior

by building another layer into your model.

But with a Bayesian model,

you kind of have to do this already

so you not have to spend more effort

in setting up your model in that way.

So if you do it,

then you're already achieving what,

regularization in non-Bayesian models trying to achieve.

But you have uncertainty quantification, so that is even better to do.

When I was teaching this at my university, I made a meme on this.

Alex, are you familiar with that meme where the child would ask,

Mom, can we have regularization?

And the mom would say, oh, but we have regularization at home,

but regularization is just ridge regression.

Well, in reality, the child really wants the regularization from Bayesian model, which is like the, I guess, the more natural way to think about these.

So I love seeing all these connections between different topics, right?

It's like, oh, regularization is just a special type of encoding prior knowledge into a model.

some people have found good ways to do it but it's just a special form of declaring

the prior into your model Alex Andorra: yeah yeah exactly uh as you're saying I love that this framework comes

with batteries included basically it's like everything is included out of the box you just

think about one uh estimator the posterior sample uh posterior distribution and then you're good

You can do anything you want.

You can do optimization.

You can do decision-making.

You can do test statistics.

And it's related to all the things you usually do in the frequentist framework,

but you have to pile an add-on and then go there and add that

and add regularization and be careful about overfitting and things like that.

Here it's like, no, no, no.

You do that already.

Quan Nguyen: You have done it. Congratulations.

Alex Andorra: Yes, exactly.

So that is really awesome.

And well, you're actually something I'm also curious to hear you about

because it's a question I get a lot now.

And I'm sure you have a lot because you have students also.

It's why would I even bother learning this?

You know, like why would learning Bayesian stats in general be still worth it now that AI can write the models for me?

Quan Nguyen: Yeah, thanks for the question.

Alex Andorra: What do you tell to your students or people who ask you that and how do you manage that?

Quan Nguyen: Yeah, and I would love to get your perspective too because mine is, you know, just a singular perspective from a university in Vietnam.

And I'm sure there are many other perspectives.

But from my point of view, I feel like with these AI assistance tools, it's even more important for us to really understand at least the fundamental ideas.

So, you know, with AI, it's becoming easier to get all of the mechanical work out of the way.

So you can do something like, oh, you type into your ChatGPT or Claude saying, oh, I want to build a Bayesian model in PyMC with all these structures.

And it will give you working PyMC code.

And that will probably work pretty well when you run it.

and, you know, MCMC will converge

and, you know, the diagnostics will look pretty good.

But that is just the mechanical step, right?

You still have to make really important decisions.

So which assumptions that we should put into our model,

how to represent uncertainty, which priors make sense

and whether the results look okay

and how can we use these results to make decisions.

You have to specify that utility function.

So the AI, at least for now, can totally do what we tell it to do,

but we still need to be that person that decides what it should do.

So this is coming back to that idea of humans on the loop, right?

Where we still want at least one human with expertise supervising the AI

and seeing whether the results being generated by AI actually make sense or not.

So I think it's good and exciting that AI is kind of shifting the bottleneck a little bit from implementation to judgment so we can really focus on the intuition, the more difficult part, right?

And because it's more difficult, the intuition, the judgment that we're making about our model, I think is even more valuable to understand the core principles in Bayesian methods and probability and whatnot.

And I feel like this is the same thing that many people are observing in programming in general, where we see that AIs are becoming better and better at coding, but we still want humans on the loop just to judge and verify code.

And some companies are shifting towards code comprehension instead of live coding for their interviews to kind of emphasize that crucial part that humans play in that software development process.

But what do you think, Alex?

Do you think that from your own world or from your own experience or your own experience at work, do you find that human expertise is still really valuable there?

Alex Andorra: yeah yeah I mean I completely agree with everything you just said um as I I tend to think about it

in like thinking that understanding is the new bottleneck if you want um um it's already related

to what you were saying in the sense that now implementing is much faster at least implementing

a prototype is much faster.

So in a sense, it's really great because you can,

before we still used to have a lot of ideas we wanted to test,

but there was a really small fraction of these ideas

we could actually test because implementing one idea

would take so long.

Now, writing code is basically free,

and it takes so little time that you can actually focus

on testing a lot more ideas and and implementing a lot more of them but yeah you have to be really

in the loop like that we with the the agents because you have to review everything they do

you have to understand deeply actually what they are trying to do uh because you ask for it you

sear them and yeah as you were saying I think that actually understanding what they do now is

much much more important and in the end that's a bit like you know the difference between

walking and and driving I would say where before we used to have to walk everywhere so um

like that was great but in the end you can go everywhere most like you can go a lot of places

by by walking but it will take you a long time now we can do that by car but we'll have to be

much more careful because uh we're going much faster and we have to steer the car in a way that's

um that's safe and for that we need to know how to drive and uh even if we have an autonomous car

an autonomous car sometimes you'll you'll need to steer yourself and take back the the wheeling

drive and that's where really knowing the models understanding the math and the stats and how to

make the difference between something that looks good and something that's actually good is extremely

important um and yeah maybe like the last thing I'm thinking about right now but that is also

the agents are not like the just the coding with AI is not the thing that's going to make you

excellent what's going to make you excellent is doing that and being persistent and understanding

what you're doing so that you can drive the process.

And yeah, basically, that's my current thinking about that.

We'll see in six months, you know, because that evolves so fast.

Quan Nguyen: No one will know.

What I will say, though, I think is that it's just so tempting, right,

to rely on these AI tools.

Like if it can give you a bunch of code and like hundreds of lines of code,

that seem to work, it's really tempting to just take it and run it.

And I think this is also true in academic research,

where people have found that, oh, yeah, I start out with an idea,

and then I tell the agent to investigate the idea for me,

and it completely does that investigation on its own.

But what's really dangerous is that along the way,

it makes a lot of subtle decisions on its own that we didn't keep track of.

and the accumulation of those

sort of decisions

it turns into something

that the original researcher

didn't intend to and

can be a whole can of worms that

is waiting for

the researcher and

it seems to me like we

what could be a good way

to kind of navigate this space is

to design the incentive structure

in a way that promotes

that kind of

that like

careful investigation of AI output

so that we are really making sure

that what we're doing is cool and good

and not just what AI thinks

that's what we want to do.

So I guess this is coming back to the idea

of really correctly specifying your utility function

so that it can be optimized in a good way.

Alex Andorra: yes love that love that uh yeah I mean I really like the way you you think about that so that's

also why I wanted to uh to ask you that that question I think it's going to be very helpful to

to the listeners um and well before letting you go Quan um looking forward what are you

focusing on you know for the coming month Quan Nguyen: for the coming months I think I my one of my biggest

priorities will be teaching. So I've just started at this university, so I'm just still trying to

settle in, getting to know the students and whatnot. So I'm spending some time developing

content for courses on the properties stats and machine learning in general. So this is something

that you're more familiar to than me, Alex. So if you can share any tips, I would greatly appreciate

it. On research, I would love to keep pushing for the same problems that I've been working on in my

PhD and my postdoc, which is to kind of apply all the machinery that we have in Bayesian experimental

design, Bayesian probability, Bayesian optimization and whatnot, to real-life scientific discovery

problems. So the idea here is, you know, in academic research, you might come up with a really

mathematically satisfying solution to optimization or experimental design.

But in the real world, things are a bit more messy.

So maybe the objective that we have for our model doesn't actually capture what the scientist

wants to do.

They might care about something else.

And we only find that out when we run the algorithm in the wild.

So one of the main interests is kind of developing customized tools to help scientists for their

own scientific discovery problem um with their own personal objective function utility function

they want to optimize and um the the thing that I'm excited about is that uh because the framework

of you know Bayesian stats a Bayesian decision theory is all very flexible that as long as we can

specify a utility function we can try to apply all this machinery to that problem so um it's

it's like every time we are faced with a new problem,

it's an opportunity for me to kind of learn

how to correctly specify a utility function

and how we can effectively optimize it.

So it's, you know, every problem requires me to start fresh.

So it's really exciting.

And the last thing I think would be about,

that I'm excited about is, you know,

this new book coming out and reaching readers.

You know, I feel really lucky

that it doesn't just stop at readers buying my books,

but sometimes some readers will reach out to me

and talk about the problems that they're facing

and how they're planning to apply some of the tools

that they are reading about to those problems.

So when something like that happens,

I feel like it's really rewarding,

even though people buying my books alone

is already a really fortunate thing.

But when something like that happens

where a reader reaches out, I feel very grateful.

Alex Andorra: Yeah.

Yeah, I mean, I can definitely resonate with that.

I always love hearing from listeners,

whether they ask, you know, on social media or email.

The funniest is when I go to conferences

and listeners come talk to me.

That's always super fun and very interesting

because they always do so many interesting things.

So yeah, definitely relate to that.

Quan Nguyen: It's kind of you to compare our individual situations

in the same sense like that

because I don't think I can get to your level of fame and popularity.

Alex Andorra: We'll see.

We'll see.

I'm sure you'll do even more.

Hopefully, you'll still be able to get out of the street

But, Quan, because that's always nice to get out and have a walk.

So I really hope you won't get that level of fame, though.

But no, when I'm in Vietnam, I definitely will bring your book to get a signed version of the book.

Quan Nguyen: You know what is really interesting is that the publisher, they are based in the U.S., Manning.

And they have an office in Singapore.

but I do wonder how they would get my author's copies to me in Vietnam.

So that is something that I have to look into.

Alex Andorra: Oh, yeah.

Good luck to them.

There's going to be some interesting legalese.

Oh, yeah.

Oh, yeah.

Alex Andorra: I'm not excited for that.

It's not for us, Quan.

So that's all.

We're the tech guys.

Oh, yeah.

Yeah.

But, yeah, so definitely encourage people to buy your book and reach out to you.

Then you heard it, folks.

Quan loves that.

So definitely reach out to him and thank him for taking the time to write the book.

Before you go, of course, Quan, the last two questions.

I think you must have already answered them, right, during your first episode.

But I'll ask them for you again because it was seven years ago.

So you're allowed to change your answer.

Quan Nguyen: Oh, I will.

I have seen new data and I have updated my beliefs.

Alex Andorra: Yeah, exactly.

Quan Nguyen: I think I saw somewhere saying something about how, you know,

like after seven years,

it's like when a human body completely changes all its cells,

like all the old cells have died out

and all of your cells now are new compared to seven years ago.

So technically we're completely different people from that time.

Interesting.

Alex Andorra: All right.

Well, a lot has changed in my life in seven years, so I can definitely relate to that.

Well, so let's get to it.

If you had unlimited time and resources, which problem would you try to solve?

Quan Nguyen: Yeah, so I think I would really push for what I'm interested in in research.

So that would be interesting connections to be made between the tools that we have in

machine learning and experimental design with domain applications in environment or biodiversity.

So I would like to share this experience that I have at the risk of being a bit too sentimental.

And this was around the time that we first met, Alex, when this was in the middle of my PhD

program where COVID happened and we were organizing that PyMCon conference. So I was having a little

mid-PhD crisis, as many people do, where it just seemed like many of the things that I were doing

just slightly out of place. It didn't seem like I would be able to help in any way if something

like COVID were to happen over again.

So that was quite scary to think about.

But that because we were organizing that conference together, I got to see so many different people

working on so many different cool things, still using the tools that I am familiar with,

still using Bayesian stats, but working on really cool and really important problems.

So that was really inspiring to me, where it goes to show that, oh, you can apply these machinery, these tools to the problems that you care about.

And as long as you do, you set up the problem correctly, you can try to solve that problem using the tools in your tool belt, basically.

so that really got me turned around

and getting out of my mid-PhD crisis there

now that I think about it

now I understand that all of us have our own specializations

so the thing about research is that you never know

where and how your findings will be applied at you

so regardless of what you're researching

there is a way to contribute to an scientific community

and help with whatever problem society is facing.

But for me, I still would love to be able to,

in some way, directly contribute to environmental

or the biodiversity applications,

where it just seems like there is more things to do

in terms of leveraging all these state-of-the-art

machine learning probability tools

to some of the more pressing problems that we're facing.

Alex Andorra: Yeah, yeah, I love that.

Yeah, very inspiring.

Lloyd, thanks, Quan.

And second question,

if you could have dinner with any great scientific mind,

dead, alive, or fictional, who would it be?

Quan Nguyen: Ah, thanks for the question.

So I remember the first time I appeared on the podcast,

I talked about Edwin Jaynes.

But, and, you know, my new answer, it didn't come from, like, me really considering how to answer this problem a really long time.

But I was just re-watching Rick and Morty last night.

And I just thought that, you know, Rick Sanchez would be a reasonably interesting choice.

you know he's a scientist and he's constantly conducting um experiments um but most of the

time he doesn't really care what happens um if you know his experiments blow up or like he hurt

other people so that that that I I think is really interesting it goes to show that you know um

given his his um the utility function that he has specified right like which is the fact that oh if

if my experiments blow up or like some other people got hurt my utility function would would

not would not take on that much of a negative uh value or anything that that is something that I

really find interesting where um you know he he is a perfectly rational person but he doesn't act

like other um other uh people in his environment just because his utility function is just so

different um so you know if I could you know sit down and have a dinner that would be really lovely

but I do worry about my own safety and maybe surviving dinner alone would be a big enough

challenge Alex Andorra: oh dear yeah great answer I think you're the I mean you're definitely the first one to to

answer uh to answer Rick Sanchez uh yeah I I agree that we'll be full of adventures for sure

deadly adventures

also very probable

so

oh yeah

be advised

I don't know

if I'll join

I'll only join

if I see

if it's

dinner safe

Quan Nguyen: maybe

I'll make

a podcast episode

out of it

and you'll listen

to the conversation

only

from a safe distance

Alex Andorra: yes

yes

that sounds like it

live stream it

Quan Nguyen: amazing

Alex Andorra: well

thank you so much

for taking the time

that was amazing

Quan Nguyen: thank you Alex

and I realize

we're way out of time

so thank you for taking the time too

Alex Andorra: yeah yeah for sure

that was great I mean I could stay

even longer like I have even more questions

for you but let's be

let's be respectful of

your time and of the listeners

Quan Nguyen: I'll be respectful of your time

Alex Andorra: and also that's great you still

have things to say so that

next time for your next book you can

come back and we'll have another conversation

Quan Nguyen: thank you yeah I'll be very flattered

Alex Andorra: yeah let's do that

well

yeah thank you so much

Quan as usual

lots of links in the show notes

folks

Quan Nguyen: I think there was

a note about getting you

a picture of me so I'll do that and then

I'll like send you the

library that we talked about

Alex Andorra: no worries yeah yeah add that in the

in the show notes and

you'll get that folks in

there links to Quan's

books

and all his research

and also the different Python packages that we have mentioned today.

And on that note, thank you so much, Quan, for taking the time and being on this show.

Quan Nguyen: Thank you, Alex, for hosting me.

Alex Andorra: This has been another episode of Learning Bayesian Statistics.

Be sure to rate, review, and follow the show on your favorite podcatcher

and visit learnbayesstats.com for more resources about today's topics

as well as access to more episodes

to help you reach true Bayesian state of mind.

That's learnbayesstats.com.

Our theme music is Good Bayesian by Baba Brinkman

with MC Lars and Mega Ran.

Check out his awesome work at bababrinkman.com.

I'm your host, Alex Andorra.

You can follow me on Twitter at Alex underscore Andorra,

like the country.

You can support the show and unlock exclusive benefits

by visiting Patreon.com slash learnbayesstats.

Thank you so much for listening and for your support.

You're truly a good Bayesian.

Key Takeaways

Quan wrote it for people who want a working intuition for Bayesian methods without a strong math background. When he started out in Bayesian machine learning, he found resources at two extremes: math-heavy texts full of measure theory and complicated integrals, and hands-on PyMC or Stan tutorials that sweep the math under the rug. Grokking Bayes aims for the middle, building intuition through examples, visualizations and code. It also goes beyond inference: a large part of the book is about what you do with a posterior once you have it, from evaluating models to making decisions and choosing which data to collect next.

A posterior tells you what might be true, not what to do. To decide, you also need a utility function describing how much you value each outcome under each action. Bayesian decision theory then weights each outcome's utility by its posterior probability and picks the action with the highest expected utility. This separates beliefs from preferences, which is why two people can agree on the same posterior and still rationally choose different actions. Quan contrasts it with deciding by p-value threshold, which says nothing about how costly it would be to be wrong or how beneficial to be right.

Bayesian experimental design (BED) is for situations where your actions decide which data you observe next, typically because experiments are expensive. Instead of picking experiments at random, you use your model's uncertainty to choose the most informative one, update the model, and repeat. Quan's favorite point is that BED isn't a separate framework at all: it's plain Bayesian decision theory with a utility function that quantifies how much you know about an unknown quantity, such as the reduction in entropy.

Bayesian experimental design tries to learn as much as possible about a system, while Bayesian optimization tries to find the input that produces the best outcome, like the neural network architecture with the highest accuracy, or the most durable material. Optimization doesn't need to map the whole response surface: it can ignore regions it's confident don't contain the optimum. The two connect through information-theoretic approaches, which recast optimization as learning about the location of the function's maximizer, so the experimental design machinery applies. Quan's first book, Bayesian Optimization in Action, goes deep into Gaussian processes and Bayesian optimization decision policies, including information-theoretic ones.

For state-of-the-art methods, the experimental design module in NumPyro implements techniques from the research community around Adam Foster and Desi Ivanova. For a lightweight, low-effort start, optbayesexpt, developed by Bob McMichael at the US National Institute of Standards and Technology, gives you a bare-bones structure: you specify your likelihood, your prior and the unknown quantity you care about, and the package handles the rest.

With a frequentist hypothesis test, re-running the test every time new data comes in is a form of data snooping (aka p-hacking). With a Bayesian model, the posterior from one round simply becomes the prior for the next, so you can keep updating and even design an early stopping rule. Quan stresses this isn't a license to cherry-pick data to reach the conclusion you want: it works when the new data is of good quality and not selected to fit a story.

Bayesian neural networks combine the flexibility of deep learning, useful for complex data like text, graphs or molecules, with Bayesian uncertainty quantification, which helps guard against overfitting all those parameters. Quan's advice is not to default to them. First check whether a simpler model captures your data, then whether a small network you can sample is enough, and only then settle for more approximate approaches.

In machine learning, regularization is an add-on that keeps models simple to avoid overfitting, like ridge regression's penalty term. In a well-specified Bayesian model, you get it for free through the prior: ridge regression is what you get from the posterior mode under a zero-mean normal prior on the coefficients, and you get uncertainty quantification on top. Dropout follows the same story. It was invented to regularize neural networks by randomly switching off nodes during training, and was later shown to be interpretable as approximate variational inference, with each node's on/off switch a Bernoulli draw. Keep dropout on at prediction time in PyTorch or TensorFlow and you're doing approximate Bayesian inference!

Quan argues it matters even more! An AI assistant can turn a description into working PyMC code, and MCMC may converge with clean diagnostics, but that's only the mechanical part. Someone still has to decide which assumptions fit, which priors make sense, whether the results are actually useful and which utility function to optimize. AI is shifting the bottleneck from implementation to judgment. He also warns that agents make many small decisions on their own, and those can accumulate into an analysis the researcher never intended, so a human with real expertise needs to stay in the loop.

Related Episodes