Order doesn't matter: permutation invariance
Read these first if they are new to you
- Shapes as point clouds Intermediate
The idea in one paragraph
A point cloud stores its points in a list, but the order of that list means nothing: the same shape can be listed in many orders. A function of the whole cloud should give the same answer for every order. Such a function is called permutation invariant. Sums, averages and maxima are; "the first point in the list" is not. A function that gives one answer per point is called permutation equivariant if shuffling the points shuffles its answers in the same way.
The same shape can be listed in very many orders
A permutation is a reordering of a list. Three points A, B and C can be listed in 3 × 2 × 1 = 6 orders: ABC, ACB, BAC, BCA, CAB and CBA. In general, n points have n! orders ("n factorial", the product 1 × 2 × … × n). That number grows fast: 10 points have 3,628,800 orders, and 1,000 points have a number of orders with 2,568 digits.
A program that stores a cloud has to pick one order, often the order a scanner happened to produce. A model could try to learn that order does not matter by seeing many shuffled copies of each cloud. With so many orders, it could never see them all. So models for point sets build the property in.
Some summaries ignore the order, and some do not
Take the points A = (1, 2), B = (4, 0) and C = (2, 3), and list them twice: as A, B, C and as C, A, B.
Predict first. For each summary in the table, will the two orders give the same answer?
| Summary of the list | order A, B, C | order C, A, B | Invariant? |
|---|---|---|---|
| Sum of the points | (7, 5) | (7, 5) | yes |
| Largest x and largest y | (4, 3) | (4, 3) | yes |
| The first point | (1, 2) | (2, 3) | no |
| 1 × first + 2 × second + 3 × third | (15, 11) | (16, 7) | no |
Check the last row for the order A, B, C: 1 × (1, 2) + 2 × (4, 0) + 3 × (2, 3) = (1 + 8 + 6, 2 + 0 + 9) = (15, 11). It gives each place in the list its own weight, so moving a point to another place changes the answer. The sum gives every place the same weight, 1, so the order cannot matter.
The last row is a warning about networks. A linear layer fed the coordinates as one long list, [x1, y1, x2, …], gives every place its own weight, exactly like that row. So it is not permutation invariant, and it also cannot accept a different number of points.
| Summary | now | vs. A, B, C |
|---|
Try it. Before you press the button, predict which of the five summaries will change. Then shuffle several times. Which ones never change?
Answer
The sum of x, the mean point and the largest y never change: each treats every place in the list alike. The first point's x and the weighted sum change with almost every shuffle, because they depend on which point sits in which place.
Answers for each point should move with their points
Some functions give one answer per point, such as a label for each point or the sum x + y of each point. For the order A, B, C that sum gives [3, 4, 5]. For the order C, A, B it gives [5, 3, 4]: the same answers, reordered the same way as the points. That is permutation equivariance. Each point keeps its own answer, wherever it sits in the list.
Models of point sets usually combine the two properties. First they run equivariant steps that compute features for each point, such as the same small network applied to every point, or attention without position information. Then they take one invariant step, such as a sum or a maximum, to summarize the whole set. PointNet pooling is the simplest example.
permutation.py
import numpy as np
P = np.array([[1.0, 2.0], [4.0, 0.0], [2.0, 3.0]]) # A, B, C
Q = P[[2, 0, 1]] # the same points as C, A, B
w = np.array([1.0, 2.0, 3.0]) # one weight per list position
print(P.sum(axis=0), Q.sum(axis=0)) # invariant
print(P.max(axis=0), Q.max(axis=0)) # invariant
print(w @ P, w @ Q) # rows weighted by w, then added: not invariant
print(P.sum(axis=1), Q.sum(axis=1)) # x + y of each point: equivariant
[7. 5.] [7. 5.] [4. 3.] [4. 3.] [15. 11.] [16. 7.] [3. 4. 5.] [5. 3. 4.]
On a computer, a sum of decimals can differ in its last digit when the order changes, because each addition rounds. In Python, (0.1 + 0.2) + 0.3 gives 0.6000000000000001 but 0.1 + (0.2 + 0.3) gives 0.6. So a sum or a mean is invariant up to rounding; a maximum is exactly invariant. Also, order is only one thing a shape model may need to ignore. Rotating or moving the whole shape changes every coordinate, which is a different property; models often learn to ignore it through data augmentation.
Check yourself
-
Is the median of the points' x coordinates permutation invariant?
Answer
Yes. The median sorts the values first, so the order you list them in does not matter.
-
Work a similar problem. The summary is "x of the last point minus x of the first point". Compute it for the orders A, B, C and C, A, B. Is it invariant?
Answer
A, B, C: 2 − 1 = 1. C, A, B: 4 − 2 = 2. The answers differ, so it is not invariant.
-
How many orders do 5 points have?
Answer
5! = 5 × 4 × 3 × 2 × 1 = 120.
-
A function gives each point its distance to the mean point of the cloud. Is it invariant, equivariant or neither?
Answer
Equivariant. It gives one answer per point, and the mean point does not depend on the order, so each point keeps its own distance wherever it sits. Shuffling the points shuffles the list of distances the same way.
Go further
Optional background, for readers who want more than this page.
-
Opens with why sets need order-free models, then reviews the ways to build them: averaging over orders (which leads to Deep Sets and self-attention), sorting, approximate invariance, and graphs.
-
PointNet paper, section 4.1: "Properties of Point Sets" Qi, Su, Mo and Guibas (2017) Paper section Advanced
One paragraph that names the three properties a point-cloud network needs, starting with "unordered".