Set Representations¶
- A set is an unordered sequence.
- If $${\bf x} = (x_1,\ldots,x_n)$$ is the unordered sequence, then the neural network $f$ must output the same value for whatever permutation of ${\bf x}$, that is $$f({\bf x}) = f(\pi \circ {\bf x}),$$ where $\pi$ is a permutation of the sequence $(1, 2,\ldots,n)$ and the operator "$\circ$" is the appropriate (permutation) action on ${\bf x}$ defined as $$\pi \circ {\bf x} \equiv (x_{\pi_1},\ldots,x_{\pi_n}).$$
- Sets often contain other invariances besides permutation invariance
- Example: Point clouds (3D objects, molecules, ...)
Permutation Invariance¶
In our CNN class, we have seen that max-pooling can create a permutation invariant layer.
That is, given a sequence (input vector) $$ {\bf x} = (x_1,\ldots,x_n) $$ and a permutation $\pi$ over the integers $\{1, 2,\ldots,n\}$ such that $\pi \circ {\bf x} = (x_{\pi_1},\ldots,x_{\pi_n})$ is the correspondingly permuted version of ${\bf x}$, the max-pooling function over ${\bf x}$ has the property that $$ \Gamma_\text{max-pooling}({\bf x}) = \Gamma_\text{max-pooling}(\pi\circ{\bf x}), \quad \forall \pi \in \mathbb{S}_n, $$ where $\mathbb{S}_n$ is the symmetric group of order $n$ (which defines a set of all permutations over the integers $\{1, 2,\ldots,n\}$).
Note that max-pooling is also the same basic operation for any value of $n > 0$ (i.e., it operates over any-size inputs).
In this lecture we will see that max pooling is one of the simplest examples of a class of neural networks that can ensure permutation invariances.
However, max-pooling (min-pooling) is a heuristic that is not learnable.
Q: What other heuristics are permutation-invariant and can operate on any-size inputs?
- Mean (sum): $$\Gamma_\text{mean-pooling}({\bf x}) = \frac{1}{n} \sum_{i=1}^n x_i.$$
- Median: $$\Gamma_\text{median-pooling}({\bf x}) = \frac{x_{(\lfloor|{\bf x}|/2 \rfloor)} + x_{(\lceil|{\bf x}|/2 \rceil)} }{2},$$ where $x_{(j)}$ is the $j$-th largest value in ${\bf x}$.
- Sorting: $$\Gamma_\text{sort-pooling}({\bf x}) = \vec{\Gamma}(\text{sort}({\bf x})),$$ where
A.$~~$ $\vec{\Gamma}$ indicates a function (neural network) that can be permutation-sensitive (e.g., MLP for fixed-size inputs and RNNs (covered later) for variable-size inputs).
B.$~~$ $\text{sort}({\bf x})$ is a function that returns ${\bf x}$ in a canonical order. That is, $\text{sort}({\bf x}) = \text{sort}(\pi \circ {\bf x})$, $\forall \pi \in \mathbb{S}_n$, where $\mathbb{S}_n$ is the symmetric group of order $n$.
Task:
- input: ${\bf x}^{(i)} =\{x_{j}^{(i)}\}_{j=1}^n = \{x_{1}^{(i)},\ldots,x_{n}^{(i)}\}$ denotes an unordered set, where there is no notion of an order of the variables
- output: ${\bf y}_i$ or a representation of ${\bf x}^{(i)}$
- Training data: $D_\text{train}=\{{\bf x}^{(i)},{\bf y}_i\}_i$
Understanding Set Representations¶
Probability distributions over sets¶
Consider a set of random variables over a countable space $\Omega$: $$ \{X_{j}\}_{j=1}^n,\qquad X_j \in \Omega $$
Joint probability distributions are only defined over ordered sequences (vectors). That is, the joint probability $P$ is defined as $$ P: \Omega^n \to [0,1] $$
Q: How should we define their joint probability distribution as a set?
Definition: The probability distribution $P$ must be such that $$ P(X_1,\ldots,X_n) = P(X_{\pi_1},\ldots,X_{\pi_n}), $$ for any permutation $\pi$ of $\{1,\ldots,n\}$.
The property of a probability distribution $P$ to be invariant under permutations is also known as exchangeability, since exchanging the random variables $X_{\pi_1},\ldots,X_{\pi_n}$ does not change their joint probability distribution.
Applications¶
- Vision (CNNs, etc.)
- Online shopping (to describe probabilities over shopping baskets)
- Self-driving cars (LIDAR point clouds, Tesla point cloud representations)
- Anomaly detection
- Predict our behavior from our set of friends, set of objects, set of products, set of preferences
- ...
Set Representations¶
The noise transfer theorem (noise outsourcing) allows us to decompose $P(X_1,\ldots,X_n)$ as a
A set representation $\Gamma(x_1,\ldots,x_n)$, which has the property that $\forall \pi \in \mathbb{S}_n$, $$\Gamma(x_1,\ldots,x_n) = \Gamma(x_{\pi_1},\ldots,x_{\pi_n})$$
And a deterministic function $\alpha:\Omega^n \to [0,1]$
$$ P(X_1,\ldots,X_n) = \alpha(\Gamma(X_1,\ldots,X_n)) $$
Infinite Exchangeability¶
Assume we have an infinite sequence of exchangeable variables. Then:
De Finetti's theorem: The probability distribution of any infinite sequence of $\{0, 1\}$-valued exchangeable random variables can be described as a mixture of conditionally independent distributions: $$ P(X_1,X_2,\ldots) = \int_\theta \prod_{i=1}^\infty P(X_i| \theta) d\!P(\theta). $$
This is the inspiration for a lot of Bayesian models: e.g., Latent Dirichlet Allocation.
Infinite exchangeability in functional representation: $$ P(X_1,X_2,\ldots) = \int_\theta \prod_{i=1}^\infty \alpha \left(\Gamma_\theta(X_i)\right) d\!P(\theta). $$
Note that this is just applying a representation over all set elements.
Can De Finetti's theorem be used in finite (large) sets?¶
Consider the following set distribution:
- There are $n$ online shoppers that are buying exactly one product on a website.
- Let $X_j$ be the product purchased by user $j$.
- There is only one last can of tuna.
Q: Assume $n$ is very large but finite. Can we arbitrarily approximate (or describe) $$P(X_1,\ldots,X_n)$$ using De Finetti's conditional independent mixture model? I.e., $$ P(X_1,\ldots,X_n) \approx \int_\theta \prod_{i=1}^n P(X_i| \theta) d\!P(\theta). $$
A: No, since no matter how large $n$ is, $P(X_2 = \text{tuna}|X_1=\text{tuna}) = 0$ but $P(X_2 = \text{tuna})>0$, and these two conditions cannot be represented by a mixture of conditionally independent distributions.
- Here is one example (of many) in statistics where arbitrarily large $\not\approx \infty$
A good read on the topic is Diaconis, Finite forms of de Finetti’s theorem on exchangeability, Synthese 1977
Can De Finetti's theorem be used in finite sets?¶
Consider the following scenario:
- Consider $n=2$ coin flips $X_1$, $X_2$, and denote head by $1$, tail by $0$
- Assume $$ P(X_1=1, X_2=0) = P(X_1=0, X_2=1) = \frac{1}{2} \\ P(X_1=0, X_2=0) = P(X_1=1, X_2=1) = 0 $$
The pair $X_1, X_2$ is exchangeable.
Q: Can we arbitrarily approximate (or describe) $$P(X_1, X_2)$$ using De Finetti's conditional independent mixture model? I.e., $$ P(X_1 = e_1, X_2 = e_2) \approx \int_\theta \prod_{i=1}^n P(X_i = e_i| \theta) d\!P(\theta), $$ for each sequence of zeros and ones $\{e_i\}_{i=1}^2$?
A: No, if there exists $P(\theta)$ such that $$ 0 = P(X_1 = 1, X_2 = 1) = \int_\theta P(X_1 = 1| \theta) P(X_2 = 1| \theta) d\!P(\theta), $$ then necessarily $P(\theta)$ puts mass 1 at the point when $P(X_1 = 1| \theta) = P(X_2 = 1| \theta) = 0$, which is also the point when $P(X_1 = 0| \theta) = P(X_2 = 0| \theta) = 1$, so we cannot have $$ 0 = P(X_1 = 0, X_2 = 0) = \int_\theta P(X_1 = 0| \theta) P(X_2 = 0| \theta) d\!P(\theta). $$
Since we have reached a contradiction we cannot use De Finetti's conditional independent mixture model.
Finite exchangeable representations¶
Finite exchangeability requires a more complex representation: $$ P(X_1,\ldots, X_n) = \rho\left(\Gamma(X_1,\ldots,X_n)\right) $$ such that $\forall \pi \in \mathbb{S}_n$, $$\Gamma(x_1,\ldots,x_n) = \Gamma(x_{\pi_1},\ldots,x_{\pi_n})$$
Q: Can we learn a representation $\Gamma(X_1,\ldots,X_n)$ using a MLP?
A: Yes, MLPs are universal approximators. However, with finite data, the learned MLP will probably be permutation sensitive.
Q: How can we enforce permutation-invariant representations for sets of arbitrary sizes?
Learnable permutation-invariant representations?¶
Learnable permutation-invariant functions with any-size inputs¶
We would like to learn these pooling operations, rather than relying on heuristics.
- Goal: Learn a function $\Gamma(\cdot ; \boldsymbol{\theta}^{(F)})$ that is permutation-invariant function taking any-size inputs.
- More formally, $\Gamma: \cup_{j=0}^\infty \mathbb{R}^j \times \mathbb{R}^a \to \mathbb{R}^d$, where $d > 0$ is the dimension of the representation output and $a > 0$ is the number of parameters we need to learn.
Murphy et al., 2019 defines the permutation-invariant representation as: $$ \tag{1} \label{eq:dbarf} \Gamma({\bf x}; \boldsymbol{\theta}^{(F)}) = \frac{1}{n!} \sum_{\pi \in \mathbb{S}_n} F(\pi \circ {\bf x} ; \boldsymbol{\theta}^{(F)}), $$ where $F$ is any permutation-sensitive function (MLP, CNN, RNN...). We will call this representation Janossy pooling.
Learning tractability¶
All existing approaches to learnable permutation representations are special cases of Equation (1).
Exercise:
- Show that max, min, mean, and sort pooling are special (tractable) cases of Equation (1).
Learning the representation:
- (Supervised learning) The optimization goal is to minimize the empirical loss over the training data $\mathcal{D} = \{({\bf x}^{(i)},{\bf y}_{i})\}_{i=1}^N$, with the loss defined as $$\begin{equation}\label{eq:Loss} \tag{2} \overline{\overline{L}}(\mathcal{D};\boldsymbol{\theta}^{(\alpha)},\boldsymbol{\theta}^{(F)}) = \frac{1}{N}\sum_{i=1}^N \! L\left({\bf y}_i , \alpha\Big( \Gamma({\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \right) , \end{equation}$$ where $$ \begin{equation} \tag{3} \label{eq:janLoss} \Gamma({\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) = \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} \!\!F(n^{(i)}, \pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}). \end{equation} $$ where $n^{(i)}$ is the length of sequence ${\bf x}^{(i)}$
- Noting the ${\bf x}^{(i)}$ may be the inputs given by the previous layer.
- Equation $(\ref{eq:janLoss})$ is computationally intractable for large inputs.
Computational tractability of learnable any-size permutation-insensitive representations¶
There are three main approaches to make Equation (3) computationally tractable.
- Canonical Ordering, defines or learns the $\text{sort}(\cdot)$ function.
- Assume $k$-ary dependencies, where we assume all the information in ${\bf x}$ can be uncovered by analyzing up to $k$ elements in ${\bf x}$, where we don't know which $k$ elements are important in the sequence (otherwise this would be a canonical order).
- Stochastic Optimization via Random Permutations, where at each gradient step we will sample a permutation $\pi$ from $\Pi$ and perform a forward and backward step of Equation (3) with this single sampled permutation.
- Framing: Reduce the group size based on the input.
1. Tractability Through Canonical Ordering¶
A good canonical order must be correlated with the task.
- CNNs use max-pooling to add some permutation-invariance in the architecture, which can be thought of as a very simple type of canonical order: $\Gamma_\text{max-pooling}({\bf x}) = \text{sort}({\bf x},\text{order=descending})[0]$.
- Learning canonical orderings: Another approach is that of learning canonical orders from the data. That is, among all possible $\Pi$ orderings of the input ${\bf x}$, which one is the best with respect to the task. For instance, Vinyals et al., 2016. This is a discrete optimization task and only approximations are available.
Q: Give an example where a canonical order will fail
A: Consider a two-dimensional random variable input $X_i = (A_i,B_i)$. Assume we decide to sort by $A_i$ but the target label depends only on $B_i$, where $A_i$ is independent of $B_i$.
2. Tractability Through $k$-ary Dependencies¶
- Fix $k \in \mathbb{Z}^+$.
- Assume $k$-ary dependencies in the input sequence ${\bf x}$ leads to a significant simplification of Equation (3).
- For any sequence ${\bf x}$, define $\downarrow_{k}\!\!({\bf x})$ as a function that keeps only the first $k$ elements of the sequence (if $n < k$ we append $(k-n)$ zeros at the end of ${\bf x}$ to make it at least of size $k$). Then, with this $k$-ary assumption Equation (3) becomes $$ \begin{equation} \tag{4} \label{eq:fKary} \Gamma(n, {\bf x} ; \boldsymbol{\theta} ) = \frac{1}{n!} \sum_{\pi \in \Pi_{n}} F(k, \downarrow_{k}\!\!({\bf x}_{\pi}); \boldsymbol{\theta}) = \frac{(n-k)!}{n!}\sum_{\pi\in \Pi_{n}^k}F\big(k,\downarrow_{k}\!\!(\pi \circ {\bf x})) ; \boldsymbol{\theta} \big), \end{equation} $$ where $\Pi_{n}^k$ are all the distinct $k$-length permutations of a sequence of length $n$.
Theorem 2.1 (Murphy et al., 2019): For any $k\in\mathbb{Z}^+$, define $\mathcal{F}_{k}$ as the set of all permutation invariant functions that can be represented by Equation (3) with $k$-ary dependencies.
- Then, $\mathcal{F}_{k-1}$ is a proper subset of $\mathcal{F}_k$. That is, Janossy pooling with $k$-ary dependencies can express any permutation-insensitive representation with $(k-1)$-ary dependencies, but the converse does not hold.
DeepSets: $k=1$ (Unary) dependencies are what we have earlier described as mean-pooling $$\Gamma_\text{mean-pooling}({\bf x}; \boldsymbol{\theta}) = \frac{1}{n} \sum_{j=1}^n F(x_j; \boldsymbol{\theta})$$ which is used by existing Graph Neural Network (GNN) models, as we will se in our next class.
DeepSets (Zaheer et al., 2017) proves that models using $k=1$-ary representation can learn arbitrary dependencies in the input data as long as its output is coupled with an universal approximator non-linearity. Corollary 2.1 of Murphy et al., 2019 shows that this non-linearity is in charge of undoing the sum of $k=1$ to model higher-order $k$-ary dependencies, $k > 1$. In practice, neural networks not always can recover $k$-ary dependencies from unary Janossy pooling.
Set Transformer: $k=2$ (Pairwise) dependencies can be learned with the Transformer archtecture (Lee et al., 2019) (which we will cover later in the course)
3. Tractability Through Stochastic Optimization with Permutation Sampling¶
The only known tractable learnable permutation-invariant representation that makes no assumptions about the inputs is approximation using stochastic optimization.
Remember our loss function: $$\tag{5}\overline{\overline{L}}(\mathcal{D};\boldsymbol{\theta}^{(\rho)},\boldsymbol{\theta}^{(F)}) = \frac{1}{N}\sum_{i=1}^N \! L\left({\bf y}_i , \alpha\Big( \Gamma({\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\rho)} \Big) \right),$$ where $$\tag{6} \Gamma({\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) = \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} F(n^{(i)}, \pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}).$$
Computing the gradient of Equation $(6)$ is intractable for large inputs ${\bf x}^{(i)}$, as the backpropagation computation graph branches out for every permutation in the sum. To address this computational challenge, we will use stochastic optimization.
Before we go into the details of permutation sampling, we need two results:
Note 1:. If $\textrm{X}$ is a random variable with non-zero variance, and $\alpha(\cdot)$ is a non-linear function, then it is possible that $E[\alpha(\textrm{X})] \neq \alpha(E[\textrm{X}])$.
Note 2: (Jensen's inequality) If $\textrm{X}$ is a random variable and $\alpha(\cdot)$ is a convex function, then $E[\alpha(\textrm{X})] \geq \alpha(E[\textrm{X}])$. Thus, minimizing $E[\alpha(\textrm{X})]$ is a surrogate to minimizing $\alpha(E[\textrm{X}])$.
Note 3: The negative log-likelihood objective is convex on the neural network model output, that is, on the predictions/logits themselves, but not on the network parameters. This means that while the loss surface is convex with respect to the final layer outputs, the overall optimization problem remains non-convex due to the compositional nature of neural networks.
Convexity in Logit Space¶
For classification tasks, the NLL—often implemented as cross-entropy loss—is inherently convex when viewed as a function of the network's raw output logits. Consider a binary classification problem with labels $y \in \{0,1\}$ and logits $z = f(\mathbf{x}; \mathbf{W})$, where $f$ is the neural network parametrized by $\mathbf{W}$. The NLL is defined as: $$ L(z, y) = -y \log(\sigma(z)) - (1 - y) \log(1 - \sigma(z)), $$ where $\sigma(z) = \frac{1}{1 + e^{-z}}$ is the sigmoid function. The convexity of $L$ with respect to $z$ can be verified by examining its second derivative: $$ \frac{\partial^2 L}{\partial z^2} = \sigma(z)(1 - \sigma(z)) > 0 \quad \forall z \in \mathbb{R}. $$
The strict positivity of the second derivative shows that $L(z, y)$ is convex in $z$. For multi-class classification, the softmax-activated NLL is also convex in the logit vector $\mathbf{z}$, as the Hessian with respect to $\mathbf{z}$ is positive semi-definite (PSD).
Important: Despite convexity in logit space, the NLL becomes non-convex when viewed as a function of the network parameters $\mathbf{W}$.
Recall that we were interested in: $$\tag{7} \Gamma({\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) = \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} \!\!F(n^{(i)}, \pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}).$$
Permutation sampling. Consider replacing the sum with the estimate $$\tag{8}\hat{\Gamma}({\bf x} ; \boldsymbol{\theta}^{(F)} ) = F(n_{\textrm{s}}, \textrm{s}\circ{\bf x}; \boldsymbol{\theta}^{(F)}),$$ where $\textrm{s}$ is a random permutation sampled uniformly, $\textrm{s} \sim \text{Unif}(\mathbb{S}_{n})$ and $n_{\textrm{s}}$ is the length of the sequence ${\bf x}_{\textrm{s}}$.
The estimator in Equation $(8)$ is unbiased: $E_\textrm{s}[\hat{\Gamma}({\bf x} ; \boldsymbol{\theta}^{(F)} )] = \Gamma({\bf x} ; \boldsymbol{\theta}^{(F)} ).$ Note however that when $\Gamma$ is chained with another nonlinear function $\alpha$ and/or nonlinear loss $L$, the composition is no longer unbiased: $$E_\textrm{s}[L({\bf y},\alpha(F(n_\textrm{s}, \textrm{s}\circ {\bf x}; \boldsymbol{\theta}^{(F)});\boldsymbol{\theta}^{(\alpha)}))] \neq L({\bf y},\alpha(E_\textrm{s}[F(n_\textrm{s}, \textrm{s}\circ {\bf x}; \boldsymbol{\theta}^{(F)})];\boldsymbol{\theta}^{(\alpha)})) .$$
- Deep down, the approach is similar to the data augmentation used by CNNs (random transformations)
Definition 2.3 $\pi$-SGD (Murphy et al., 2019):
Let $\mathcal{B} =\{({\bf x}^{(1)},{\bf y}_{1}),\ldots,({\bf x}^{(B)},{\bf y}_{B})\}$ be a mini-batch sampled uniformly i.i.d. from the training data $\mathcal{D}$.
At step $t$, consider the stochastic gradient descent update
$$\begin{equation}\label{eq:piSGD} \boldsymbol{\theta}_t = \boldsymbol{\theta}_{t-1} - \eta_t \textrm{Z}_t,\end{equation}$$
where $\textrm{Z}_t$ is the random gradient
$$
\textrm{Z}_t = \frac{1}{B} \sum_{i=1}^B \nabla_{\boldsymbol{\theta}} L\left({\bf y}_{i} , \alpha\Big( F(\textrm{s}_i \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}_t) ; \boldsymbol{\theta}^{(\alpha)}_t \Big) \right)
$$
with $\boldsymbol{\theta} = (\boldsymbol{\theta}^{(\alpha)}, \boldsymbol{\theta}^{(F)})$, with the random permutations $\{\textrm{s}_i\}_{i=1}^B$, $\textrm{s}_i \sim \text{Uniform}(\mathbb{S}_{|{\bf x}^{(i)}|})$; the learning rate is $\eta_t \in (0,1)$ s.t. $\sum_{t=1}^\infty \eta_t = \infty$ and $\sum_{t=1}^\infty \eta_t^2 < \infty$.
Proposition 2.2 (Murphy et al., 2019): $\pi$-SGD opmizes via stochastic optimization the following objective (loss) function:
$$\begin{align} \tag{9} J(\mathcal{D};\boldsymbol{\theta}^{(\alpha)}, \boldsymbol{\theta}^{(F)}) &= \frac{1}{N}\sum_{i=1}^N E_{\textrm{s}_i}\left[ \! L\Bigg({\bf y}_i , \alpha\Big( F(\textrm{s}_i \circ {\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \Bigg) \right]\\ &= \frac{1}{N}\sum_{i=1}^N \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} L\Bigg({\bf y}_i , \alpha\Big( F(\pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \Bigg), \end{align}$$
- Like our original loss, the loss in Equation $(9)$ is also permutation invariant.
Compare the original loss: $$\overline{\overline{L}}(\mathcal{D};\boldsymbol{\theta}^{(\alpha)},\boldsymbol{\theta}^{(F)}) = \frac{1}{N}\sum_{i=1}^N \! L\left({\bf y}_i , \alpha\Big( \Gamma({\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \right) ,$$
where
$$\Gamma({\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) = E{\textrm{s}_i}\Big[F(\textrm{s}_i \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)})\Big] = \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} \!\!F(n^{(i)}, \pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}).$$
with the new objective: $$J(\mathcal{D};\boldsymbol{\theta}^{(\alpha)}, \boldsymbol{\theta}^{(F)}) = \frac{1}{N}\sum_{i=1}^N \frac{1}{n^{(i)}!} \sum_{\pi \in \mathbb{S}_{|{\bf x}^{(i)}|}} L\Bigg({\bf y}_i , \alpha\Big( F(\pi \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \Bigg).$$
Observe that the expectation over permutations is now outside the $L$ and $\alpha$ functions.
In general, the optima of $J$ are different from those of the original objective function $\overline{\overline{L}}$.
But, using Note 2 (Jensen's inequality) and Note 3 (Convexity in Logit Space), if $L$ is the NLL we can extend this to:
$$\frac{1}{N}\sum_{i=1}^N E_{\textrm{s}_i}\left[ \! L\Bigg({\bf y}_i , \alpha\Big( F(\textrm{s}_i \circ {\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)} \Big) \Bigg) \right] \geq \frac{1}{N}\sum_{i=1}^N \! L\Bigg({\bf y}_i , E_{\textrm{s}_i}\left[\alpha\Big( F(\textrm{s}_i \circ {\bf x}^{(i)};\boldsymbol{\theta}^{(F)}) ; \boldsymbol{\theta}^{(\alpha)}\right] \Big) \Bigg) $$
- And, if $L$ is the NLL, and $\alpha$ is the sigmoid or softmax functions, we can use Note 3 (Convexity in Logit Space) again to show that $\pi$-SGD minimizes an upper bound of the true loss. $$\frac{1}{N}\sum_{i=1}^N E_{\textrm{s}_i}\left[ \! L\Bigg({\bf y}_i , \sigma\Big( F(\textrm{s}_i \circ {\bf x}^{(i)};\boldsymbol{\theta}^{(F)})\Big) \Bigg) \right] \geq \frac{1}{N}\sum_{i=1}^N L\Bigg({\bf y}i, \sigma\Big(E{\textrm{s}_i}\Big[F(\textrm{s}_i \circ {\bf x}^{(i)}; \boldsymbol{\theta}^{(F)})\Big]\Big)\Bigg)$$
- While this property no longer holds for general $\alpha$, in practice, this result holds for a composition $\vec{f'} \equiv \alpha \circ F$ and shows state-of-the-art performance in relational tasks (Moore & Neville, 2017, Hamilton et al., 2017).
Inference of models trained with $\pi$-SGD: The use of $\pi$-SGD to optimize the the original loss optimizes the new objective in Equation (9), and thus has the following implication on how outputs should be calculated at inference time:
- Assume $L$ is convex (e.g., $L$ is the L2, cross entropy, or negative log-likelihood losses), which via Jensen's inequality makes $\pi$-SGD a proper surrogate to the original Janossy objective.
- At test time we estimate the output ${\bf y}^{(i)}$ of input ${\bf x}^{(i)}$ by computing (or estimating) $$\hat{{\bf y}}^{(i)}({\bf x}^{(i)}) = E_{\textrm{s}_i}\left[ F'(\textrm{s}_i \circ {\bf x}^{(i)\star}; \boldsymbol{\theta}^{f'\star}) \right],$$ where $F' \equiv \alpha \circ F$, $\boldsymbol{\theta}^{(f')\star} \equiv (\boldsymbol{\theta}^{(F)\star},\boldsymbol{\theta}^{(\alpha)\star})$ and $\boldsymbol{\theta}^{(\alpha)\star}, \boldsymbol{\theta}^{(F)\star}$ are fixed points of the $\pi$-SGD optimization. Note that the equation is a permutation-invariant function.
Quiz¶
Regarding Projects
A) I already have a project I am working on
B) I do not have a project I am working on
Representations of Point Clouds¶
- A point cloud is an example of a set input:
- Object in $\mathbb{R}^3$ is a collection of points, represented by a subset $O \subsetneq \mathbb{R}^3$
Note that in the above example the data consists of a sequence of $N$ points, defined as $((x_1,y_1,z_1),\ldots,(x_N,y_N,z_N))$:
- The order that we draw the points is irrelevant. Thus representing the sequence should be invariant to permutations of the sequence elements.
- The sequence is permutation invariant
- The $(x,y,z)$ values can be jointly rotated around an axis and the object remains the same.
- The points are jointly rotation invariant
- The $(x,y,z)$ values can be jointly translated and the object remains the same.
- The points are jointly translation invariant
3D transformations:¶
- Transformation of an object: A single mapping $T : O \to O$ which maps the coordinates of points in the object from their original to their final configurations.
- Rigid Body (Isometric) Transformation: A mapping of each point in $O \subsetneq \mathbb{R}^3$ such that $T : \mathbb{R}^3 \to \mathbb{R}^3$ is called a rigid body transformation if it satisfies the following two properties:
- The length is preserved: $\Vert T(v) - T(u)\Vert = \Vert v - u \Vert$, for all $u,v \in \mathbb{R}^3$.
- The cross product is preserved: $T(v \times u) = T(v) \times T(u),$ for all $v, u \in \mathbb{R}^3$.
- These imply:
- It preserves the Euclidean distance between every pair of points
- Angles between vectors are preserved (inner product is preserved)
- Orthogonal vectors are transformed to orthogonal vectors
- Orientation is preserved (right-handed coordinate frames are transformed to right-handed coordinate frames)
Rotation Transformations in 3D space (SO(3))¶
The 3D rotation group, denoted SO(3), is the group of all rotations about the origin of three-dimensional Euclidean space $\mathbb{R}^{3}$ under the operation of composition.
- The group of all $3\times 3$ orthogonal matrices $T$ is denoted O(3)
- $T^{\mathrm {T} }T=T T^{\mathrm {T} }=I,$
- Orthogonal matrices preserve length of vectors, since for $\mathbf{v} \in \mathbb{R}^3,$ we have ${\mathbf{v}}^{\mathrm{T}}{\mathbf{v}}=(T{\mathbf{v}})^{\mathrm{T}}(T{\mathbf{v}})={\mathbf{v}}^{\mathrm{T}} T^{\mathrm{T}} T{\mathbf{v}}.$
- Special Orthogonal 3D group (SO(3)) is an orthogonal group such that $(\text{det} T)^2 = 1$.
- SO(3) has continuous rotations $T_\theta$, where $\theta \in [0,360)$ degrees.
- SO(3) is a Lie group (smooth/differentiable manifold)
- Every rotation can be represented uniquely by an orthogonal matrix $T$ with unit determinant.
- For instance, a counterclockwise rotation about a positive axis by angle $\theta$ is given by $$\begin{alignedat}{1}T_{(1,0,0)}(\theta )&={\begin{bmatrix}1&0&0\\0&\cos \theta &-\sin \theta \\[3pt]0&\sin \theta &\cos \theta \\[3pt]\end{bmatrix}},\\[6pt]T_{(0,1,0)}(\theta )&={\begin{bmatrix}\cos \theta &0&\sin \theta \\[3pt]0&1&0\\[3pt]-\sin \theta &0&\cos \theta \\\end{bmatrix}},\\[6pt]T_{(0,0,1)}(\theta )&={\begin{bmatrix}\cos \theta &-\sin \theta &0\\[3pt]\sin \theta &\cos \theta &0\\[3pt]0&0&1\\\end{bmatrix}}.\end{alignedat}$$
- Other rotation matrices can be obtained from the above three rotations using matrix multiplication.
Exponential Map of SO(3)¶
A matrix exponential $\exp(A)$ is defined as $$\exp(A) =\sum _{k=0}^{\infty }{1 \over k!}A^{k}.$$
The exponential map defines composition of transformations through the matrix exponential:
- Let $$L_{\mathbf {x} }=\left[{\begin{matrix}0&0&0\\0&0&-1\\0&1&0\end{matrix}}\right],\quad L_{\mathbf {y} }=\left[{\begin{matrix}0&0&1\\0&0&0\\-1&0&0\end{matrix}}\right],\quad L_{\mathbf {z} }=\left[{\begin{matrix}0&-1&0\\1&0&0\\0&0&0\end{matrix}}\right].$$
Then, convince yourself that (just look at the series definition of sine and cosine) $$T_{(0,0,1)}(\theta) =\begin{pmatrix}\cos \theta &-\sin \theta &0\\\sin \theta &\cos \theta &0\\0&0&1\end{pmatrix}=\exp(\theta L_{z}).$$
Also note that $$\exp(A+B) =\sum _{k=0}^{\infty }{1 \over k!}(A+B)^{k} = I + A + B + \frac{A^2}{2} + \frac{A B}{2} + \frac{BA}{2} + \frac{B^2}{2} + \cdots, $$ which is a composition of all transformations $A$ and $B$.
Then, for a rotation $\boldsymbol{\theta} = (\theta_x,\theta_y,\theta_z)$ is $$\begin{aligned}T_{\bf u}(\boldsymbol{\theta})&=\exp {\bigl (}\theta_x L_{\mathbf {x} } + \theta_y L_{\mathbf {y} } + \theta_z L_{\mathbf {z} }{\bigr )}\\&=\exp \left(\left[{\begin{matrix}0&-\theta_z &\theta_y \\\theta_z &0&-\theta_x \\-\theta_y &\theta_x &0\end{matrix}}\right]\right).\end{aligned}$$
3D Rigid Transformation (SE(3))¶
The group of rigid transformations in 3D space, SE(3), consider both rotations and translations:
If $T \in \text{SO}(3)$ is a rotation and ${\bf t} \in \mathbb{R}^{3\times 1}$ is a translation, then the 3D rigid transformation is $$C = \begin{bmatrix}T&{\bf t}\\{\bf 0}&1\end{bmatrix} \in \text{SE}(3). $$
Rigid transformation of points: In this matrix representation, the transformation (group action) on 3D points is: $${\bf x}^\mathrm{T}=[x,y,z,1]$$ and then $$C {\bf x} = \begin{bmatrix}T {\bf x} + {\bf t}\\1\end{bmatrix}$$
Rigid transformation of direction vectors: If ${\bf x}$ is a direction vector, we define ${\bf x}^\mathrm{T}=[x,y,z,0]$ and the translation is ignored.
Exponential Map of SE(3)¶
Let $$G_{1}=\begin{bmatrix}0&0&0&1\\0&0&0&0\\0&0&0&0\\0&0&0&0\end{bmatrix},\quad G_{2}=\begin{bmatrix}0&0&0&0\\0&0&0&1\\0&0&0&0\\0&0&0&0\end{bmatrix},\quad G_{3}=\begin{bmatrix}0&0&0&0\\0&0&0&0\\0&0&0&1\\0&0&0&0\end{bmatrix},\quad G_{4}=\begin{bmatrix}0&0&0&0\\0&0&-1&0\\0&1&0&0\\0&0&0&0\end{bmatrix}, \quad G_{5}=\begin{bmatrix}0&0&1&0\\0&0&0&0\\-1&0&0&0\\0&0&0&0\end{bmatrix}, \quad G_{6}=\begin{bmatrix}0&-1&0&0\\1&0&0&0\\0&0&0&0\\0&0&0&0\end{bmatrix}.$$
A rigid transformation that rotates around the origin by $\theta = (\theta_x,\theta_y,\theta_z)$ angles (on the x,y,z-axis, respectively) and translates by ${\bf u}=(x,y,z)$ is then $$ T_{{\bf u},\theta} = \exp(x G_1 + y G_2+ z G_3 + \theta_x G_4 + \theta_y G_5 + \theta_z G_6 ). $$
Similarity Transformations in 3D space (Sim(3))¶
- Similarity transformations are combinations of rigid transformation and scaling.
- The group of similarity transforms in 3D space, Sim(3), has a nearly identical representation to SE(3), with an additional scale factor:
If $T \in \text{SO}(3)$ is a rotation, ${\bf t} \in \mathbb{R}^{3\times 1}$ is a translation, and $s \in \mathbb{R}$ is a scaling, then the 3D similarity transformation is $$S = \begin{bmatrix}T&{\bf t}\\{\bf 0}&s^{-1}\end{bmatrix} \in \text{Sim}(3). $$
Similarity transformation of points: In this matrix representation, the transformation (group action) on 3D points is: $${\bf x}^\mathrm{T}=[x,y,z,1]$$ and then $$S {\bf x} = \begin{bmatrix}T {\bf x} + {\bf t}\\s^{-1}\end{bmatrix} \cong \begin{bmatrix}s (T {\bf x} + {\bf t})\\1\end{bmatrix},$$ where $\cong$ represent congruent angles and segments, which have the same length and angles.
Lie group¶
Let $G$ be a group on 3D point clouds (one among SO(3), SE(3), Sim(3)). Those are also called Lie Groups.
We have seen that any group element $g \in G$ can be written in terms of the exponential: $$ \forall g \in G: \quad \quad g = \exp{\Big(\sum_{i=1}^D \alpha_i A_i\Big)}, $$
where $\alpha_i \in \mathbb{R}$, $\forall i \in \{1,..D\}$, and $\{A_i\}_{i=1}^D$ are the generators (e.g., $L_{\bf x}$, $L_{\bf y}$, $L_{\bf z}$ in SO(3)).
The generators $\{A_i\}_{i=1}^D$ are the basis of a vector space called Lie algebra $\mathfrak{g}$.
A group element is most relevant in how it acts as a transformation on a input.
A group representation $$\rho: G \rightarrow \text{GL}(m)$$ associates every group element $g$ to an invertible matrix $\rho(g) \in \mathbb{R}^{m \times m}$ that acts on $\mathbb{R}^{m}$.
The representaton satisfies $\forall g_1, g_2 \in G$, $\rho(g_1 g_2)= \rho(g_1) \rho(g_2)$ and therefore also $\rho(g_1^{-1}) = \rho(g_1)^{-1}$.
A group representation describes how a group transformation acts on $\mathbb{R}^m$.
Therefore every group has multiple representations, each describing transformations on some vector space by invertible linear maps.
Lie algebra¶
Mirroring the group representations, Lie groups have an associated representation of their Lie algebra.
A Lie algebra representation $d\rho: \mathfrak{g} \to \mathfrak{gl}(m)$ is a linear map from the Lie algebra to ${m\times m}$ matrices.
An important result in Lie Theory relates the representation of a Lie Group to the representation of its Lie Algebra $$ \begin{equation}\label{eq:lie_correspondance} \forall A \in \mathfrak{g}: \quad \rho(e^A) = e^{d\rho(A)} \end{equation} $$
G-Equivariant Layers¶
We want to characterize all equivariant linear layers $W\in \mathbb{R}^{N_2\times N_1}$ that map from one vector space $V_1$ with representation $\rho_1$ to another vector space $V_2$ with representation $\rho_2$ for a matrix group $G$.
Being equivariant to every transformation in the group means that transforming the input $x \in V_1$ is the same as transforming the output $W x \in V_2$. $$\begin{equation}\tag{10} \forall x \in V_1 \quad \forall g \in G: \quad \quad \rho_2(g) W x = W \rho_1(g) x. \end{equation}$$
Since true for all $x$, we have $$\rho_2(g)W\rho_1(g)^{-1}=W,$$ or more abstractly: $$\begin{equation}\tag{11} \label{eq:kro} \forall g\in G:\quad \rho_2(g)\otimes \rho_1(g^{-1})^\top \mathrm{vec}(W)=\mathrm{vec}(W),\end{equation}$$ where $\mathrm{vec}$ flattens the matrix into a vector and $\otimes$ on matrices is the Kronecker product.
Let's denote $$\rho(g) = \rho_2(g)\otimes \rho_1(g^{-1})^\top,$$ which is a representation of how $g$ acts on matrices mapping from $V_1\to V_2$.
Therefore, rewriting using $\rho(g)$ and using $v = \mathrm{vec}(W)$ we have $$\begin{equation}\tag{12} \forall g\in G:\quad \rho(g) v = v . \end{equation}$$
G-Equivariant Layers conditions¶
Since we have said $$ \forall g \in G: \quad \quad g = \exp{\Big(\sum_{i=1}^D \alpha_i A_i\Big)}, $$ Equation (12) (that is $\forall g\in G: \rho(g) v = v$) becomes $$ \tag{13} \forall g\in G:\quad \rho\Big(\exp{\Big(\sum_{i=1}^D \alpha_i A_i\Big)}\Big) v = v. $$
Which we can rewrite using $$ \forall A \in \mathfrak{g}: \quad \rho(e^A) = e^{d\rho(A)}$$ as $$ \forall \alpha_i: \quad \quad \exp{\Big(\sum_{i=1}^D \alpha_i d\rho(A_i)\Big)}v = v $$
Note that $d\rho(A_i)$ are the called infinitesimal generators.
Taking the derivative with respect to $\alpha_i$ at $\alpha = 0$ we get a constraint for each infinitesimal generator: $$\forall i \in \{1, .. D\}: \quad \quad d\rho(A_i) v = 0. $$
These constrains represent a necessary and sufficient condition (Finzi et al., 2021) and thus characterize all solutions (i.e. all G-equivariant layers).
G-Equivariant Layers solutions¶
We can collect all the $D$ constrains into a single matrix $C$, which we can break down into its nullspace spanned by the columns of $Q \in \mathbb{R}^{m \times r}$ and orthogonal complement $P \in \mathbb{R}^{m \times (m-r)}$ $$ C v = \begin{bmatrix} d\rho(A_1) \\ d\rho(A_2) \\ \vdots\\ d\rho(A_D) \end{bmatrix} v = U \begin{bmatrix}\Sigma & 0 \\ 0 & 0 \\ \end{bmatrix} \begin{bmatrix} P^T \\ Q^T \\ \end{bmatrix} v = 0 $$
All symmetric solutions for $v$ must lie in the nullspace of $C$, that is $$ v = Q \beta $$
for any coefficients $\beta \in \mathbb{R}^{r \times 1}$.
This means that if we consider weights $W$ such that $$\text{vec}(W) = Q \beta$$ and only learn the coefficients $\beta$, then $W$ is $G$-equivariant, since by construction $$\rho_2(g) W x = W \rho_1(g) x , \qquad \forall x \in V_1 \: , \: \forall g \in G.$$ For more details, refer to our lecture on G-invariant neural networks.
Invariant and equivariant functions¶
We have seen a practical method to obtain equivariant layers $W$ (Finzi et al., 2021).
Q: Can arbitrary functions $\phi:V_1 \rightarrow \mathbb{R}$, $\Phi:V_1 \rightarrow V_2$, where $V_1,V_2$ are some vector spaces, be made respectively invariant and equivariant?
A: Yes, arbitrary functions can be made invariant or equivariant by averaging over the group as we have seen in Murphy et al 2019: $$\begin{equation} \tag{14} \psi(X) = \frac{1}{|G|}\sum_{g\in G} \phi(\rho_1(g)X), \quad \Psi(X) = \frac{1}{|G|}\sum_{g\in G}\rho_2(g)^{-1} \Phi(\rho_1(g)X) \end{equation}$$ are $G$-invariant and equivariant, respectively.
The challenge is that when the cardinality of $G$ is large or infinite (e.g., continuous groups such as rotations), then exact averaging is intractable.
In such cases, we can approximate the sum via heuristics or Monte Carlo (MC), thereby sacrificing the exact invariance/equivariance property for computational efficiency.
Puny et al., 2022, propose to replace the group average in Equation (14) with an average over a carefully selected subset $\mathcal{F}(X)\subset G$ while retaining both exact invariance/equivariance and expressive power.
Equivariant frame¶
$\mathcal{F}(X)\subset G$ is called a frame, and it is defined as a set valued function $\mathcal{F}:V_1 \rightarrow 2^{G} \setminus \emptyset$.
A frame is $G$-equivariant if $$\begin{equation}\tag{15} \mathcal{F}(\rho_1(g)X)= g \mathcal{F}(X), \quad \forall X\in V_1,\ g\in G,\end{equation}$$ where $g\mathcal{F}(X)=\{g h \ \vert \ h\in \mathcal{F}(X)\}$, and the equality should be understood as equality of sets.
Frame averaging (Reynolds operator)¶
How are equivariant frames useful?
Consider a scenario where an equivariant frame is easy to compute, and its cardinality, $|\mathcal{F}(X)|$, is not too large. Then averaging over the frame, denoted ${\left \langle \cdot \right \rangle}_\mathcal{F}$ is defined by
$$\begin{align} \tag{16} \label{e:inv} {\left \langle \phi \right \rangle}_\mathcal{F}(X) &= \frac{1}{|\mathcal{F}(X)|}\sum_{g\in \mathcal{F}(X)} \phi(\rho_1(g) X) \\ \tag{17} \label{e:equi} {\left \langle \Phi \right \rangle}_\mathcal{F}(X) &= \frac{1}{|\mathcal{F}(X)|}\sum_{g \in \mathcal{F}(X)} \rho_2(g)^{-1} \Phi(\rho_1(g)X) \end{align} $$
Theorem 1 (Puny et al., 2022) Let $\mathcal{F}$ be a $G$-equivariant frame, and $\phi:V_1\rightarrow\mathbb{R}$, $\Phi:V_1\rightarrow V_2$ some functions. Then, ${\left \langle \phi \right \rangle}_\mathcal{F}$ is $G$-invariant, while ${\left \langle \Phi \right \rangle}_\mathcal{F}$ is $G$-equivariant.
Therefore we can replace the group averaging operator with an averaging operator over a small subset of the group elements (a frame). Averaging over a frame guarantees exact invariance or equivariance while often being simpler to compute.
Puny et al., 2022 define the frames and instatiate the frame averaging framework for several groups.
References¶
(Murphy et al., 2019) Ryan L. Murphy, Balasubramaniam Srinivasan, Vinayak Rao, and Bruno Ribeiro, "Janossy Pooling: Learning Deep Permutation-invariant Functions for Variable-size Inputs", ICLR 2019.
(Sabour et al., 2017) Sara Sabour, Nicholas Frosst, and Geoffrey E. Hinton. "Dynamic routing between capsules." NeurIPS 2017.
(Bahdanau et al., 2015) Dzmitry Bahdanau, Kyunghyun Cho, and Yoshua Bengio. "Neural machine translation by jointly learning to align and translate." ICLR 2015.
(Zaheer et al., 2017) Manzil Zaheer, Satwik Kottur, Siamak Ravanbakhsh, Barnabas Poczos, Ruslan Salakhutdinov, and Alexander Smola. "Deep sets". NeurIPS 2017.
(Vinyals et al., 2016) Oriol Vinyals, Samy Bengio, and Manjunath Kudlur. Order Matters: Sequence to Sequence for Sets. ICLR, 2016
(Lee et al., 2019) Lee, Juho, Yoonho Lee, Jungtaek Kim, Adam R. Kosiorek, Seungjin Choi, and Yee Whye Teh. "Set transformer: A framework for attention-based permutation-invariant neural networks." ICML 2019.
(Finzi et al., 2021) Marc Finzi, Max Welling, and Andrew Gordon Wilson. "A Practical Method for Constructing Equivariant Multilayer Perceptrons for Arbitrary Matrix Groups". ICML 2021.
(Puny et al., 2022) Omri Puny, Matan Atzmon, Heli Ben-Hamu, Edward J. Smith, Ishan Misra, Aditya Grover, and Yaron Lipman. "Frame Averaging for Invariant and Equivariant Network Design". ICLR 2022.