Skip to content

Commit 98945ea

Browse files
converted diagrams to mermaid
1 parent 138bd40 commit 98945ea

File tree

2 files changed

+125
-20
lines changed

2 files changed

+125
-20
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using DynamicPPL: AbstractPPL
88
# in the doctest as run in `test/runtests.jl`, and so we need to stay
99
# consistent with that.
1010
using Distributions
11+
using DocumenterMermaid
1112

1213
# Doctest setup
1314
DocMeta.setdocmeta!(DynamicPPL, :DocTestSetup, :(using DynamicPPL); recursive=true)

docs/src/internals/transformations.md

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,35 @@ But to ensure that we stay consistent with what the user expects, DynamicPPL.jl
4141

4242
In the end, we'll end up with something that looks like this:
4343

44-
```@raw html
45-
<div style="flex-direction: row; display: flex; justify-content: space-around; margin: 1em;">
46-
<img style="border-radius: 5px;" src="../../assets/images/transformations.dot.png" />
47-
</div>
44+
```mermaid
45+
%%{ init: { 'themeVariables': { 'lineColor': '#000000' } } }%%
46+
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
47+
graph TD
48+
subgraph assume ["assume"]
49+
style assume fill:#ffffff,font-family:Courier
50+
51+
A["x ~ Normal()"]:::boxStyle
52+
B["vn = <span style='color:#3B6EA8 !important;'>@varname</span>(x)<br>dist = Normal()<br>x, vi = ..."]:::boxStyle
53+
C["assume(vn, dist, vi)"]:::boxStyle
54+
D(["<span style='color:#3B6EA8 !important;'>if</span> istrans(vi, vn)"]):::boxStyle
55+
E["f = from_internal_transform(vi, vn, dist)"]:::boxStyle
56+
F["f = from_linked_internal_transform(vi, vn, dist)"]:::boxStyle
57+
G["x, logjac = with_logabsdet_jacobian(f, getindex_internal(vi, vn, dist))"]:::boxStyle
58+
H["<span style='color:#3B6EA8 !important;'>return</span> x, logpdf(dist, x) - logjac, vi"]:::boxStyle
59+
60+
A -.->|<span style='color:#3B6EA8 ; background-color:#ffffff;'>@model</span>| B
61+
B -.->|<span style='color:#000000 ; background-color:#ffffff;'>tilde-pipeline</span>| C
62+
C --> D
63+
D -->|<span style='color:#97365B ; background-color:#ffffff;'>false</span>| E
64+
D -->|<span style='color:#97365B ; background-color:#ffffff;'>true</span>| F
65+
E --> G
66+
F --> G
67+
G --> H
68+
end
69+
70+
classDef boxStyle fill:#ffffff,stroke:#000000,font-family:Courier,color:#000000
71+
72+
linkStyle default stroke:#000000,stroke-width:1px,color:#000000
4873
```
4974

5075
Below we'll see how this is done.
@@ -197,10 +222,27 @@ One might wonder why we need both `to_internal_transform` and `to_linked_interna
197222

198223
That is, why can't we just do
199224

200-
```@raw html
201-
<div style="flex-direction: row; display: flex; justify-content: space-around; margin: 1em;">
202-
<img style="border-radius: 5px;" src="../../assets/images/transformations-assume-without-istrans.dot.png" />
203-
</div>
225+
```mermaid
226+
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
227+
%%{ init: { 'themeVariables': { 'lineColor': '#000000' } } }%%
228+
graph TD
229+
subgraph assume ["assume"]
230+
style assume fill:#ffffff,font-family:Courier
231+
232+
A["assume(varinfo, <span style='color:#3B6EA8 !important;'>@varname</span>(x), Normal())"]:::boxStyle
233+
B["f = from_internal_transform(varinfo, varname, dist)"]:::boxStyle
234+
C["x, logjac = with_logabsdet_jacobian(f, assume_internal(varinfo, varname, dist))"]:::boxStyle
235+
D["<span style='color:#3B6EA8 !important;'>return</span> x, logpdf(dist, x) - logjac, varinfo"]:::dashedBox
236+
237+
A --> B
238+
B --> C
239+
C --> D
240+
end
241+
242+
classDef dashedBox fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5,font-family:Courier,color:#000000
243+
classDef boxStyle fill:#ffffff,stroke:#000000,font-family:Courier,color:#000000
244+
245+
linkStyle default stroke:#000000,stroke-width:1px,color:#000000
204246
```
205247

206248
Unfortunately, this is not possible in general. Consider for example the following model:
@@ -277,10 +319,32 @@ That is, if the variable is linked / "unconstrained", we use the [`DynamicPPL.fr
277319

278320
And so the earlier diagram becomes:
279321

