<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Posts on Derek Lim</title>
		<link>https://cptq.github.io/posts/</link>
		<description>Recent content in Posts on Derek Lim</description>
		<generator>Hugo -- gohugo.io</generator>
		<language>en-us</language>
		<copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright>
		<lastBuildDate>Sun, 06 Mar 2022 00:00:00 +0000</lastBuildDate>
		<atom:link href="https://cptq.github.io/posts/index.xml" rel="self" type="application/rss+xml" />
		
		<item>
			<title>Universal Invariant Networks Through a Nice Commutative Diagram</title>
			<link>https://cptq.github.io/posts/universal_invariant/</link>
			<pubDate>Sun, 06 Mar 2022 00:00:00 +0000</pubDate>
			
			<guid>https://cptq.github.io/posts/universal_invariant/</guid>
			<description>\(\newcommand{\RR}{\mathbb{R}}\) \(\newcommand{\NN}{\mathbb{N}}\)
\(\newcommand{\mc}{\mathcal}\)
When working on a project with group invariant neural networks, I found myself repeatedly using essentially the same steps to prove many different results on universality of invariant networks. I eventually realized that these steps could be captured in the following commutative diagram:
  What’s more: this commutative diagram helps simplify and unify previous proofs of results in the study of invariant neural networks. Plus, it gives a blueprint for developing novel invariant neural network architectures.</description>
			<content type="html"><![CDATA[<p><span class="math inline">\(\newcommand{\RR}{\mathbb{R}}\)</span> <span class="math inline">\(\newcommand{\NN}{\mathbb{N}}\)</span><br />
<span class="math inline">\(\newcommand{\mc}{\mathcal}\)</span><br />
When working on a project with group invariant neural networks, I found myself repeatedly using essentially the same steps to prove many different results on universality of invariant networks. I eventually realized that these steps could be captured in the following commutative diagram:</p>
<figure>
<img src="commutative_diagram.png" width=75%>
</figure>
<p>What’s more: this commutative diagram helps simplify and unify previous proofs of results in the study of invariant neural networks. Plus, it gives a blueprint for developing novel invariant neural network architectures.</p>
<p>In this post, I will explain what this all means. This should be of interest to people who like invariant neural networks, or are curious about applications of some basic topology, algebra, and geometry to the study of neural networks.</p>
<h2 id="definitions">Definitions</h2>
<p>First, an invariant neural network is a neural network <span class="math inline">\(f\)</span> such that certain transformations of its inputs do not affect its outputs. We denote the set of transformations as <span class="math inline">\(G\)</span>, and assume that <span class="math inline">\(G\)</span> is what is known as a <a href="https://en.wikipedia.org/wiki/Group_(mathematics)">group</a> in algebra. Then a neural network <span class="math inline">\(f\)</span> that is <span class="math inline">\(G\)</span>-invariant satisfies <span class="math inline">\(f(gx) = f(x)\)</span> for any <span class="math inline">\(g \in G\)</span>.</p>
<figure>
<img src="duck_translation_inv.png" width=60%>
<figcaption style="font-size:80%">
A neural network should classify both images as having a duck. (Duck photo by <a href="https://unsplash.com/@lozt?utm_source=unsplash&utm_medium=referral&utm_content=creditcopytext">Hoover Tung</a> on <a href="https://unsplash.com/s/photos/duck?utm_source=unsplash&utm_medium=referral&utm_content=creditcopytext">Unsplash</a>)
</figcaption>
</figure>
<p>For instance, if <span class="math inline">\(f\)</span> is an image classifier, then certain translations of the input images should not change the output of <span class="math inline">\(f\)</span>; a picture <span class="math inline">\(x\)</span> with a duck in the bottom right corner and a picture <span class="math inline">\(gx\)</span> with the same duck in the top left corner should both be classified as having a duck. Thus, <span class="math inline">\(f\)</span> should approximately be invariant to the group <span class="math inline">\(G\)</span> of translations. Convolutional neural networks for image classification are approximately invariant to translations.</p>
<p>We say that a network is <em>universal</em> if it can compute all continuous functions that we care about. In particular, we say that a <span class="math inline">\(G\)</span>-invariant network architecture is universal if it can express any continuous <span class="math inline">\(G\)</span>-invariant function.</p>
<p>In the commutative diagram above, <span class="math inline">\(\mathcal X\)</span> is the domain that our input data lies on. We will assume <span class="math inline">\(\mc X \subseteq \RR^D\)</span> is embedded in some Euclidean space of dimension <span class="math inline">\(D\)</span>. The <em>quotient space</em> <span class="math inline">\(\mathcal X / G\)</span> is the set of all equivalence classes of inputs under the transformations of <span class="math inline">\(G\)</span>. In other words, it is the space <span class="math inline">\(\mathcal X\)</span>, but where <span class="math inline">\(gx\)</span> is viewed as equal to <span class="math inline">\(x\)</span> for any <span class="math inline">\(g \in G\)</span>. The <em>quotient map</em> <span class="math inline">\(\pi: \mathcal{X} \to \mathcal{X}/G\)</span> is the map that sends an <span class="math inline">\(x \in \mathcal{X}\)</span> to the equivalence class of all inputs that it can be transformed to, <span class="math inline">\(\pi(x) = \{ gx : g \in G\}\)</span>. Thus, <span class="math inline">\(\pi\)</span> is <span class="math inline">\(G\)</span>-invariant.</p>
<details>
<summary>
Mathematical notes
</summary>
<p>
<p>We will generally assume <span class="math inline">\(G\)</span> is a finite or compact matrix Lie group. A lot can be said when <span class="math inline">\(\mathcal X\)</span> is just a topological space, though we will assume <span class="math inline">\(\mc X\)</span> is embedded in some Euclidean space so that we can process our data with standard neural networks. A more detailed discussion of assumptions can be found in the appendix of our paper [Lim et al. 22], but the topological assumptions are generally very mild.</p>
</p>
</details>
<h2 id="commutative-diagram">Commutative Diagram</h2>
<p>A <a href="https://en.wikipedia.org/wiki/Commutative_diagram">commutative diagram</a> is a diagram where you can take any path through arrows and arrive at the same result. Let <span class="math inline">\(f: \mathcal{X} \to \mathbb{R}^s\)</span> be any <span class="math inline">\(G\)</span>-invariant continuous function. As an example, the above commutative diagram says that there is an <span class="math inline">\(\tilde f\)</span> such that <span class="math inline">\(f = \tilde f \circ \pi\)</span>, and also an invertible <span class="math inline">\(\psi\)</span> such that <span class="math inline">\(\tilde f \circ \psi^{-1} \circ \psi \circ \pi = f\)</span>.</p>
<figure>
<img src="quotient_cd.png" width=30%>
</figure>
<p>First, consider the subdiagram shown here. This captures the so-called universal property of quotient spaces; for any continuous <span class="math inline">\(G\)</span>-invariant function <span class="math inline">\(f: \mc X \to \RR^s\)</span>, there exists a unique continuous function <span class="math inline">\(\tilde f: \mc X / G \to \RR^s\)</span> on the quotient space such that <span class="math inline">\(f = \tilde f \circ \pi\)</span>. However, this does directly not help us to parameterize <span class="math inline">\(G\)</span>-invariant functions <span class="math inline">\(f\)</span>, as the quotient space <span class="math inline">\(\mc X / G\)</span> that the <span class="math inline">\(\tilde f\)</span> are defined on may look rather non-Euclidean (recall that the quotient space consists of equivalence classes of data points), so we may not know how to parameterize functions on such a domain.</p>
<p>Thus, we will want a topological embedding <span class="math inline">\(\psi : \mc X / G \to \mc Z \subseteq \RR^a\)</span> of the quotient space into some Euclidean space <span class="math inline">\(\RR^a\)</span>, which means <span class="math inline">\(\psi\)</span> is a continuous bijection with continuous inverse <span class="math inline">\(\psi^{-1}\)</span>. This brings us closer to parameterizing <span class="math inline">\(G\)</span>-invariant neural networks. The two functions denoted with dashed red arrows in the commutative diagram are parameterized by neural networks: <span class="math display">\[
\begin{align*}
\phi &amp; = \psi \circ \pi : \mc X \subseteq \RR^D \to \mc Z \subseteq \RR^a \\
\rho &amp; = \tilde f \circ \psi^{-1}: \mc Z \subseteq \RR^a \to \RR^s.
\end{align*}
\]</span> Of course, <span class="math inline">\(f = \tilde f \circ \pi = \tilde f \circ \psi^{-1} \circ \psi \circ \pi = \rho \circ \phi\)</span>. Note that <span class="math inline">\(\rho\)</span> and <span class="math inline">\(\phi\)</span> are compositions of continuous functions, so they are both continuous. Also, their domains are Euclidean spaces, so we can approximate them with standard neural network operations. <span class="math inline">\(\rho\)</span> can be parameterized by an unconstrained neural network. However, <span class="math inline">\(\phi\)</span> is required to be <span class="math inline">\(G\)</span>-invariant, so it seems that we have not made progress, as our original goal was to parameterize <span class="math inline">\(G\)</span>-invariant functions by neural networks. The next section shows how we can utilize structure in <span class="math inline">\(\phi = \psi \circ \pi\)</span> to parameterize <span class="math inline">\(G\)</span>-invariant neural nets.</p>
<h2 id="finding-a-quotient-space-embedding-with-structure">Finding a quotient space embedding with structure</h2>
<p>To parameterize the <span class="math inline">\(G\)</span>-invariant <span class="math inline">\(\phi = \psi \circ \pi\)</span>, we need to find some structure in <span class="math inline">\(\psi \circ \pi\)</span> that handles the <span class="math inline">\(G\)</span>-invariance. For instance, for processing sets we want permutation invariance, and we can show that in this case for input <span class="math inline">\(x \in \RR^n\)</span> (which represents a set of <span class="math inline">\(n\)</span> real numbers) we may write <span class="math inline">\(\phi(x) = \sum_{i=1}^n \varphi(x_{i})\)</span> for some suitable <span class="math inline">\(\varphi\)</span> that does not have the <span class="math inline">\(G\)</span>-invariance constraint. Thus, we may then parameterize <span class="math inline">\(\varphi\)</span> with a standard neural network. There are different ways to find such structure in <span class="math inline">\(\phi\)</span> or the quotient space embedding.</p>
<p>One way to find structure in <span class="math inline">\(\phi\)</span> is to find structure in a generating set of <span class="math inline">\(G\)</span>-invariant polynomials. A generating set <span class="math inline">\(p_{1}, \ldots, p_{l}\)</span> of the <span class="math inline">\(G\)</span>-invariant polynomials is a set of <span class="math inline">\(G\)</span>-invariant polynomials such that every other <span class="math inline">\(G\)</span>-invariant polynomial <span class="math inline">\(p\)</span> can be written as a polynomial in <span class="math inline">\(p_{1}, \ldots, p_{l}\)</span>. Lemma 11.13 of [González and de Salas 03] shows that the map <span class="math inline">\(h: \mc X \to \RR^l\)</span> given by <span class="math inline">\(h(x) = (p_{1}(x), \ldots, p_{l}(x))\)</span> induces a topological embedding <span class="math inline">\(\tilde h: \mc X / G \to h(\mc X)\)</span> such that <span class="math inline">\(h = \tilde h \circ \pi\)</span>. Thus, choosing <span class="math inline">\(\psi = \tilde h\)</span> as our topological embedding above, we have that <span class="math inline">\(\phi(x) = h(x)\)</span>, so <span class="math inline">\(\phi\)</span> contains all the structure that <span class="math inline">\(h\)</span> does. This is why for the permutation invariant case, we can choose <span class="math inline">\(\phi(x) = \sum_{i=1}^n \varphi(x_{i})\)</span>; as the polynomials of the form <span class="math inline">\(p_{k}(x) = \sum_{i=1}^n x_{i}^k\)</span> for <span class="math inline">\(k=1, \ldots, n\)</span> are generating polynomials of the permutation invariant polynomials, we can write <span class="math display">\[\phi(x) = h(x) = (p_{1}(x), \ldots, p_{n}(x)) = \sum_{i=1}^n (x_{i}, \ldots, x_{i}^n),\]</span> so letting <span class="math inline">\(\varphi(x_{i}) = (x_{i}, \ldots, x_{i}^n)\)</span>, we have a nice sum decomposition structure on <span class="math inline">\(\phi\)</span>.</p>
<p>While this use of the <span class="math inline">\(G\)</span>-invariant polynomials is theoretically general, it can be difficult to use in practice besides for particular choices of <span class="math inline">\(G\)</span>. This is because generators of <span class="math inline">\(G\)</span>-invariant polynomials can be difficult to find for different <span class="math inline">\(G\)</span>, and they can take complicated forms with high degree polynomials (of up to degree <span class="math inline">\(|G|\)</span> by Noether’s bound <a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>). Thankfully, efficiently-computable generators are well known for two of the cases we consider below: when the groups are for permutation symmetries or for rotation/reflection symmetries.</p>
<h2 id="parameterizing-with-neural-networks">Parameterizing with neural networks</h2>
<p>Suppose that the data domain <span class="math inline">\(\mc X\)</span> is <a href="https://en.wikipedia.org/wiki/Compact_space">compact</a>, and that we have some structure such that <span class="math inline">\(\phi\)</span> can be universally approximated by neural networks. Then <span class="math inline">\(\rho\)</span> and <span class="math inline">\(\phi\)</span> can be universally approximated by a neural network.</p>
<p>This is due to an application of standard <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem">universal approximation results</a>, which say that neural networks can universally approximate continuous functions with domains that are compact subsets of some Euclidean space. If <span class="math inline">\(\mc X\)</span> is compact, then one can show that <span class="math inline">\(\mc X / G\)</span> is compact and thus <span class="math inline">\(\mc Z\)</span> is compact. Hence, <span class="math inline">\(\phi: \mc X \to \mc Z\)</span> and <span class="math inline">\(\rho: \mc Z \to \RR^s\)</span> are continuous functions on compact subsets of Euclidean spaces, so they are amenable to approximation by neural networks.</p>
<h2 id="application-1-deep-sets">Application 1: Deep Sets</h2>
<p>We now give more details on the application of this commutative diagram to neural networks on sets. If we represent a set of <span class="math inline">\(n\)</span> elements as a vector <span class="math inline">\(x \in \mathbb{R}^n\)</span>, then we want any function on the set to not depend on the order of the elements. Thus, letting <span class="math inline">\(G = \mathbb{S}_n\)</span> be the group of permutations on <span class="math inline">\(n\)</span> elements, we want a function <span class="math inline">\(f\)</span> on sets to be invariant to permutations <span class="math inline">\(f(g x) = f(x)\)</span>, where <span class="math inline">\(gx = [x_{g(1)}, \ldots, x_{g(n)}]\)</span> permutes the entries of <span class="math inline">\(x\)</span> by the permutation <span class="math inline">\(g\)</span>.</p>
<p>The invariant DeepSets [Zaheer et al. 17] architecture parameterizes permutation invariant functions as <span class="math display">\[ f(x) \approx \rho_\theta\left(\sum_{i=1}^n \phi_\theta(x_{i}) \right),\]</span> where <span class="math inline">\(\rho_\theta\)</span> and <span class="math inline">\(\phi_\theta\)</span> are neural networks. Their proof that the architecture is universal uses a few computations and facts about symmetric polynomials (see their Appendix A.2).</p>
<p>We can instead prove universality using the above commutative diagram as follows. We take our generating set of <span class="math inline">\(G\)</span>-invariant polynomials as the <a href="https://en.wikipedia.org/wiki/Power_sum_symmetric_polynomial">power sum symmetric polynomials</a>: <span class="math inline">\(p_{k}(x) = \sum_{i=1}^n x_{i}^k\)</span> for <span class="math inline">\(k=1, \ldots, n\)</span>. Thus, we know that in the above commutative diagram, we can write <span class="math display">\[\phi = \psi \circ \pi(x) = \begin{bmatrix}\sum_{i=1}^n x_{i} &amp; \ldots &amp; \sum_{i=1}^n x_{i}^n\end{bmatrix} = \sum_{i=1}^n \begin{bmatrix}x_{i} &amp; \ldots &amp; x_{i}^n\end{bmatrix}.\]</span></p>
<p>Hence, in the DeepSets neural architectures, we can approximate <span class="math inline">\(\rho_{\theta} \approx \rho\)</span>, and <span class="math inline">\(\phi_\theta(y) \approx \begin{bmatrix} y &amp; \ldots &amp; y^n \end{bmatrix}\)</span>, which standard feedforward networks can do, so DeepSets is universal.</p>
<p>We note that this connection to the power sum symmetric polynomials as an embedding of the quotient space is also used in [Finkelshtein et al. 22], see their Appendix C.</p>
<h2 id="application-2-rotation-and-reflection-invariance">Application 2: Rotation and Reflection Invariance</h2>
<p>When dealing with certain types of point clouds of points in <span class="math inline">\(\mathbb{R}^d\)</span>, we may want to be invariant to rotations and reflections, which form the group <span class="math inline">\(G = O(d)\)</span> of orthogonal <span class="math inline">\(d \times d\)</span> matrices. [Villar et al. 21] proposed to use some classical results in invariant theory to parameterize <span class="math inline">\(O(d)\)</span>-invariant neural networks. For learning an <span class="math inline">\(O(d)\)</span> invariant function <span class="math inline">\(f: \RR^{n \times d} \to \RR^s\)</span> on <span class="math inline">\(n\)</span> points that satisfies <span class="math inline">\(f(Q v_{1}, \ldots, Qv_{n}) = f(v_{1}, \ldots, v_{n})\)</span> for any <span class="math inline">\(Q \in O(d)\)</span>, they parameterize <span class="math display">\[ f(v_{1}, \ldots, v_{n}) \approx g_{\theta}(V^\top V) = g_{\theta}((v_{i}^\top v_{j})_{i,j=1, \ldots, n}). \]</span> In other words, <span class="math inline">\(g_\theta\)</span> is a neural network acting on all inner products of two points <span class="math inline">\(v_{i}\)</span> and <span class="math inline">\(v_{j}\)</span>. [Villar et al. 21] uses an argument based on the Cholesky decomposition to say that allowing <span class="math inline">\(g_\theta\)</span> to be any arbitrary function gives universality.</p>
<p>To see that we only need continuous <span class="math inline">\(g_\theta\)</span> and that we can thus use a neural network as <span class="math inline">\(g_\theta\)</span>, we note that the First Fundamental Theorem of <span class="math inline">\(O(d)\)</span> from invariant theory says that the inner product polynomials <span class="math inline">\(p_{ij}(v_{1}, \ldots, v_{n}) = v_{i}^\top v_{j}\)</span> are generators of the <span class="math inline">\(O(d)\)</span>-invariant polynomials. Thus, in the above commutative diagram, we can write <span class="math display">\[\phi(x) = \psi \circ \pi(x) = \begin{bmatrix} v_{i}^\top v_{j} \end{bmatrix}_{i,j=1, \ldots, n}.\]</span> So the functions of the form <span class="math inline">\(\rho(\begin{bmatrix} v_{i}^\top v_{j} \end{bmatrix}_{i,j=1, \ldots, n})\)</span> are universal. As <span class="math inline">\(\rho\)</span> is unconstrained and continuous, we can approximate it by a neural network <span class="math inline">\(\rho_\theta \approx \rho\)</span>, so the networks of the form <span class="math inline">\(\rho_\theta( \begin{bmatrix} v_{i}^\top v_{j} \end{bmatrix}_{i,j=1, \ldots, n})\)</span> are universal.</p>
<h2 id="application-3-direct-products-and-eigenvectors">Application 3: Direct Products and Eigenvectors</h2>
<p>Our recent paper [Lim et al. 22] inspired this blog post, as I discovered this common pattern underlying the commutative diagram through working on this project. In the paper, we develop universal architectures for a large class of invariances coming from direct products. If <span class="math inline">\(G_i\)</span> is a group acting on <span class="math inline">\(\mc X_i\)</span> for <span class="math inline">\(i=1, \ldots, k\)</span>, then the direct product <span class="math inline">\(G_1 \times \ldots \times G_k\)</span> is the group of tuples <span class="math inline">\((g_1, \ldots, g_k)\)</span> which acts on <span class="math inline">\(\mc X_1 \times \ldots \times \mc X_k\)</span> as <span class="math inline">\((g_1, \ldots, g_k) (x_1, \ldots, x_k) = (g_1 x_1, \ldots, g_k x_k)\)</span>. In our Theorem 1 (the decomposition theorem), we show that a continuous function <span class="math inline">\(f(x_1, \ldots, x_k)\)</span> that is invariant to the large group <span class="math inline">\(G = G_1 \times \ldots \times G_k\)</span> can be parameterized as <span class="math display">\[f(x_1, \ldots, x_k) \approx \rho_\theta\left(\phi_{1,\theta}(x_{1}), \ldots, \phi_{k,\theta}(x_{k}) \right),\]</span> where <span class="math inline">\(\phi_{i,\theta}\)</span> only needs to be invariant to the constituent smaller group <span class="math inline">\(G_{i}\)</span>, and <span class="math inline">\(\rho\)</span> is unconstrained. Further, we can take <span class="math inline">\(\phi_{i,\theta} = \phi_{j,\theta}\)</span> if <span class="math inline">\(\mc X_{i} = \mc X_{j}\)</span> and <span class="math inline">\(G_{i} = G_{j}\)</span>. We prove this theorem precisely through the same-old commutative diagram, where we show that the <span class="math inline">\(\phi\)</span> map has a product structure <span class="math display">\[\phi(x_{1}, \ldots, x_{k}) = (\phi_{1}(x_{1}), \ldots, \phi_{k}(x_{k})),\]</span> for some <span class="math inline">\(G_{i}\)</span>-invariant functions <span class="math inline">\(\phi_{i}\)</span> on the <span class="math inline">\(\mc X_{i}\)</span>.</p>
<p>We proved this result to apply it to a specific invariance arising from learning functions on eigenvectors. For a matrix <span class="math inline">\(A \in \RR^{n \times n}\)</span> with an eigenvector <span class="math inline">\(v \in \RR^n\)</span> of eigenvalue <span class="math inline">\(\lambda\)</span>, note that <span class="math inline">\(-v\)</span> is also an eigenvector of <span class="math inline">\(A\)</span> with the same eigenvalue. A numerical eigenvector algorithm could have returned either <span class="math inline">\(v\)</span> or <span class="math inline">\(-v\)</span>, so we want a function <span class="math inline">\(f\)</span> on eigenvectors <span class="math inline">\(v_{1}, \ldots, v_{k}\)</span> to be invariant to sign flips: <span class="math display">\[f(\pm v_{1}, \ldots, \pm v_{k}) = f(v_{1}, \ldots, v_{k}).\]</span> There are in fact more invariances desired if there is a higher dimensional eigenspace, but we will not cover those here (see [Lim et al. 22] for more on this). This sign invariance is precisely invariance to the action of the group <span class="math inline">\(G = \{1, -1\}^k = \{1, -1\} \times \ldots \times \{1, -1\}\)</span>. Thus, our theorem says that as long as we can parameterize a universal network that is <span class="math inline">\(\{1, -1\}\)</span> invariant, then we can use that to make a <span class="math inline">\(\{1, -1\}^k\)</span> invariant function. Invariance to <span class="math inline">\(\{1, -1\}\)</span> just means that <span class="math inline">\(h(-x) = h(x)\)</span>, so such a function is an even function, which can be simply parameterized as <span class="math inline">\(h(x) = \varphi(x) + \varphi(-x)\)</span> for some unconstrained <span class="math inline">\(\varphi\)</span>. Thus, we can parameterize sign invariant functions on <span class="math inline">\(k\)</span> vectors as <span class="math display">\[f(v_{1}, \ldots, v_{k}) \approx \rho_\theta\left( \phi_\theta(v_{1}) + \phi_\theta(-v_{1}), \  \ldots, \  \phi_{\theta}(v_{k}) + \phi_{\theta}(-v_{k})\right).\]</span> Note that we can use the same <span class="math inline">\(\phi_\theta\)</span> for each vector <span class="math inline">\(v_{i}\)</span> by our decomposition theorem, as <span class="math inline">\(\mc X_{i} = \mc X_{j}\)</span> and <span class="math inline">\(G_{i} = G_{j}\)</span> for each <span class="math inline">\(i\)</span> and <span class="math inline">\(j\)</span>.</p>
<h2 id="limitations">Limitations</h2>
<p>While I think the strategy based on this commutative diagram may be useful for developing new invariant architectures (especially those that come from direct products of groups), this is far from solving every problem in invariant machine learning. For one, many invariant networks are built from equivariant layers followed by a final invariant pooling. Using equivariance has been shown to significantly improve performance in certain applications (e.g. note the success of networks with convolutional layers that are approximately translation equivariant, or see Figure 7 of [Batzner et al. 22] for an example in molecular dynamics). Also, this is mostly concerned with developing universal architectures, but universality is not sufficient for good performance. Inductive biases can greatly improve the performance of invariant architectures, as can be seen by the success of adding attention modules to Set architectures [Lee et al. 19] [Kim et al. 21] or as we saw by adding message passing to our SignNet architecture for eigenvectors of graph operators [Lim et al. 22]. Even if we do desire universality, this commutative diagram approach may not be computationally useful, as there may be no nice quotient space embedding with structure that we can leverage.</p>
<h2 id="references">References</h2>
<p>[Zaheer et al. 17] Deep Sets.<br />
[Villar et al. 21] Scalars are universal: Equivariant machine learning, structured like classical physics.<br />
[Lim et al. 22] Sign and Basis Invariant Networks for Spectral Graph Representation Learning.<br />
[Finkelshtein et al. 22] A Simple and Universal Rotation Equivariant Point-cloud Network.<br />
[Batzner et al. 21] E(3)-Equivariant Graph Neural Networks for Data-Efficient and Accurate Interatomic Potentials.<br />
[Lee et al. 19] Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks.<br />
[González and de Salas 03] C∞-differentiable spaces. Springer.<br />
[Kim et al. 21] Transformers Generalize DeepSets and Can be Extended to Graphs and Hypergraphs.<br />
[Kraft and Procesi 96]. Classical Invariant Theory.</p>
<section class="footnotes" role="doc-endnotes">
<hr />
<ol>
<li id="fn1" role="doc-endnote"><p>Noether’s bound says that the <span class="math inline">\(G\)</span>-invariant polynomials of degree at most <span class="math inline">\(|G|\)</span> generate all <span class="math inline">\(G\)</span>-invariant polynomials. See e.g. [Kraft and Procesi 96] Theorem 2.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section>
]]></content>
		</item>
		
		<item>
			<title>Flags Ranked by Matrix Rank</title>
			<link>https://cptq.github.io/posts/flags/</link>
			<pubDate>Fri, 27 Mar 2020 00:00:00 +0000</pubDate>
			
			<guid>https://cptq.github.io/posts/flags/</guid>
			<description>One day I was watching a lecture, and the lecturer noted that the flags of some nations, when viewed as matrices, have quite low rank, in the sense of the standard concept from linear algebra. I found this remark pretty amusing, so I set out to compute the ranks of some flags. The flag of Bolivia has rank one, since all of its columns are the same and hence any two columns are linearly dependent.</description>
			<content type="html"><![CDATA[<p>One day I was watching a lecture, and the lecturer noted that the flags of some nations, when viewed as matrices, have quite low <a href="https://en.wikipedia.org/wiki/Rank_(linear_algebra)">rank</a>, in the sense of the standard concept from linear algebra. I found this remark pretty amusing, so I set out to compute the ranks of some flags. The flag of Bolivia has rank one, since all of its columns are the same and hence any two columns are linearly dependent. The flag of Sweden has rank two; there are two types of columns: the all yellow ones and the ones with a blue top, yellow middle, and blue bottom, and these two types of columns are linearly independent. The rank of some flags cannot be computed by hand, so I collected some images of flags and wrote some scripts to compute them.</p>
<figure>
<img src="BO.svg" width=30%>
<figcaption>
Flag of Bolivia
</figcaption>
</figure>
<p><br></br></p>
<figure>
<img src="SE.svg" width=30%>
<figcaption>
Flag of Sweden
</figcaption>
</figure>
<h2 id="flag-images">Flag Images</h2>
<p>Luckily for me, there was some nice data available that worked perfectly for this task. Wikimedia hosts svg files with the flags of all sorts of territories and states under a consistent format. What I did at first was directly scrape the flags of sovereign states from some Wikipedia lists. After running some computations on these, I came across <a href="https://github.com/google/region-flags">this</a> repository of region flags by Google, which has the Wikipedia flags including some US state and Canadian province flags that I did not have. Thus, I started using these svg files instead. In total, we have 326 flags (with some duplicates due to, for example, Bouvet Island using the flag of Norway). I converted each svg to a png file to allow for the analysis of each flag as a matrix of pixels. Technically, the flag pngs are not quite matrices of pixels, as each pixel has a red, green, and blue value. We simply map these images to grayscale to analyze them—as far as I can tell, there are no overlaps in which two colors map to the same grayscale value.</p>
<h2 id="ranks-and-complexity-of-flags">Ranks and Complexity of Flags</h2>
<p>There is no doubt that the flags of low rank are simple and easy to unambiguously define. Any <span class="math inline">\(m \times n\)</span> real matrix of rank <span class="math inline">\(k\)</span> can be written as a sum of outer products <span class="math inline">\(\sum_{j=1}^k x_j y_j^T\)</span>, where <span class="math inline">\(x_j \in \mathbb{R}^m\)</span> and <span class="math inline">\(y_j \in \mathbb{R}^n\)</span>, so <span class="math inline">\(k(m+n)\)</span> real numbers specify the whole matrix. In fact, all that one has to do to describe the flags of Bolivia and Sweden is to specify a few colors and lines. However, the inverse is certainly not true—not all flags of high rank are complex. This is to be expected by basic linear algebra: any <span class="math inline">\(n \times n\)</span> diagonal matrix with nonzero diagonal is full rank yet can be fully specified by an <span class="math inline">\(n\)</span>-tuple of elements. In the same vein, the flag of the Republic of Congo is full rank due to its diagonal structure, yet it is composed of just three lines.</p>
<figure>
<img src="CG.svg" width=30%> </img>
<figcaption>
Flag of the Republic of the Congo
</figcaption>
</figure>
<p>Another measure of complexity of a flag is given by the size in bytes of the flag’s svg file. The Republic of Congo’s svg is only 416 bytes, placing it as only the 183rd largest file in our set. After doing my analysis, I found <a href="https://lascarides.github.io/fussyflags/">this blog post</a> which also ranks country flags by their svg file’s size in bytes, and funnily enough does so by using the size of Palau’s svg file as the smallest unit of measurement.</p>
<p>To compute ranks of the grayscale images, I simply use the <code>rank</code> function with default parameters in Julia’s default LinearAlgebra library. This function works by defining the rank as the number of singular values of <span class="math inline">\(A\)</span> that have magnitude greater than <span class="math inline">\(k \cdot \epsilon \cdot \sigma_1\)</span>, where <span class="math inline">\(k\)</span> is the smaller of number of rows and number of columns of <span class="math inline">\(A\)</span>, <span class="math inline">\(\epsilon\)</span> is <a href="https://en.wikipedia.org/wiki/Machine_epsilon">machine epsilon</a>, and <span class="math inline">\(\sigma_1\)</span> is the largest singular value of <span class="math inline">\(A\)</span>. Due to numerical error, the results are not perfect (e.g. we find that it computes the rank of the <span class="math inline">\(2 \times 200\)</span> matrix with all elements equal to <span class="math inline">\(\pi\)</span> as rank two), but we find that they are accurate in all low-rank examples besides Switzerland, for which the computed rank is 5 but the actual rank is 3.</p>
<figure>
<img src="CH.svg" width=30%></img>
<figcaption>
Flag of Switzerland
</figcaption>
</figure>
<p>Since flags have different aspect ratios and require different resolutions, the matrices are of different sizes, which makes a direct comparison of rank to be unfair. Thus, we instead consider the ratio between the rank and the maximum possible rank given the size of the matrix, <span class="math inline">\(\frac{\mathrm{rank}(A)}{\min(m,n)}\)</span>, which we call the <em>percent rank</em> of the <span class="math inline">\(m \times n\)</span> matrix <span class="math inline">\(A\)</span>.</p>
<p>Altogether, <span class="math inline">\(15\)</span> flags have full rank and <span class="math inline">\(43\)</span> flags have rank one. Every one of the flags with full rank has some diagonal structure extending along an entire diagonal. While some of these full rank flags are simple like the Republic of Congo’s, some of them are—in my eyes—deserving of full rank, like Bhutan’s. The distribution of percent ranks covers much of <span class="math inline">\([0,1]\)</span>, with some bias towards rank one and full rank values.</p>
<figure>
<img src="prank_distr.svg"></img>
<figcaption>
Distribution of percent rank
</figcaption>
</figure>
<p><br></br></p>
<figure>
<img src="full_rank.png"> </img>
<figcaption>
Full rank flags
</figcaption>
</figure>
<p>Looking at the flags of lowest rank, we see some interesting patterns in choices by flag designers. Each rank one flag either consists of only horizontal or only vertical lines. None of these rank one flags have more than four different colors, and none of them have more than five lines. A lot of territories fly the flag of France. There are two different types of rank two flags: a bicolored flag with a cross and a multicolored flag with one vertical line with a few horizontal lines. The rank three flags either have an outlined cross or Switzerland’s cross that does not extend to the edges of the flag.</p>
<figure>
<img src="rank_one.svg"> </img>
<figcaption>
Rank one flags (all scaled to 2:3 aspect ratio)
</figcaption>
</figure>
<p><br></p>
<figure>
<img src="rank_two.svg"> </img>
<figcaption>
Rank two flags
</figcaption>
</figure>
<p><br></p>
<figure>
<img src="rank_3.svg"> </img>
<figcaption>
Rank three flags
</figcaption>
</figure>
<p>We find that rank and percent rank have a nice, somewhat linear positive relationship. Also, filesize and percent rank have a somewhat positive relationship, but there is clearly a lot of deviation in which flags with low filesize have high percent rank. However, the flags with the largest filesizes do tend to have large ranks; the complexity of an svg file describing a low rank flag is just never that high. It is easy to imagine a pathological case in which a flag is solely composed of a massive amount of thin horizontal lines, in which case we have a rank one flag with a large filesize. For some reason, no state has used such a flag.</p>
<figure>
<img src=pathological_flag.svg> </img>
<figcaption>
An example pathological flag: a rank one flag with a 656KB svg file.
</figcaption>
</figure>
<p><br></br></p>
<figure>
<img src=rank_vs_prank.svg> </img>
<figcaption>
Rank vs. percent rank (Pearson correlation .649)
</figcaption>
</figure>
<p><br></br></p>
<figure>
<img src=fsize_vs_prank.svg> </img>
<figcaption>
Filesize vs. percent rank (Pearson correlation .317)
</figcaption>
</figure>
<p>Looking at the flags with the largest filesize, we see an assortment of flags with complex symbols and drawings.</p>
<figure>
<img src="top_svg_fsize.png"></img>
<figcaption>
Largest filesize flags
</figcaption>
</figure>
<p>Some of these large filesize flags still do not have very high rank. The flag of Pennsylvania has filesize 775,498 bytes and 62% rank, so it has the second largest filesize but merely 107th largest percent rank. While it has a detailed seal, the seal does not take up the whole flag, so it has many linearly dependent rows that are just entirely blue.</p>
<p>The case of Pennsylvania gives some nice intuition on these two flag complexity metrics, and suggests another way to measure complexity. We can measure each flag with a combination of these two metrics by taking the sum of the position (a better term would be rank or positional rank, but that would be confusing in the context of the linear rank) as measured by filesize with the position as measured by percent rank. Another way to combine the ranks would be through something like a <a href="https://en.wikipedia.org/wiki/Rank_product">rank product</a>, but the simple sum maintains integer values. Here are the most complex flags as measured by this metric.</p>
<figure>
<img src="top_pos.png"> </img>
<figcaption>
Top 12 flags by position sum
</figcaption>
</figure>
<p>These flags do not just have detailed symbols and drawings, but in fact they have large drawings that span significant portions of the flag, or at least diagonal lines that do. Pennsylvania falls to position 27 in this ranking, but other flags like North Dakota’s (position 4) have a seal in the middle with a lot of empty columns; the difference is that North Dakota’s seal takes up a larger portion of the vertical space of the flag, so there are many linearly independent rows. There are still some flags that somewhat hack this ranking. The flag of Florida (position 1) has a small seal, but it has diagonal lines that give it full rank.</p>
<h2 id="without-us-states-and-canadian-provinces">Without US States and Canadian Provinces</h2>
<p>For anyone who does not care for US State or Canadian provinces, we also compute the filesize and position sum rankings after omitting flags for these subregions. Note that no US State or Canadian province flags have low-rank, while many have large filesizes. Some regions change relative order in position sum after omitting the subregions, in part due to omission of subregions making the filesize rankings more compact. For instance, Saint Pierre and Miquelon is now position 1, even though it was behind Tristan da Cunha when subregions were included.</p>
<figure>
<img src="nosubregion_top_svg_fsize.png"> </img>
<figcaption>
Top 12 non-subregion flags by filesize
</figcaption>
</figure>
<p><br></br></p>
<figure>
<img src="nosubregion_top_pos.png"> </img>
<figcaption>
Top 12 non-subregion flags by position sum
</figcaption>
</figure>
<h2 id="thoughts">Thoughts</h2>
<p>The ranking of flag complexity by the sum of the rankings by percent rank and filesize seems pretty fair to me. I especially feel that the flag of Saint Pierre and Miquelon is deserving of the top spot, as it has neat designs that take up the whole flag. I am somewhat disappointed by the lack of variety in the designs of the flags of rank at most 3, but this is understandable given that flag designers probably did not care much for the rank of their flags. This type of computation would probably be pretty interesting for other types of flags and graphics. For example, the checkered flags used in auto racing have rank two and have a design distinct from the two types of rank two region flags.</p>
]]></content>
		</item>
		
		<item>
			<title>Endless Eigenart in 3 lines of code</title>
			<link>https://cptq.github.io/posts/eigart/</link>
			<pubDate>Fri, 03 Jan 2020 00:00:00 +0000</pubDate>
			
			<guid>https://cptq.github.io/posts/eigart/</guid>
			<description>Science is what we understand well enough to explain to a computer. Art is everything else we do. — Donald Knuth
 If we import numpy and matplotlib,
