Skip to content

Commit 5fb16a9

Browse files
committed
math writeup first draft
1 parent 4bee915 commit 5fb16a9

File tree

5 files changed

+273
-0
lines changed

5 files changed

+273
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build/
44
/output/
55
/.vscode/
66
/.pixi/
7+
*.aux
8+
*.log

docs/fmb-math.qmd

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
\newcommand{\L}{\mathcal{L}}
2+
\newcommand{\N}{\mathbb{N}}
3+
\newcommand{\R}{\mathbb{R}}
4+
\newcommand{\SE}{\mathrm{SE}}
5+
\newcommand{\argmax}{\operatorname*{argmax}}
6+
7+
# Mathematical Description of Fuzzy Metaball Rendering
8+
9+
## Notation
10+
11+
$\N_n$ denotes the set $\{1, 2, \ldots, n\}$. $\SE(d)$ denotes the group of
12+
$d$-dimensional rigid transformations (hence $\SE(3)$ is the group of poses).
13+
$S^d$ denotes the $d$-dimensional sphere, i.e. the set of $d + 1$ dimensional
14+
unit vectors.
15+
16+
The notation $\mathrm{symbol} := \mathrm{expression}$ offers the definition of "symbol" in terms of the "expression."
17+
18+
Greek letters are unknowns, Latin letters are known
19+
20+
Writing $(\tau, \rho) := \pi $ for $\pi \in \SE(3)$ means that $\pi$'s translational
21+
component is $\tau$ and it's rotational component is $\rho$. For $v \in \R^d$
22+
we write $\pi\cdot v$ to denote $v$ transformed by $\pi$.
23+
24+
| Symbol | Type | Meaning |
25+
|:------:|:----:|:--------|
26+
| $N$ | $\N$ | number of fuzzy metaballs |
27+
| $T$ | $\N$ | number of time steps (frames) |
28+
| $H$ | $\N$ | height of each observed frame in pixels |
29+
| $W$ | $\N$ | width of each observed frame in pixels |
30+
| $i$ | $\N_H$ | index ranging over the rows in each observed frame |
31+
| $j$ | $\N_W$ | index ranging over the columns in each observed frame |
32+
| $k$ | $\N_N$ | index ranging over the fuzzy metaballs |
33+
| $t$ | $\N_T$ | index ranging over frames |
34+
| $v_{ij}$ | $S^2$ | direction of the ray corresponding to pixel $(i, j)$ in the camera frame |
35+
| $\pi^{(t)}$ | $\SE(3)$ | camera pose in world frame at frame $t$ |
36+
| $\mu_k$ | $\R^3$ | the mean vector of the $k$-the fuzzy metaball |
37+
| $\Sigma_k$ | $\R^{3\times 3}_{\succ 0}$ | the covariance matrix of the $k$-the fuzzy metaball |
38+
| $\lambda_k$ | $\R$ | log-weight of the $k$-the fuzzy metaball |
39+
| $d_{ijk}^{(t)}$ | $\R$ | intersection depth of ray corresponding to pixel $(i, j)$ at frame $t$ with the $k$-th fuzzy metaball |
40+
| $q_{ijk}^{(t)}$ | $\R$ | the value of the quadratic form of $k$-th fuzzy metaball at the intersection of ray $(i, j)$ at frame $t$ |
41+
| $w_{ijk}^{(t)}$ | $\R$ | depth blending weight of the $k$-th fuzzy metaball for pixel $(i, j)$ at frame $t$ |
42+
| $\bar{d}_{ij}^{(t)}$ | $\R$ | depth value of pixel $(i, j)$ at frame $t$ |
43+
| $c_{ij}^{(t)}$ | $[0, 1]$ | confidence value of pixel $(i, j)$ at frame $t$ |
44+
| $\L_c$ | $\R$ | contour loss (a function of $c_{ij}^{(t)}$) |
45+
| $\L_d$ | $\R$ | depth loss (a function of $d_{ij}^{(t)}$) |
46+
47+
48+
## Forward Pass
49+
50+
\begin{align*}
51+
%\argmax_{d \in \R} (\mu_k - \Delta x^{(t)} - dv_{ij}^{(t)})^\top
52+
%\Sigma^{-1} (\mu_k - \Delta x^{(t)} - dv_{ij}^{(t)}) \\
53+
(\tau^{(t)}, \rho^{(t)}) &:= \pi^{(t)} \\
54+
v_{ij}^{(t)} &:= \rho^{(t)}v_{ij} \\
55+
d_{ijk}^{(t)} &:= \frac{(\mu_k - \tau^{(t)})^\top\Sigma_k^{-1}v_{ij}^{(t)}}
56+
{{v_{ij}^{(t)}}^\top\Sigma_k^{-1}v_{ij}^{(t)}} \\
57+
q_{ijk}^{(t)} &:= (\mu_k - \tau^{(t)} - d_{ijk}^{(t)}v_{ij}^{(t)})^\top
58+
\Sigma_k^{-1} (\mu_k - \tau^{(t)} - d_{ijk}^{(t)}v_{ij}^{(t)}) \\
59+
\tilde{w}_{ijk}^{(t)} &:=
60+
\exp\left(\beta_1(-q_{ijk}^{(t)}/2 + \lambda_k) - \beta_2 d_{ijk}^{(t)}\right) \\
61+
w_{ijk}^{(t)} &:= \frac{\tilde{w}_{ijk}^{(t)}}{\sum_{k=1}^N \tilde{w}_{ijk}^{(t)}} \\
62+
\bar{d}_{ij}^{(t)} &:= \sum_{k=1}^N w_{ijk}^{(t)} d_{ijk}^{(t)} \\
63+
c_{ij}^{(t)} &:= 1 - \exp\left(\sum_{k=1} \exp(q_{ijk}^{(t)}/2 - \lambda_k)\right)
64+
\end{align*}
65+
66+
![Dependency graph of the variables in the forward pass using plate
67+
notation](plate_diagram.png){width=540}
68+
69+
## Depth Backward Pass
70+
71+
\begin{align*}
72+
\frac{\partial \L_d}{\partial \tilde{w}_{ijk}^{(t)}} &=
73+
\frac{\partial \L_d}{\partial \bar{d}_{ij}^{(t)}}
74+
\frac{\partial \bar{d}_{ij}^{(t)}}{\partial \tilde{w}_{ijk}^{(t)}}\\
75+
\frac{\partial \L_d}{\partial q_{ijk}^{(t)}} &=
76+
\frac{\partial \L_d}{\partial \tilde{w}_{ijk}^{(t)}}
77+
\frac{\partial \tilde{w}_{ijk}^{(t)}}{\partial q_{ijk}^{(t)}}\\
78+
\frac{\partial \L_d}{\partial d_{ijk}^{(t)}} &=
79+
\frac{\partial \L_d}{\partial q_{ijk}^{(t)}}
80+
\frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
81+
+ \frac{\partial \L_d}{\partial \tilde{w}_{ijk}^{(t)}}
82+
\frac{\partial \tilde{w}_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
83+
+ \frac{\partial \L_d}{\partial \bar{d}_{ij}^{(t)}}
84+
\frac{\partial \bar{d}_{ij}^{(t)}}{\partial d_{ijk}^{(t)}} \\
85+
\frac{\partial \L_d}{\partial \tau^{(t)}} &=
86+
\sum_{i,j}\sum_k \frac{\partial \L_d}{\partial q_{ijk}^{(t)}}
87+
\frac{\partial q_{ijk}^{(t)}}{\partial \tau^{(t)}}
88+
+ \sum_{i,j}\sum_k \frac{\partial \L_d}{\partial d_{ijk}^{(t)}}
89+
\frac{\partial d_{ijk}^{(t)}}{\partial \tau^{(t)}} \\
90+
\frac{\partial \L_d}{\partial v_{ij}^{(t)}} &=
91+
\sum_k \frac{\partial \L_d}{\partial q_{ijk}^{(t)}}
92+
\frac{\partial q_{ijk}^{(t)}}{\partial v_{ij}^{(t)}}
93+
+ \sum_k \frac{\partial \L_d}{\partial d_{ijk}^{(t)}}
94+
\frac{\partial d_{ijk}^{(t)}}{\partial v_{ij}^{(t)}} \\
95+
\frac{\partial \L_d}{\partial \rho^{(t)}} &=
96+
\sum_{i,j} \frac{\partial \L_d}{\partial v_{ij}^{(t)}}
97+
\frac{\partial v_{ij}^{(t)}}{\partial \rho^{(t)}} \\
98+
\frac{\partial \L_d}{\partial \lambda_k} &=
99+
\sum_t \sum_{i, j}
100+
\frac{\partial \L_d}{\partial \tilde{w}_{ijk}^{(t)}}
101+
\frac{\partial \tilde{w}_{ijk}^{(t)}}{\partial \lambda_k} \\
102+
\frac{\partial \L_d}{\partial \mu_k} &=
103+
\sum_t \sum_{i, j} \frac{\partial \L_d}{\partial q_{ijk}^{(t)}}
104+
\frac{\partial q_{ijk}^{(t)}}{\partial \mu_k}
105+
+ \sum_t \sum_{i, j} \frac{\partial \L_d}{\partial d_{ijk}^{(t)}}
106+
\frac{\partial d_{ijk}^{(t)}}{\partial \mu_k} \\
107+
\frac{\partial \L_d}{\partial \Sigma_k} &=
108+
\sum_t \sum_{i, j} \frac{\partial \L_d}{\partial q_{ijk}^{(t)}}
109+
\frac{\partial q_{ijk}^{(t)}}{\partial \Sigma_k}
110+
+ \sum_t \sum_{i, j} \frac{\partial \L_d}{\partial d_{ijk}^{(t)}}
111+
\frac{\partial d_{ijk}^{(t)}}{\partial \Sigma_k} \\
112+
\end{align*}
113+
114+
115+
## Confidence Backward Pass
116+
117+
\begin{align*}
118+
\frac{\partial \L_c}{\partial d_{ijk}^{(t)}} &=
119+
\frac{\partial \L_c}{\partial q_{ijk}^{(t)}}
120+
\frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}\\
121+
\frac{\partial \L_c}{\partial q_{ijk}^{(t)}} &=
122+
\frac{\partial \L_c}{\partial c_{ij}^{(t)}}
123+
\frac{\partial c_{ij}^{(t)}}{\partial q_{ijk}^{(t)}}\\
124+
\frac{\partial \L_c}{\partial \tau^{(t)}} &=
125+
\sum_{i,j}\sum_k \frac{\partial \L_c}{\partial d_{ijk}^{(t)}}
126+
\frac{\partial d_{ijk}^{(t)}}{\partial \tau^{(t)}}
127+
+ \sum_{i,j}\sum_k \frac{\partial \L_c}{\partial q_{ijk}^{(t)}}
128+
\frac{\partial q_{ijk}^{(t)}}{\partial \tau^{(t)}}\\
129+
\frac{\partial \L_c}{\partial v_{ij}^{(t)}} &=
130+
\sum_{k} \frac{\partial \L_c}{\partial d_{ijk}^{(t)}}
131+
\frac{\partial d_{ijk}^{(t)}}{\partial v_{ij}^{(t)}}
132+
+ \sum_{k} \frac{\partial \L_c}{\partial q_{ijk}^{(t)}}
133+
\frac{\partial q_{ijk}^{(t)}}{\partial v_{ij}^{(t)}} \\
134+
\frac{\partial \L_c}{\partial \rho^{(t)}} &=
135+
\sum_{i,j} \frac{\partial \L_c}{\partial v_{ij}^{(t)}}
136+
\frac{\partial v_{ij}^{(t)}}{\partial \rho^{(t)}} \\
137+
\frac{\partial \L_c}{\partial \lambda_k} &=
138+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
139+
\frac{\partial c_{ij}^{(t)}}{\partial \lambda_k} \\
140+
\frac{\partial \L_c}{\partial \mu_k} &=
141+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial q_{ijk}^{(t)}}
142+
\frac{\partial q_{ijk}^{(t)}}{\partial \mu_k}
143+
+ \sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial d_{ijk}^{(t)}}
144+
\frac{\partial d_{ijk}^{(t)}}{\partial \mu_k} \\
145+
\frac{\partial \L_c}{\partial \Sigma_k} &=
146+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial q_{ijk}^{(t)}}
147+
\frac{\partial q_{ijk}^{(t)}}{\partial \Sigma_k}
148+
+ \sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial d_{ijk}^{(t)}}
149+
\frac{\partial d_{ijk}^{(t)}}{\partial \Sigma_k}
150+
\end{align*}
151+
152+
We can simplify the backward pass by inlining those derivatives that depend on
153+
fixed $i$, $j$, and $t$. We get:
154+
155+
\begin{align*}
156+
\frac{\partial \L_c}{\partial \tau^{(t)}} &=
157+
\sum_{i,j}\sum_k \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
158+
\frac{\partial c_{ij}^{(t)}}{\partial q_{ijk}^{(t)}} \left(
159+
\frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
160+
\frac{\partial d_{ijk}^{(t)}}{\partial \tau^{(t)}}
161+
+ \frac{\partial q_{ijk}^{(t)}}{\partial \tau^{(t)}}
162+
\right)\\
163+
\frac{\partial \L_c}{\partial \rho^{(t)}} &=
164+
\sum_{i,j} \sum_{k} \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
165+
\frac{\partial c_{ij}^{(t)}}{\partial q_{ijk}^{(t)}} \left(
166+
\frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
167+
\frac{\partial d_{ijk}^{(t)}}{\partial v_{ij}^{(t)}}
168+
+ \frac{\partial q_{ijk}^{(t)}}{\partial v_{ij}^{(t)}}
169+
\right)
170+
\frac{\partial v_{ij}^{(t)}}{\partial \rho^{(t)}} \\
171+
\frac{\partial \L_c}{\partial \lambda_k} &=
172+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
173+
\frac{\partial c_{ij}^{(t)}}{\partial \lambda_k} \\
174+
\frac{\partial \L_c}{\partial \mu_k} &=
175+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
176+
\frac{\partial c_{ij}^{(t)}}{\partial q_{ijk}^{(t)}} \left(
177+
\frac{\partial q_{ijk}^{(t)}}{\partial \mu_k}
178+
+ \frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
179+
\frac{\partial d_{ijk}^{(t)}}{\partial \mu_k}
180+
\right) \\
181+
\frac{\partial \L_c}{\partial \Sigma_k} &=
182+
\sum_{t}\sum_{i,j} \frac{\partial \L_c}{\partial c_{ij}^{(t)}}
183+
\frac{\partial c_{ij}^{(t)}}{\partial q_{ijk}^{(t)}} \left(
184+
\frac{\partial q_{ijk}^{(t)}}{\partial \Sigma_k}
185+
+ \frac{\partial q_{ijk}^{(t)}}{\partial d_{ijk}^{(t)}}
186+
\frac{\partial d_{ijk}^{(t)}}{\partial \Sigma_k}
187+
\right) \\
188+
\end{align*}
189+
190+
##