280-
```@raw html
281-
<div style="flex-direction: row; display: flex; justify-content: space-around; margin: 1em;">
282-
<img style="border-radius: 5px;" src="../../assets/images/transformations-assume.dot.png" />
283-
</div>
322+
```mermaid
323+
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
324+
%%{ init: { 'themeVariables': { 'lineColor': '#000000' } } }%%
325+
graph TD
326+
subgraph assume ["assume"]
327+
style assume fill:#ffffff,font-family:Courier
328+
329+
A["assume(varinfo, <span style='color:#3B6EA8 !important;'>@varname</span>(x), Normal())"]:::boxStyle
330+
B(["<span style='color:#3B6EA8 !important;'>if</span> istrans(varinfo, varname)"]):::boxStyle
331+
C["f = from_internal_transform(varinfo, varname, dist)"]:::boxStyle
332+
D["f = from_linked_internal_transform(varinfo, varname, dist)"]:::boxStyle
333+
E["x, logjac = with_logabsdet_jacobian(f, assume_internal(varinfo, varname, dist))"]:::boxStyle
334+
F["<span style='color:#3B6EA8 !important;'>return</span> x, logpdf(dist, x) - logjac, varinfo"]:::dashedBox
335+
336+
A --> B
337+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>false</span>| C
338+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>true</span>| D
339+
C --> E
340+
D --> E
341+
E --> F
342+
end
343+
344+
classDef dashedBox fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5,font-family:Courier,color:#000000
345+
classDef boxStyle fill:#ffffff,stroke:#000000,font-family:Courier,color:#000000
346+
347+
linkStyle default stroke:#000000,stroke-width:1px,color:#000000
284348
```
285349

286350
!!! note
@@ -294,18 +358,58 @@ This is also the reason why we have two definitions of `getindex`:
294358

295359
For `getindex` we have the following diagram:
296360

297-
```@raw html
298-
<div style="flex-direction: row; display: flex; justify-content: space-around; margin: 1em;">
299-
<img style="border-radius: 5px;" src="../../assets/images/transformations-getindex-with-dist.dot.png" />
300-
</div>
361+
```mermaid
362+
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
363+
%%{ init: { 'themeVariables': { 'lineColor': '#000000' } } }%%
364+
graph TD
365+
subgraph getindex ["getindex"]
366+
style getindex fill:#ffffff,font-family:Courier
367+
368+
A["x = getindex(varinfo, <span style='color:#3B6EA8 !important;'>@varname</span>(x), Normal())"]:::boxStyle
369+
B(["<span style='color:#3B6EA8 !important;'>if</span> istrans(varinfo, varname)"]):::boxStyle
370+
C["f = from_internal_transform(varinfo, varname, dist)"]:::boxStyle
371+
D["f = from_linked_internal_transform(varinfo, varname, dist)"]:::boxStyle
372+
E["<span style='color:#3B6EA8 !important;'>return</span> f(getindex_internal(varinfo, varname))"]:::dashedBox
373+
374+
A --> B
375+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>false</span>| C
376+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>true</span>| D
377+
C --> E
378+
D --> E
379+
end
380+
381+
classDef dashedBox fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5,font-family:Courier,color:#000000
382+
classDef boxStyle fill:#ffffff,stroke:#000000,font-family:Courier,color:#000000
383+
384+
linkStyle default stroke:#000000,stroke-width:1px,color:#000000
301385
```
302386

303387
While if `dist` is not provided, we have:
304388

305-
```@raw html
306-
<div style="flex-direction: row; display: flex; justify-content: space-around; margin: 1em;">
307-
<img style="border-radius: 5px;" src="../../assets/images/transformations-getindex-without-dist.dot.png" />
308-
</div>
389+
```mermaid
390+
%%{ init: { 'flowchart': { 'curve': 'linear' } } }%%
391+
%%{ init: { 'themeVariables': { 'lineColor': '#000000' } } }%%
392+
graph TD
393+
subgraph getindex ["getindex"]
394+
style getindex fill:#ffffff,font-family:Courier
395+
396+
A["x = getindex(varinfo, <span style='color:#3B6EA8 !important;'>@varname</span>(x))"]:::boxStyle
397+
B(["<span style='color:#3B6EA8 !important;'>if</span> istrans(varinfo, varname)"]):::boxStyle
398+
C["f = from_internal_transform(varinfo, varname)"]:::boxStyle
399+
D["f = from_linked_internal_transform(varinfo, varname)"]:::boxStyle
400+
E["<span style='color:#3B6EA8 !important;'>return</span> f(getindex_internal(varinfo, varname))"]:::dashedBox
401+
402+
A --> B
403+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>false</span>| C
404+
B -->|<span style='color:#97365B ; background-color:#ffffff;'>true</span>| D
405+
C --> E
406+
D --> E
407+
end
408+
409+
classDef dashedBox fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5,font-family:Courier,color:#000000
410+
classDef boxStyle fill:#ffffff,stroke:#000000,font-family:Courier,color:#000000
411+
412+
linkStyle default stroke:#000000,stroke-width:1px,color:#000000
309413
```
310414

311415
Notice that `dist` is not present here, but otherwise the diagrams are the same.

0 commit comments

Comments
 (0)