# 基於流嘅生成模型

## 方法同推導

${\displaystyle z_{0}}$係具有分佈${\displaystyle p_{0}(z_{0})}$隨機變量（可能係多變量）。

${\displaystyle z_{K}}$個對數概似係：

${\displaystyle \log p_{K}(z_{K})=\log p_{0}(z_{0})-\sum _{i=1}^{K}\log \left|\det {\frac {df_{i}(z_{i-1})}{dz_{i-1}}}\right|}$

1.容易求逆；

2.容易計出Jacobi行列式。

### 反向訓練

${\displaystyle \int p_{1}(z_{1})dz_{1}=\int p_{0}(z_{0})dz_{0}=1}$

${\displaystyle p_{1}(z_{1})=p_{0}(z_{0})\left|{\frac {dz_{0}}{dz_{1}}}\right|}$

${\displaystyle p_{1}(z_{1})=p_{0}(z_{0})\left|\det {\frac {df_{1}^{-1}(z_{1})}{dz_{1}}}\right|}$

${\displaystyle p_{K}(z_{K})=p_{0}(z_{0})\prod _{i=1}^{K}\left|\det {\frac {df_{i}^{-1}(z_{i})}{dz_{i}}}\right|}$

${\displaystyle \log p_{K}(z_{K})=\log p_{0}(z_{0})+\sum _{i=1}^{K}\log \left|\det {\frac {df_{i}^{-1}(z_{i})}{dz_{i}}}\right|}$

### 正向生成

${\displaystyle {\frac {df_{1}^{-1}(z_{1})}{dz_{1}}}=\left({\frac {df_{1}(z_{0})}{dz_{0}}}\right)^{-1}}$

${\displaystyle \det(A^{-1})=\det(A)^{-1}}$${\displaystyle A}$係一個可逆矩陣），有：

${\displaystyle \left|\det \left({\frac {df_{1}(z_{0})}{dz_{0}}}\right)^{-1}\right|=\left|\det {\frac {df_{1}(z_{0})}{dz_{0}}}\right|^{-1}}$

${\displaystyle p_{1}(z_{1})=p_{0}(z_{0})\left|\det {\frac {df_{1}(z_{0})}{dz_{0}}}\right|^{-1}}$

${\displaystyle \log p_{K}(z_{K})=\log p_{0}(z_{0})-\sum _{i=1}^{K}\log \left|\det {\frac {df_{i}(z_{i-1})}{dz_{i-1}}}\right|}$

## 連續歸一化流

${\displaystyle x=F(z_{0})=z_{T}=z_{0}+\int _{0}^{t}f(z_{t},t)dt}$

${\displaystyle z_{0}=F^{-1}(x)=z_{T}+\int _{t}^{0}-f(z_{t},t)dt}$

${\displaystyle x}$嘅對數概似即為：[6]

${\displaystyle \log(p(x))=\log(p(z_{0}))-\int _{0}^{t}{\text{Tr}}\left[{\frac {\partial f}{\partial z_{t}}}dt\right]}$

## 考

1. Danilo Jimenez Rezende. "Variational Inference with Normalizing Flows". arXiv:1505.05770.
2. Weng, Lilian (2018-10-13). "Flow-based Deep Generative Models". Lil'Log.{{cite web}}: CS1 maint: url-status (link)
3. Dinh. "NICE: Non-linear Independent Components Estimation". arXiv:1410.8516.
4. Dinh. "Density estimation using Real NVP". arXiv:1605.08803.
5. Kingma. "Glow: Generative Flow with Invertible 1x1 Convolutions". arXiv:1807.03039.
6. Grathwohl. "FFJORD: Free-form Continuous Dynamics for Scalable Reversible Generative Models". arXiv:1810.01367.
7. Chen. "Neural Ordinary Differential Equations". arXiv:1806.07366.
8. Ping. "WaveFlow: A Compact Flow-based Model for Raw Audio". arXiv:1912.01219.
9. Shi. "GraphAF: A Flow-based Autoregressive Model for Molecular Graph Generation". arXiv:2001.09382.
10. Yang. "PointFlow: 3D Point Cloud Generation with Continuous Normalizing Flows". arXiv:1906.12320.
11. Kumar. "VideoFlow: A Conditional Flow-Based Model for Stochastic Video Generation". arXiv:1903.01434.