ArticleslgStudy

biology

Flow-based generative model

Flow-based generative model is a biology topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Flow-based generative model rather than just read about it. In short: A flow-based generative model is a generative model used in machine learning that explicitly models a probability distribution by leveraging normalizing flow, which is a statistical method using the change-of-variable law of probabilities to transform a simple distribution into a complex one. The direct modeling of likelihood provides many advantages.

Flow-based generative model — main illustration
Flow-based generative model — illustration

Key takeaways

  • Flow-based generative model belongs to biology; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Flow-based generative model to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Flow-based generative model from memory before moving on to harder problems.

Reference excerpt

A flow-based generative model is a generative model used in machine learning that explicitly models a probability distribution by leveraging normalizing flow, which is a statistical method using the change-of-variable law of probabilities to transform a simple distribution into a complex one. The direct modeling of likelihood provides many advantages. For example, the negative log-likelihood can be directly computed and minimized as the loss function. Additionally, novel samples can be generated by sampling from the initial distribution, and applying the flow transformation. In contrast, many alternative generative modeling methods, such as variational autoencoders (VAEs), generative adversarial networks (GANs), or diffusion models, do not explicitly represent the likelihood function.

Method

Let z0 be a (possibly multivariate) random variable with distribution p0(z0). For i=1,...,K, let zi=fi(zi−1) be a sequence of random variables transformed from z0. The functions f1,...,fK should be invertible, i.e. the inverse function fi−1 exists. The final output zK models the target distribution. The log likelihood of zK is (see derivation):

log⁡pK(zK)=log⁡p0(z0)−∑i=1Klog⁡|det⁡dfi(zi−1)dzi−1| Learning probability distributions by differentiating such log Jacobians originated in the Infomax (maximum likelihood) approach to ICA, which forms a single-layer (K=1) flow-based model. Relatedly, the single layer precursor of conditional generative flows appeared in. To efficiently compute the log likelihood, the functions f1,...,fK should be easily invertible, and the determinants of their Jacobians should be simple to compute. In practice, the functions f1,...,fK are modeled using deep neural networks, and are trained to minimize the negative log-likelihood of data samples from the target distribution. These architectures are usually designed such that only the forward pass of the neural network is required in both the inverse and the Jacobian determinant calculations. Examples of such architectures include NICE, RealNVP, and Glow.

Derivation of log likelihood Consider z1 and z0. Note that z0=f1−1(z1). By the change of variable formula, the distribution of z1 is:

p1(z1)=p0(z0)|det⁡df1−1(z1)dz1| Where det⁡df1−1(z1)dz1 is the determinant of the Jacobian matrix of f1−1. By the inverse function theorem:

p1(z1)=p0(z0)|det⁡(df1(z0)dz0)−1| By the identity det⁡(A−1)=det⁡(A)−1 (where A is an invertible matrix), we have:

p1(z1)=p0(z0)|det⁡df1(z0)dz0|−1 The log likelihood is thus:

log⁡p1(z1)=log⁡p0(z0)−log⁡|det⁡df1(z0)dz0| In general, the above applies to any zi and zi−1. Since log⁡pi(zi) is equal to log⁡pi−1(zi−1) subtracted by a non-recursive term, we can infer by induction that:

log⁡pK(zK)=log⁡p0(z0)−∑i=1Klog⁡|det⁡dfi(zi−1)dzi−1|

Training method As is generally done when training a deep learning model, the goal with normalizing flows is to minimize the Kullback–Leibler divergence between the model's likelihood and the target distribution to be estimated. Denoting pθ the model's likelihood and p∗ the target distribution to learn, the (forward) KL-divergence is:

DKL[p∗(x)‖pθ(x)]=−𝔼p∗(x)[log⁡pθ(x)]+𝔼p∗(x)[log⁡p∗(x)] The second term on the right-hand side of the equation corresponds to the entropy of the target distribution and is independent of the parameter θ we want the model to learn, which only leaves the expectation of the negative log-likelihood to minimize under the target distribution. This intractable term can be approximated with a Monte-Carlo method by importance sampling. Indeed, if we have a dataset {xi}i=1N of samples each independently drawn from the target distribution p∗(x), then this term can be estimated as:

−𝔼̂p∗(x)[log⁡pθ(x)]=−1N∑i=0Nlog⁡pθ(xi) Therefore, the learning objective

