You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/example.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,38 +1,40 @@
1
1
## Example: Using Planar Flow
2
2
3
-
Here we provide a minimal demonstration of learning a synthetic 2d banana distribution
4
-
using *planar flows* (Renzende *et al.* 2015) by maximizing the [Evidence Lower Bound (ELBO)](@ref).
3
+
Here we provide a minimal demonstration of learning a synthetic 2D banana distribution
4
+
using planar flows (Rezende and Mohamed, 2015) by maximizing the ELBO.
5
5
To complete this task, the two key inputs are:
6
6
- the log-density function of the target distribution,
7
7
- the planar flow.
8
8
9
-
#### The Target Distribution
9
+
- the log-density function of the target distribution
10
+
- the planar flow
11
+
12
+
### The Target Distribution
13
+
14
+
The `Banana` object is defined in `example/targets/banana.jl` (see the source for details).
10
15
11
-
The `Banana` object is defined in `example/targets/banana.jl`, see the [source code](https://github.com/zuhengxu/NormalizingFlows.jl/blob/main/example/targets/banana.jl) for details.
12
16
```julia
13
17
p =Banana(2, 1.0f-1, 100.0f0)
14
18
logp = Base.Fix1(logpdf, p)
15
19
```
16
-
Visualize the contour of the log-density and the sample scatters of the target distribution:
17
-

18
20
21
+
Visualize the contour of the log-density and the sample scatters of the target distribution:
19
22
23
+

20
24
25
+
### The Planar Flow
21
26
22
-
#### The Planar Flow
27
+
The planar flow is defined by repeatedly applying a sequence of invertible
28
+
transformations to a base distribution $q_0$. The building blocks for a planar flow
29
+
of length $N$ are the following invertible transformations, called planar layers:
23
30
24
-
The planar flow is defined by repeated applying a sequence of invertible
25
-
transformations to a base distribution $q_0$. The building blocks for a planar flow
26
-
of length $N$ are the following invertible transformations, called *planar layers*:
27
31
```math
28
-
\text{planar layers}:
29
-
T_{n, \theta_n}(x)=x+u_n \cdot \tanh \left(w_n^T x+b_n\right), \quad n=1, \ldots, N,
32
+
T_{n, \theta_n}(x)=x+u_n \cdot \tanh \left(w_n^T x+b_n\right), \quad n=1, \ldots, N.
30
33
```
31
-
where $\theta_n = (u_n, w_n, b_n), n=1, \dots, N$ are the parameters to be learned.
flow_untrained =deepcopy(flow) # keep a copy of the untrained flow for comparison
53
55
```
54
-
*Notice that here the flow layers are chained together using `fchain` function from [`FunctionChains.jl`](https://github.com/oschulz/FunctionChains.jl).
55
-
Alternatively, one can do*
56
+
57
+
Notice: Using `fchain` (FunctionChains.jl) reduces compilation time versus chaining with `∘` for many layers.
0 commit comments