TL;DR
Some inputs are collections whose items have no natural order: the points of a 3D scan, the atoms of a molecule, the items in a shopping basket. A function of such an input is permutation invariant when shuffling the items leaves its output unchanged. A model built this way cannot learn a meaningless rule such as "the first point counts for more than the second", and it accepts collections of any size. The standard recipe applies the same small network to every item and then combines the results with a symmetric operation such as a sum, a mean or a maximum.
Builds on: Multivariable Function, Feedforward Neural Network · Leads to: Graph Readout, PointNet
Where it's used
Classifying 3D objects from point clouds. A depth sensor or LiDAR scan returns a list of (x, y, z) coordinates, and nothing about the physical object says which point comes first. PointNet, published in 2017, takes the raw unordered points, applies one shared network to each point, and pools the results with a max operation. The answer does not depend on the order in which the scanner happened to list the points.
Predicting a property of a molecule. A Graph Neural Network produces one vector per atom. To predict a single property of the whole molecule, the network combines all the atom vectors in a readout step. Renumbering the atoms in a file format must not change the prediction, and a permutation invariant readout guarantees that.
Summarising a feature map. In a Convolutional Neural Network, Global Average Pooling replaces each feature map with its average over all of its positions. Shuffling those positions changes nothing about the average, so the output is invariant to them. The price is that the average also throws away where in the image a feature was found.
How it works
Take a tiny collection of three numbers and a rule that maps each number to a new number, then add the results up.
- Input. The collection is the list 2, 5, 3. A list is ordered, but we want the answer to depend only on which numbers are present, not on where they sit.
- Per-item map. Apply the rule φ(x) = 2x + 1 to each number on its own. The number 2 becomes 5, the number 5 becomes 11 and the number 3 becomes 7. The list is now 5, 11, 7. Every item is handled by the same rule, and no item looks at any other item. Check: 2 times 5 plus 1 is 11, so the middle entry is 11.
- Pool. Add the three results: 5 + 11 + 7 = 23. This is the output. Addition does not care about order. Check: 5 plus 11 is 16, and 16 plus 7 is 23.
- Shuffle the input. Feed in 3, 2, 5 instead. Step 2 gives 7, 5, 11, and step 3 gives 7 + 5 + 11 = 23. The output did not change. That is what permutation invariance means. Check: the same three numbers are present, so the same three values are summed.
- Contrast with a positional rule. Now combine the numbers with weights that depend on position: h(x1, x2, x3) = x1 + 2 x2 + 3 x3. For 2, 5, 3 this gives 2 + 10 + 9 = 21. For 3, 2, 5 it gives 3 + 4 + 15 = 22. Shuffling changed the answer, so h is not permutation invariant. Check: the only difference between the two calls is which number got the weight 3.
flowchart LR A["items x1, x2, x3 in any order"] --> B["same map phi applied to each item"] B --> C["pool with sum, mean or max"] C --> D["output, the same for every order"]
The math
Let f take n inputs. Let π be any permutation of the positions , meaning a rearrangement of them. Then f is permutation invariant when
for every such π. In words: for every reordering of the inputs, f returns the same value as for the original order.
Step 1 in symbols: the per-item map
Let φ be a function from to . Each item is a vector with d numbers, and φ turns it into a vector with k numbers. The same φ, with the same weights, is applied to every item. In the walkthrough, d = k = 1 and φ(x) = 2x + 1. Applied to the list 2, 5, 3 it gives the list 5, 11, 7.
Step 2 in symbols: symmetric pooling
Pooling combines the k-vectors into one vector without caring about their order. Three choices are common:
The max is taken separately in each of the k coordinates. Each of these is invariant. For the sum, reindexing the terms with π gives
because a sum of the same terms in a different order is the same number. The mean is the sum divided by the fixed number n, so it is invariant too. The max depends only on which values are present, not where they are.
Step 3 in symbols: the general form
Combine the pooled vector with a second function ρ:
Any f of this form is permutation invariant, because the inner sum is. Zaheer and coauthors showed in 2017 that, for finite collections and under mild conditions on continuity and on the size of the pooled vector, every permutation invariant function can be written this way. In practice both φ and ρ are small neural networks, trained together.
Worked examples
- Let f(x1, x2) = x1 + x2. Evaluate f(4, 1) = 4 + 1 = 5.
- Swap the inputs and evaluate f(1, 4) = 1 + 4 = 5. The answer is the same.
- Let g(x1, x2) = x1 − x2. Evaluate g(4, 1) = 4 − 1 = 3.
- Swap the inputs and evaluate g(1, 4) = 1 − 4 = −3. The answer changed, so g is not permutation invariant.
Interpretation: addition does not care which input is first; subtraction does. One swap that changes the answer is enough to rule a function out. One swap that does not change the answer proves nothing by itself.
Use φ(x) = x², sum pooling, and ρ(s) = s + 1. The input collection is 1, −2, 3.
- Apply φ to each item: 1² = 1, (−2)² = 4, 3² = 9. The list is 1, 4, 9.
- Sum the list: 1 + 4 + 9 = 14.
- Apply ρ: 14 + 1 = 15. This is the output.
- Reorder the input to 3, 1, −2. Apply φ: 9, 1, 4. Sum: 9 + 1 + 4 = 14. Apply ρ: 15. The output matches.
- Now replace the sum with a max. The largest value of φ is 9 for both orders, so the pooled value is 9 and ρ gives 9 + 1 = 10 for both orders. The max version is invariant as well.
Interpretation: the square and the +1 are applied item by item and after pooling respectively. The only thing that matters for the output is the multiset of φ values, and that multiset is the same for both orders.
Take four points in the plane: A = (1, 2), B = (3, 0), C = (2, 2) and D = (0, 1). Let φ(p) = (p_x, p_y, p_x p_y), which gives each point three numbers. The values of φ are:
- A gives (1, 2, 2)
- B gives (3, 0, 0)
- C gives (2, 2, 4)
- D gives (0, 1, 0)
Pool with a componentwise max. The largest first coordinate is 3, the largest second coordinate is 2, and the largest third coordinate is 4, so the pooled vector is (3, 2, 4). Let ρ add its three coordinates, so the output is 3 + 2 + 4 = 9.
Try it: keep the same φ and ρ, but replace the max with a componentwise mean, and feed the points in the order B, A, D, C. Work out the output.
Answer: the first coordinates are 3, 1, 0, 2, which sum to 6 and average to 1.5. The second coordinates are 0, 2, 1, 2, which sum to 5 and average to 1.25. The third coordinates are 0, 2, 0, 4, which sum to 6 and average to 1.5. ρ adds these to 1.5 + 1.25 + 1.5 = 4.25. Any other order of the four points would give 4.25 too, because a mean does not depend on order.
Common mistakes and tradeoffs
It is tempting to think that invariance means ignoring the items. In fact the output depends on every item's value. It only fails to depend on their order. Changing the coordinates of any one point in the mean version of the third example changes the output, because every point contributes to the mean. With max pooling, a point that is not the largest in any coordinate can change without affecting the output.
It is tempting to think that sorting the items is an equally good way to get invariance. Sorting does give a canonical order, but it needs a key to sort by, and in more than one dimension there is no natural key. The result then depends on the key that was chosen. Symmetric pooling avoids this choice.
It is tempting to think that max pooling keeps all the information. In fact it keeps only the largest value in each coordinate, so two different collections can give the same output. Sum and mean keep more, but mean also loses the number of items.
It is tempting to think that invariant and equivariant mean the same thing. In fact an equivariant function returns one output per item and permutes those outputs along with the input, while an invariant function returns one output for the whole collection. See Equivariance for the general version.
| Pooling | Keeps | Loses |
|---|---|---|
| Sum | The total, which grows with the collection size | Nothing about how the total is split |
| Mean | The average, which is independent of collection size | The number of items |
| Max | The largest value in each coordinate | Every other value |
Use this design when the order carries no information and collections vary in size. Do not use it when order is the signal: a sentence, a time series or an image where position matters needs a model that keeps positions, such as a Convolutional Neural Network or a sequence model.
History
Symmetric functions have been studied in mathematics for a long time, and the sum and the maximum are the first examples anyone meets. What changed in machine learning was a practical architecture for learning such functions. Early models for graphs and sets used pooling by hand, with a fixed rule chosen by the designer.
In 2017 Zaheer and coauthors published "Deep Sets", which proved the sum-decomposition form given above and showed that it can be learned from data. In the same year Qi and coauthors published PointNet, which applied the idea to 3D point clouds with max pooling. Point clouds come straight from depth sensors, so the approach found many uses.
Recap
- A collection has no order, so the right function of a collection is one that ignores order.
- A function is permutation invariant when every reordering of its inputs gives the same output. A single swap that changes the output shows it is not.
- The recipe is a shared per-item map φ, a symmetric pool (sum, mean or max), then a readout ρ.
- Deep Sets shows this recipe is general for finite collections.
- Next, read about the Graph Readout, which applies the same idea to the nodes of a graph, and then PointNet, which applies it to 3D scans.
Check yourself
QuestionIn plain words, what must be true of a function f for it to be permutation invariant?Show answer
For every reordering of its inputs, f must return exactly the same value that it returns for the original order. Changing the order of the inputs must not change the output, although changing the values of the inputs may.
QuestionLet φ(x) = x + 1 and use sum pooling. Compute the pooled value for the collection −1, 4, 2 and check that the order 2, −1, 4 gives the same result.Show answer
φ gives 0, 5 and 3 for the three inputs in the first order. Their sum is 0 + 5 + 3 = 8. For the order 2, −1, 4, φ gives 3, 0 and 5, whose sum is also 8. Both orders give 8, as invariance requires.
QuestionWhy does summing the per-item values give invariance, while concatenating them in arrival order does not?Show answer
A sum of a fixed set of numbers is the same however the terms are arranged, so reordering the items cannot change it. A concatenation keeps each value in its own slot, so reordering the items moves values into different slots, and the output changes even though the same items are present.
QuestionA colleague wants to feed a set of sensor readings to a model by joining them into one long vector in the order they arrived. Why might that be a problem, and what would you suggest instead?Show answer
Arrival order is an accident of timing, so the model would learn patterns that depend on it, and two identical sets of readings arriving in different orders would get different predictions. If order carries no meaning, apply a shared per-reading map and pool the results with a sum, mean or max, which gives the same answer for every arrival order. If order does carry meaning, such as a time series, keep the order and use a model designed for sequences instead.
Sources
- Zaheer et al., "Deep Sets" (2017): https://arxiv.org/abs/1703.06114
- Qi et al., "PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation" (2017): https://arxiv.org/abs/1612.00593
- Goodfellow, Bengio, Courville, "Deep Learning", Chapter 6: https://www.deeplearningbook.org/