Quant Memo
Core

Deep Sets and Permutation-Invariant Networks

Deep Sets builds a network whose output is guaranteed not to change no matter what order you feed its inputs in, by encoding each element separately and combining them with a symmetric operation like a sum.

Prerequisites: The Multilayer Perceptron

Some inputs to a model are naturally sets, not sequences: a basket of correlated positions in a portfolio, the price levels sitting in an order book at one instant, or the collection of news headlines mentioning a ticker on a given day. There is no meaningful "first" element. Feed such a collection into an ordinary neural network by concatenating the elements in some order, and the network's output depends on that arbitrary order — shuffle the same basket and you can get a different answer, which is clearly wrong for something that shouldn't have an order at all.

The analogy: counting a bag of coins

The total value of a bag of coins does not depend on the order you dropped them in — you can add them up in any sequence and get the same sum. That property, unaffected by reordering, is permutation invariance, and addition is the simplest operation that has it.

The mechanics

Deep Sets builds any permutation-invariant function of a set X={x1,,xn}X = \{x_1, \dots, x_n\} as:

f(X)=ρ(xXϕ(x))f(X) = \rho\left(\sum_{x \in X} \phi(x)\right)

In words: first, a small network ϕ\phi encodes each element on its own, the same way for every element, ignoring the others entirely. Then a symmetric pooling operation — here, a sum — combines all the per-element encodings into one fixed-size vector, which cannot depend on element order because addition doesn't care about order. Finally, a second network ρ\rho turns that pooled vector into the actual output.

Worked example 1: order doesn't matter

Let ϕ\phi be a simple learned scalar per element: three set elements produce ϕ\phi-outputs 2,5,32, 5, 3 in that order. Sum pooling: 2+5+3=102+5+3=10. Feed the same three elements in the order 5,2,35, 2, 3: still 5+2+3=105+2+3=10. Any of the 3!=63! = 6 orderings of these three numbers gives the identical sum — the invariance is exact, not approximate, because addition is exactly commutative.

Worked example 2: sum versus max pooling

Same three per-element outputs, 2,5,32, 5, 3. Sum pooling gives 1010; max pooling instead gives max(2,5,3)=5\max(2,5,3)=5. Both are valid symmetric (order-independent) choices, but they encode different things: sum captures a total across the whole set (useful for something like aggregate portfolio risk contribution), while max captures only the single most extreme element (useful for something like "is there at least one order-book level at an extreme price"). Both remain invariant to reordering the same three numbers in any way.

x1 x2 x3 φ φ φ Σpool ρ
Every element passes through the same φ independently, then a symmetric pool (sum, mean, or max) combines them — reordering the elements never changes the pooled result.
sum: 10 mean: 3.3 max: 5
The same set {2, 5, 3}, in any order, pooled three different symmetric ways — each choice is invariant to reordering but captures a different summary of the set.

Deep Sets guarantees permutation invariance by construction: encode each set element identically and separately with ϕ\phi, then combine with a symmetric operation like a sum, and no ordering of the inputs can change the output — this is a structural property of the architecture, not something the model has to learn from examples.

What this means in practice

Any input that is genuinely a collection with no inherent order — a set of correlated holdings, a snapshot of order-book levels, a day's worth of news items about one name — is a candidate for a Deep Sets-style model instead of forcing it into a fixed-order vector or a sequence model that would otherwise treat item order as meaningful when it isn't.

Don't confuse permutation invariance (the whole-set output is unchanged by reordering) with permutation equivariance (per-element outputs reorder along with the input, but aren't collapsed to one value). The ϕ\phi layers before pooling in Deep Sets are equivariant — reorder the inputs and their outputs reorder correspondingly — and it is only the pooling step afterward that produces the fully invariant, order-blind result. Applying pooling too early, or expecting invariance from a layer before the sum, is the classic mistake.

Related concepts

Practice in interviews

Further reading

  • Zaheer et al., Deep Sets (2017)
ShareTwitterLinkedIn