Diffusion models took off in recent machine learning conferences.
This year, NeurIPS had around 400 publications that employ diffusion techniques. At first glance the math might seem familiar, but some results might catch you off guard and require more clarification. This article tries to fill the gap without going the painful formal math way.
Here you will get the necessary basics covering the foundational building blocks.
- Stochastic Processes
- Brownian motion
- Stochastic Integral
- Ito Differential- Stochastic Differential Equations
- Ornstein-Uhlembeck Process
A quick disclaimer.
The results presented here have been significantly condensed to keep things simple to not go into formal math territory. This comes at a significant cost in correctness. However, if you require a more formally accurate foundation, there will be no other way than literature. Make sure to check out the references below to have some starting points.
That being said, let us begin.
Stochastic Processes
In the domain of stochastic calculus one reasons about probabilities that a certain path will take.
For our sake, stochastic processes are noisy continuous paths in indexed by time. One could think of a function . Since we want to keep track of a lot of them, we need a way to distinguish each by an additional variable - hence we denote - defining the total function space as . In Haskell-like notation it would result in . So we end up with a function outputting paths.
This allows us to assign probabilities to paths.
Brownian Motion
Often referred to as the most important object of discussion in probability theory.
In essence, Brownian Motions are continuous paths (Kolmogorov's continuity theorem) starting from zero
and having an independent Gaussian increment
This means, at each time point, the tracked particle position will completely forget its movement history and choose the position around the current one with a normal distribution. Extending this concept to involves using multiple independent Brownian Motions in conjunction.
Following, we will use the Brownian Motion to define an integral, using the independent increments as our measurement delta.
Stochastic Integral (Itô)
In this chapter, we will explore the concept of the stochastic integral,
which is essential for defining the stochastic integral
The key idea is similar to the definition of the Riemann Integral through the limit of sums
, which goes over the partitioned space
with each partition becoming finer. First we require the process to behave without hindsight (adapted process). This simply means that the process, for any given time point, does not look into future values. Here lies the crux of the stochastic integral definition,
where the integrand is required to be evaluated at the beginning of the interval to not peek into the future. Hence the resulting integral is an adapted process itself.
Note: There are other definitions of stochastic integrals like Stratonovich Integral, where evaluation happens in the middle of the interval, but also comes also with other properties. For diffusion models the Itô integral remains the goto choice.
As this material can be quite dense, we will go through some key results and properties of this integral.
We have learned previously that the increments, appearing now in the sum, are independent Gaussians. In some cases the distribution remains in the limiting cases. For this we require the integrand to be square integrable i.e.
then the process
is Gaussian itself.
Some way to think about it, we integrate over paths, which spread unbiased in space, hence the integral is "centered" by design and sums up the "spread" of the integrand.
This neat property allows us to compute in some cases the integral in closed form.
As we will be concerned with the distribution of the integral, we will often encounter its square expectation to compute variances. There is a neat property.
For this property, the process needs to be in . Think of it as the analogue of space for stochastic processes.
The next theorem is less concerned with computation, but gives us some key insights of the nature of stochastic integrals
First, observe the bare-bone integral,
which is the Brownian motion. Now, consider plugging in a process that 'remaps' time, taking a path from zero to infinity. If this process is well-behaved to some extent i.e. in
the result aligns with the Brownian motion. This statement holds if one defines,
for the integral,
which is our recovered Brownian motion. There are a lot of other worth mentioning properties concerning martingales. However, these few hand picked examples should already convey the type of structure we are dealing with
We will continue now with the core topics.
Itô Differential
The previous topic was concerned about integration, this one will be with differentiation.
Differential equations are typically denoted by . For stochastic differential equations (SDE) it is more convenient to look at the differential version as we can use the integral to define these. Thus the Ito stochastic differential is denoted as
for each , which emits (think of the limit) the differential
We end up with a deterministic part and a stochastic.
is referred to as the drift term, it influences the overall direction of the process. One could think of the expectation of . The term plays the role of a valve controlling the randomness of the process – how much the process oscillates – around the expected value. This is in line with our intuition on how the stochastic integral operates.
So how do we compute the derivative of a stochastic function?
This is where Itô's lemma gives us the solution.
For example, this result in , which is contrary to the standard way derivatives work. An intuition on where the last part comes from lies in the Taylor series expansion.
The standard calculus derivative, is the best linear approximation as the other higher terms tent to zero in the limiting case. However, for the stochastic differential, the term behaves as . A sort of hand wavy explanation why that is provides the following equation.
As such, in the limit – in – this lets behave as .
However, some aspects of standard calculus do translate.
For example the partial differentiation,
which allows us to compute the stochastic integral for any deterministic function. This is a direct consequence of the Itô lemma applied to the function .
Note: We keep things simple here and define all terms only in one dimension. The extension to higher dimension can get quite hairy, but fortunately, in most research publications the dimensions are assumed to be independent. Hence, we can compute each dimension separate.
Stochastic Differential Equations
As we might now expect, Stochastic Differential Equations (SDEs) are defined as follows
with an initial condition . (could also be a random variable). The solution has to satisfy the following:
This forms the basic structure of SDEs.
Next, let us explore one of the most predominant forms of SDEs and its applications.
The Ornstein-Uhlenbeck Process
This process is arguably the most used example that can be encountered in every second publication on diffusion models.
Some prior orientation. The negative sign pushes the process in the opposite direction. We should expect the process to settle in around zero. The constant before the Brownian motion lets us expect the overall stationary (for time going to infinity) to look like a Gaussian distribution.
As a first step we look at the deterministic part of the equation.
The solution here is of course . Next we try to guess the solution by computing the differential of using Itô's lemma.
and compare it to the original SDE term by term.
Finally solve for by integrating the differential.
obtaining the solution
Recall the note before, that under certain conditions the stochastic integral results in a Gaussian distribution. In this case, conditions are met and we can even compute the distribution of the process at any time in close form.
Thus, our goal is to find the expectation and variance.
is simply the drive term
and for the variance we recall the property on squared stochastic integrals and apply it to
.
Hence we end up with the distribution .
This is basically it. Let us have a final discussion on the result.
As time progresses the distribution settles in the normal distribution for the infinite case. This is the reason why this process is of such use for diffusion models. First any data diffused will end up in the stationary distribution. As a byproduct the entropy of the distribution is kept in check and does not diverge to infinity. Second the distribution at any time point is known in closed form and can be step wise computed. This all allows us to learn the step wise diffusion updates, which diffusion models are all about.
Final notes
This article is getting a bit too long.
There are some topics left to discuss such as reverse processes and the SDE-ODE relationships. Let me know if there is interest in a continuation.
References
Øksendal, Bernt. “Stochastic Differential Equations.” In Stochastic Differential Equations, Springer, 2003.
Baldi, Paolo. Stochastic Calculus: An Introduction Through Theory and Exercises. Springer, 2010.
Song, Yang; Sohl-Dickstein, Jascha; Kingma, Diederik P.; Kumar, Abhishek; Ermon, Stefano; Poole, Ben. “Score-Based Generative Modeling Through Stochastic Differential Equations.” arXiv preprint arXiv:2011.13456, 2020.
Top comments (0)