docs/make_fig.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
pdflatex plate_diagram.tex
4+
convert -verbose -density 300 -trim plate_diagram.pdf -size 1080x1080 -quality 100 -flatten -sharpen 0x1.0 plate_diagram.png

docs/plate_diagram.png

45.2 KB
Loading

docs/plate_diagram.tex

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
\documentclass[border=10pt]{standalone}
2+
\usepackage{tikz}
3+
\usepackage{amsmath,amssymb}
4+
5+
\usetikzlibrary{arrows.meta, positioning, fit, backgrounds}
6+
7+
\begin{document}
8+
% if plate p binds index i and variable v appears in p, then v should vary over
9+
% i
10+
\begin{tikzpicture}[
11+
node distance=1cm and 1cm,
12+
>={Stealth[length=2mm]},
13+
every node/.style={font=\small},
14+
every edge/.style = {draw, -latex}
15+
]
16+
17+
% Define coordinates for nodes
18+
\node (lambdak) at ( -1, 5) {$\lambda_k$};
19+
\node (muk) at ( 0, 5) {$\mu_k$};
20+
\node (Sigmak) at ( 1, 5) {$\Sigma_k$};
21+
22+
\node (vij) at (2.5, 4) {$v_{ij}^{(t)}$};
23+
\node (rho) at ( 4, 4) {$\rho^{(t)}$};
24+
25+
\node (tau) at ( 4, 3.5) {$\tau^{(t)}$};
26+
27+
\node (qijk) at ( 0, 2.5) {$q_{ijk}^{(t)}$};
28+
\node (dijk) at ( 1, 2.5) {$d_{ijk}^{(t)}$};
29+
30+
\node (wijk) at ( 0, 1) {$\tilde{w}_{ijk}^{(t)}$};
31+
32+
\node (cij) at ( -1, -0.2) {$c_{ij}^{(t)}$};
33+
\node (dijbar) at ( 1, -0.2) {$\bar{d}_{ij}^{(t)}$};
34+
35+
\node (Lc) at ( -1, -1.4) {$\mathcal{L}_c$};
36+
\node (Ld) at ( 1, -1.4) {$\mathcal{L}_d$};
37+
38+
39+
\draw (Sigmak.south) edge (qijk.north) edge (dijk.north)
40+
(muk.south) edge (qijk.north) edge (dijk.north)
41+
(vij.south) edge (qijk.north) edge (dijk.north)
42+
(rho.west) edge (vij.east)
43+
(tau.west) edge (qijk.north) edge (dijk.north)
44+
(lambdak.south) edge (wijk.north) edge (cij.north)
45+
(qijk.south) edge (wijk.north) edge (cij.north)
46+
(dijk.south) edge (wijk.north) edge (dijbar.north)
47+
(dijk.west) edge (qijk.east)
48+
(wijk.south) edge (dijbar.north)
49+
(cij) edge (Lc)
50+
(dijbar) edge (Ld);
51+
52+
% Inner plate k
53+
\begin{scope}[on background layer]
54+
\node[draw, rectangle, rounded corners=2pt,
55+
inner sep=4pt,
56+
fit=(Sigmak)(muk)(lambdak)(wijk)(dijk),
57+
label={[anchor=south east, font=\small]south east:$k$}] (plate_k) {};
58+
\end{scope}
59+
60+
% Middle plate (i,j)
61+
\begin{scope}[on background layer]
62+
\node[draw, rectangle, rounded corners=2pt,
63+
inner sep=4pt,
64+
fit=(wijk)(dijk)(vij)(cij)(dijbar),
65+
label={[anchor=south east, font=\small]south east:$(i,j)$}] (plate_ij) {};
66+
\end{scope}
67+
68+
% Outer plate t
69+
\begin{scope}[on background layer]
70+
\node[draw, rectangle, rounded corners=2pt,
71+
inner sep=4pt,
72+
fit=(plate_ij)(rho)(tau),
73+
label={[anchor=south east, font=\small]south east:$t$}] (plate_t) {};
74+
\end{scope}
75+
76+
\end{tikzpicture}
77+
\end{document}

0 commit comments

Comments
 (0)