argminθ DKL[p∗(x)‖pθ(x)] is replaced by

argmaxθ ∑i=0Nlog⁡pθ(xi) In other words, minimizing the Kullback–Leibler divergence between the model's likelihood and the target distribution is equivalent to maximizing the model likelihood under observed samples of the target distribution. A pseudocode for training normalizing flows is as follows:

INPUT. dataset x1:n, normalizing flow model fθ(⋅),p0. SOLVE. maxθ∑jlog⁡pθ(xj) by gradient descent RETURN. θ̂

Variants

Planar Flow The earliest example. Fix some activation function h, and let θ=(u,w,b) with the appropriate dimensions, thenx=fθ(z)=z+uh(⟨w,z⟩+b) The inverse fθ−1 has no closed-form solution in general. The Jacobian is |det⁡(I+h′(⟨w,z⟩+b)uwT)|=|1+h′(⟨w,z⟩+b)⟨u,w⟩|. For it to be invertible everywhere, it must be nonzero everywhere. For example, h=tanh and ⟨u,w⟩>−1 satisfies the requirement.

Nonlinear Independent Components Estimation (NICE) Let x,z∈ℝ2n be even-dimensional, and split them in the middle. Then the normalizing flow functions arex=[x1x2]=fθ(z)=[z1z2]+[0mθ(z1)] where mθ is any neural network with weights θ. fθ−1 is just z1=x1,z2=x2−mθ(x1), and the Jacobian is just 1, that is, the flow is volume-preserving. When n=1, this is seen as a curvy shearing along the x2 direction.

Real Non-Volume Preserving (Real NVP) The Real Non-Volume Preserving model generalizes NICE model by:x=[x1x2]=fθ(z)=[z1esθ(z1)⊙z2]+[0mθ(z1)] Its inverse is z1=x1,z2=e−sθ(x1)⊙(x2−mθ(x1)), and its Jacobian is ∏i=1nesθ(z1,). The NICE model is recovered by setting sθ=0. Since the Real NVP map keeps the first and second halves of the vector x separate, it's usually required to add a permutation (x1,x2)↦(x2,x1) after every Real NVP layer.

Generative Flow (Glow) In generative flow model, each layer has 3 parts:

channel-wise affine transformycij=sc(xcij+bc) with Jacobian ∏cscHW. invertible 1x1 convolutionzcij=∑c′Kcc′ycij with Jacobian det⁡(K)HW. Here K is any invertible matrix. Real NVP, with Jacobian as described in Real NVP. The idea of using the invertible 1x1 convolution is to permute all layers in general, instead of merely permuting the first and second half, as in Real NVP.

… excerpt ends here. Continue reading the full article.

Illustrations

Flow-based generative model: For the 1-simplex (blue) embedded in ℝ2, when we pull back Lebesgue measure from tangent space (parallel to the simplex), via the embedding p1↦(p1,1−p1), with Jacobian 𝐄=[1−1]′, a scaling factor of 𝐄′𝐄=2 results.
For the 1-simplex (blue) embedded in ℝ2, when we pull back Lebesgue measure from tangent space (parallel to the simplex), via the embedding p1↦(p1,1−p1), with Jacobian 𝐄=[1−1]′, a scaling factor of 𝐄′𝐄=2 results.

Worked examples

Example 1 — a first encounter with Flow-based generative model

Start with the simplest possible case. Write down what Flow-based generative model claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In biology, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Flow-based generative model before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Flow-based generative model ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Flow-based generative model

In research
Flow-based generative model appears in biology research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Flow-based generative model in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Flow-based generative model is common in secondary-school and first-year university syllabi. It links to neighbouring topics Bijections, Machine learning, Probabilistic models, so understanding it makes those chapters shorter.
In everyday life
Look for Flow-based generative model outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Flow-based generative model” →

How to study Flow-based generative model in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Flow-based generative model means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Flow-based generative model out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Flow-based generative model in simple terms?

A flow-based generative model is a generative model used in machine learning that explicitly models a probability distribution by leveraging normalizing flow, which is a statistical method using the change-of-variable law of probabilities to transform a simple distribution into a complex one. The d…

Why does Flow-based generative model matter?

Because it connects several biology ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Flow-based generative model?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Flow-based generative model.

Tags

  • Bijections
  • Machine learning
  • Probabilistic models
  • Statistical models

Keep exploring