import numpy as np import matplotlib.pyplot as plt then we can generate really nice art in just 3 lines of code.
As = np.random.randn(6,6,3) vals = [val for s in np.linspace(0,1,500) for t in np.linspace(0,1-s,500) for val in np.linalg.eigvals(s*As[:,:,0] + t*As[:,:,1] + (1-s-t)*As[:,:,2])] plt.</description>
			<content type="html"><![CDATA[<blockquote>
<p>Science is what we understand well enough to explain to a computer. Art is everything else we do. — Donald Knuth</p>
</blockquote>
<p>If we import numpy and matplotlib,</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt</code></pre>
<p>then we can generate really nice art in just 3 lines of code.</p>
<pre><code>As = np.random.randn(6,6,3)
vals = [val for s in np.linspace(0,1,500) for t in np.linspace(0,1-s,500) for val in np.linalg.eigvals(s*As[:,:,0] + t*As[:,:,1] + (1-s-t)*As[:,:,2])]
plt.plot(np.real(vals), np.imag(vals), &#39;mo&#39;, alpha=.5, markeredgewidth=.1, markeredgecolor=&#39;k&#39;, markersize=1.5)</code></pre>
<p><img src="chs1.png" width=90%> </img><br />
<img src="chs2.png" width=90%> </img><br />
<img src="chs3.png" width=90%> </img><br />
<img src="chs4.png" width=90%> </img></p>
<p>Of course, this code was condensed for the novelty of having as few lines of code as possible. It is quite beautiful that essentially infinitely many (if not for the finiteness of the floating point system among other physical limitations) pretty images can be completely specified in so few lines of code. Compare this to the complexity of a Post-Impressionist oil painting, which would require data at the atomic level of every brushstroke to unambiguously store. To be fair, a better comparison would probably take into account the size of the library functions called along with the python interpreter, and it can be argued that a painting does not require atomic level information to understand or experience. Even so, the basic point still stands.</p>
<figure>
<img src="Cezanne.jpg" width=90% alt="A Cézanne, which cannot be specified in 3 lines of code."> </img>
<figcaption>
A Cézanne, which cannot be specified in 3 lines of code.
</figcaption>
</figure>
<p>Coming in at a more modest 9 lines we have code that is more flexible and easy to read:</p>
<pre><code>def eigenart(n, prec=500):
    A1 = np.random.randn(n,n)
    A2 = np.random.randn(n,n)
    A3 = np.random.randn(n,n)
    vals = []
    for s in np.linspace(0,1, prec):
        for t in np.linspace(0,1-s, prec):
            vals.extend(np.linalg.eigvals(s*A1 + t*A2 + (1-s-t)*A3))
    plt.plot(np.real(vals), np.imag(vals), &#39;mo&#39;, alpha=.5, markeredgewidth=.1, markeredgecolor=&#39;k&#39;, markersize=1.5)</code></pre>
<p>The generated art is simply the set of all complex numbers that occur as an eigenvalue of some matrix in a convex set of matrices. Let <span class="math inline">\(M_n(\mathrm{F})\)</span> denote the set of <span class="math inline">\(n \times n\)</span> matrices with entries in <span class="math inline">\(\mathbb{F}\)</span>, <span class="math inline">\(\sigma(A)\)</span> denote the set of eigenvalues of the matrix <span class="math inline">\(A\)</span>, and <span class="math inline">\(\mathrm{Co}(S)\)</span> denote the convex hull of <span class="math inline">\(S\)</span>. For a set of matrices <span class="math inline">\(S \subseteq M_n(\mathbb{C})\)</span>, we define the <em>hull spectra</em> of <span class="math inline">\(S\)</span> to be <span class="math display">\[\mathrm{HS}(S) = \{\lambda \in \sigma(A) : A \in \mathrm{Co}(S) \}\]</span> Thus, our <code>eigenart</code> function plots <span class="math inline">\(\mathrm{HS}(\{A_1, A_2, A_3\})\)</span> for three random matrices <span class="math inline">\(A_1, A_2,\)</span> and <span class="math inline">\(A_3\)</span> in <span class="math inline">\(M_n(\mathbb{R})\)</span> with entries drawn from a standard normal distribution. We can now understand certain properties of the generated art.</p>
<p>In the <code>eigenart</code> function, <span class="math inline">\(n\)</span> is the size of the matrices. Larger <span class="math inline">\(n\)</span> gives more complex hull spectra as each matrix in <span class="math inline">\(\mathrm{Co}(S)\)</span> has more eigenvalues, and they interact in more complex ways. <code>prec</code> controls the number of convex combinations of matrices whose eigenvalues are computed and plotted. It can be increased to get rid of some of the areas of low density, or decreased to allow for less expensive computation. The plotting parameter <code>alpha</code> allows transparent markers so that overlap can be seen. Also, the small black marker edges allow for a shading effect, as areas that are denser with eigenvalues appear darker.</p>
<p>The hull spectra shown above are symmetric about the real axis—the generator matrices were chosen to be real, and the non-real eigenvalues of real matrices in <span class="math inline">\(M_n(\mathbb{R})\)</span> come in conjugate pairs. If we instead take our random generators to have non-real entries as well, then the hull spectra does not have this symmetry. Also, real matrices tend to have some real eigenvalues with high probability (for instance, any <span class="math inline">\(n \times n\)</span> real matrix with <span class="math inline">\(n\)</span> an odd number has at least one real eigenvalue), so most hull spectra of real matrices contain a line segment or multiple line segments on the real line.</p>
<figure>
<img src="chs5.png" width=90% alt="Hull spectra of 3 random complex matrices in $M_4(\mathbb{C})$"> </img>
<figcaption>
Hull spectra of 3 random complex matrices in <span class="math inline">\(M_4(\mathrm{C})\)</span>
</figcaption>
</figure>
<p>Let <span class="math inline">\(A_{s, t} = s A_1 + t A_2 + (1-s-t) A_3\)</span> be a matrix in <span class="math inline">\(\mathrm{Co}(\{A_1, A_2, A_3\})\)</span>. Continuity and differentiability of the eigenvalues of a family of matrices is a technical subject, so what follows is rather hand-wavy. The entire set of eigenvalues of a matrix depends continuously on its entries. Some of the holes in the hull spectra are actual holes where there are no eigenvalues. However, some of the areas where there are holes or that are sparse with eigenvalues are actually mathematically completely solid; the choice of a finite number of matrices in the convex hull to evaluate at causes them to appear empty. These spots tend to occur near an eigenvalue of higher multiplicity, which is where non-differentiability of eigenvalues can occur. This explains sparse areas of eigenvalues near the real line, as when a non-real eigenvalue approaches the real line, its conjugate is another eigenvalue that approaches the real line. Elsewhere, the shading shows “folds” and other properties that seem to give the hull spectra depth. This can be explained by the fact that the hull spectra is a projection onto the first two coordinates of the higher dimensional surface consisting of points of the form <span class="math inline">\(\big(\Re\; \lambda(A_{s,t}), \Im\; \lambda(A_{s,t}), s, t\big)\)</span> in <span class="math inline">\(\mathbb{R}^4\)</span> (recall that the eigenvalues depend continuously on <span class="math inline">\(s\)</span> and <span class="math inline">\(t\)</span>).</p>
<p>The eigenvalues of a matrix are the roots of its characteristic polynomial, and any polynomial <span class="math inline">\(p\)</span> has a corresponding matrix <span class="math inline">\(C\)</span> (the companion matrix) such that the eigenvalues of <span class="math inline">\(C\)</span> are precisely the roots of <span class="math inline">\(p\)</span>. From another viewpoint, the hull spectra <span class="math inline">\(\mathrm{HS}(S)\)</span> can also be viewed as the roots of the characteristic polynomials of matrices in <span class="math inline">\(\mathrm{Co}(S)\)</span> Others have created or discovered art from the roots of polynomials before: this <a href="http://math.ucr.edu/home/baez/roots/">post</a> by John Baez and the work of Bahman Kalantari in <a href="https://www.cs.rutgers.edu/~kalantar/polynomiography/exhibitions.html">polynomiography</a> provide striking examples.</p>
<p>While hull spectra do provide amazing images, my interest in them arose from important problems in mathematics. One open problem that has been unsolved for decades is that of determining the set of complex numbers which occur as the eigenvalue of some <span class="math inline">\(n \times n\)</span> doubly stochastic matrix. Equivalently, this set is the hull spectra of the <span class="math inline">\(n \times n\)</span> permutation matrices. This article [<a href="https://arxiv.org/abs/1703.10992">1</a>] provides a good survey of this problem and similar problems; I have also published two works in this field [<a href="https://arxiv.org/abs/1909.10597">2</a>] [<a href="https://arxiv.org/abs/1908.03647">3</a>].</p>
<p>[1] Charles R. Johnson, Carlos Marijuán, Pietro Paparella, and Miriam Pisonero. “The NIEP.” Operator Theory, Operator Algebras, and Matrix Theory, pp. 199-220 (2018).</p>
<p>[2] Eric Jankowski, Charles R. Johnson, and Derek Lim. “Spectra of convex hulls of matrix groups.” Linear Algebra and its Applications (2020).</p>
<p>[3] Amit Harlev, Charles R. Johnson, and Derek Lim. “The Doubly Stochastic Single Eigenvalue Problem: A Computational Approach.” Experimental Mathematics (2020).</p>
<figure>
<img src="cDS6.png" width=90% alt="Eigenvalues of convex combinations of pairs of $6 \times 6$ permutation matrices. Only those in the upper half-plane are shown."> </img>
<figcaption>
Eigenvalues of convex combinations of pairs of <span class="math inline">\(6 \times 6\)</span> permutation matrices. Only those in the upper half-plane are shown.
</figcaption>
</figure>
]]></content>
		</item>
		
	</channel>
</rss>
