Skip to content

Tabular, time-series, scientific, and geometric deep learning · Sets, point clouds, and geometric learning · SPE005 · Architecture

Deep Sets

Deep Sets models unordered collections through shared element transformations and symmetric aggregation. It is appropriate when predictions should not depend on input order, such as bags of measurements, variable-sized…

Runs in CodeSplash (Experimental) Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.set_model. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Deep Sets models unordered collections through shared element transformations and symmetric aggregation. It is appropriate when predictions should not depend on input order, such as bags of measurements, variable-sized object sets or event collections.

Question / hypotheses

The operative question is whether the specified representation, symmetry, likelihood or physical constraint improves held-out behavior for this data domain. This is a learning framework, not a null-hypothesis test; losses, attention weights and predictive confidence are not statistical p-values.

Architecture / computational structure

An element encoder phi maps every item independently, a sum pools the transformed items, and rho transforms the aggregate. Equivariant variants produce elementwise outputs while sharing a global set summary.

Assumptions

Order must truly be irrelevant. Pooling can lose interactions unless the element representation is rich enough; extrapolation to much larger sets is not automatic. Universality statements have domain and latent-dimension conditions, not finite-data guarantees.

Formula / computational definition

f(X)=ρ(∑x∈Xϕ(x))f(X)=\rho(\sum_{x\in X}\phi(x)). The sum is permutation invariant; ϕ\phi and ρ\rho are learned functions. Task loss depends on whether the output is a set label, regression target or structured prediction.

Parameters and notation

Learned or estimated: Element-encoder and aggregate-network weights, optional embeddings and output head.

Hyperparameters and effects: Latent width, pooling operator, depth, set-size handling and optimizer. Sum preserves multiplicity but grows with set size; mean pooling removes some count information. Sufficient representation capacity matters for expressivity.

Fitting, fine-tuning, and adaptation

Fit the task loss while randomly permuting input order as an implementation check. Transfer a frozen element encoder with a new aggregate head, then unfreeze if target validation improves. Monitor shifts in set cardinality and element distribution, and preserve source-task performance when adapting shared representations.

How to use and calibrate

Define the independent evaluation unit before preprocessing: row/entity, whole set/object, molecule/trajectory, input function or chronological forecasting origin. Keep target construction and normalization within permitted training data. Test exact permutation invariance, cardinality shift, missing/duplicated elements and comparison with simple pooled statistics. Report uncertainty and task error on independently held-out sets.

Example application

Predict a specimen-level property from an unordered collection of cell measurements. This is a proposed use case, not a claim of validated performance on supplied real data.

Interpretation / pitfalls

Watch out

Assess model error against domain baselines and the stated assumptions. Component-level mathematical correctness does not establish paper reproduction or scientific validity. Invariance/equivariance checks validate transformation behavior; they do not establish correct physical dynamics or chemical accuracy.

Python and R code examples

Scope: Small Deep Sets map with an exact permutation-invariance assertion. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python/R: shared MLPs plus sum pooling in PyTorch/native torch. The NumPy/base-R example verifies permutation invariance of a small fixed-weight Deep Sets map.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Small Deep Sets map with an exact permutation-invariance assertion. Use the shared setup.

Shared setup for this chapter
import numpy as np
def sm(x):
    x=np.asarray(x); e=np.exp(x-x.max(axis=-1,keepdims=True)); return e/e.sum(axis=-1,keepdims=True)
X=np.array([[1.,0.],[.2,.8],[-.3,.5]])
W=np.array([[.5,.2],[-.1,.7]])
def f(A): return np.tanh(np.tanh(A@W).sum(axis=0))
permutation=[2,0,1]
assert np.allclose(f(X),f(X[permutation]))
print(f(X))
R

Complete calculation — Small Deep Sets map with an exact permutation-invariance assertion. Use the shared setup.

Shared setup for this chapter
sm <- function(x) {
  if(is.null(dim(x))) { e<-exp(x-max(x)); return(e/sum(e)) }
  t(apply(x,1,function(v) { e<-exp(v-max(v)); e/sum(e) }))
}
X<-matrix(c(1,0,.2,.8,-.3,.5),3,byrow=TRUE)
W<-matrix(c(.5,.2,-.1,.7),2,byrow=TRUE)
f<-function(A) tanh(colSums(tanh(A%*%W)))
stopifnot(max(abs(f(X)-f(X[c(3,1,2),])))<1e-12); print(f(X))

Sources

From the CodeSplash reference, entry SPE005.