Locally Injective Pattern Counts for Graph Learning

Graph neural networks are often made more expressive by counting small patterns, such as triangles, cycles or other motifs, inside the input graph and feeding those counts in as extra features. The machine-learning community counts homomorphisms: maps from a small pattern into the graph that send edges to edges. These maps may fold the pattern onto itself, so a 6-cycle can be "counted" by walking back and forth along a single edge. A separate community in graph algorithms has spent two decades studying locally constrained homomorphisms, which forbid such folding near each vertex. Its results are stated in vocabulary and problem orientations the learning community does not use. This note proposes one specific transfer between the two. We would count locally injective homomorphisms from small patterns into the input graph, meaning maps in which no two neighbours of a pattern vertex land on the same graph vertex. We would prove exactly what extra information these counts carry, measure what they cost to compute, and test them on the standard expressiveness and molecular benchmarks.

The core prediction is plain. For cycle patterns, locally injective counts are closed non-backtracking walks: walks that never immediately reverse along the edge they just used. These can be computed in polynomial time by repeatedly multiplying an edge-to-edge transition matrix, even for long cycles where plain subgraph counting is provably hard. The theory also says where they must fail. On regular graphs, non-backtracking walk counts carry the same information as the eigenvalues of the adjacency matrix. They should therefore give no gain on pairs of strongly regular graphs that share eigenvalues, and that gap must instead be closed by non-cycle patterns such as theta graphs. The proposal stands or falls on this pairing of a cheap gain and a predicted blind spot.

Why the two directions meet here, and what the obvious idea gets wrong

The learning side has a mature account of plain homomorphism counts. Beyond Weisfeiler-Lehman characterizes each architecture by the family of patterns whose homomorphism counts it can compute; message-passing networks, for example, reach only trees. Homomorphism Counts for GNNs: All About That Basis shows that subgraph counts are linear combinations of homomorphism counts over the pattern's "spasm", the set of graphs obtained by merging pattern vertices. Two papers then inject such counts into models: Homomorphism Counts as Structural Encodings as node features (MoSE), and Deep Homomorphism Networks as stacked layers. All four papers restrict themselves to unconstrained maps. They motivate this proposal, since they establish homomorphism counting as the working currency of expressiveness. They also supply our method: the spasm decomposition and the completeness theorem.

The graph-mapping side, surveyed in Locally constrained graph homomorphisms, studies three kinds of constrained maps. Locally bijective maps (coverings) match each neighbourhood exactly. Locally injective maps never send two neighbours to the same vertex. Locally surjective maps (role assignments) hit every neighbour at least once. The obvious bridge, and the one the research file lists first among its gaps, is "add locally constrained counts to GNNs." Taken literally, two-thirds of that idea does not survive inspection.

The same survey shows that two graphs share a common cover exactly when they have the same degree refinement matrix, which is the stable output of colour refinement. Covering information therefore sits at the 1-WL level, the distinguishing power of the classical one-dimensional Weisfeiler-Lehman test, and adds nothing beyond plain message passing. Locally bijective or surjective maps from a small pattern into a large graph also rarely exist, because they force degrees to match. Locally injective maps are the only variant that is both well-defined and informative as a pattern feature.

The second correction concerns hardness, and it is a translation error between the two communities. An Algorithmic Framework for Locally Constrained Homomorphisms proves locally injective homomorphism decision is W[1]-hard even parameterized by the guest size. W[1]-hard means it is believed to admit no algorithm whose exponential cost depends on the parameter alone. The survey proves NP-completeness for fixed theta-graph targets. In both results the large graph is the source and the small graph is the fixed target. GNN features run the other way: a fixed small pattern maps into a varying large input. Read naively across the silo, these hardness results would wrongly suggest locally injective features are intractable. The proposal therefore treats the mapping-complexity literature as a constraint that must be re-oriented before use, not imported wholesale.

Core Claim

For a pattern $F$ and input graph $G$, let $\mathrm{lih}(F,G)$ be the number of locally injective homomorphisms from $F$ to $G$, and $\mathrm{hom}(F,G)$ the number of plain ones. We claim three things.

The first is a decomposition. By inclusion-exclusion over the forbidden identifications (pairs of pattern vertices with a common neighbour), we expect

$$\mathrm{lih}(F,G)=\sum_{\pi\in\mathcal{L}(F)} c_\pi\,\mathrm{hom}(F/\pi,G).$$

Here $\mathcal{L}(F)$ is the set of partitions of $V(F)$ generated by merging vertices that share a neighbour, $F/\pi$ is the merged graph, and $c_\pi$ are integer coefficients determined by $F$ alone. We call $\{F/\pi\}$ the local spasm; it is a subset of the spasm used by Jin et al. By the completeness theorem of Zhang et al., a model can determine $\mathrm{lih}(F,\cdot)$ if its pattern family contains the local spasm. This places locally injective counts inside the existing homomorphism-expressivity hierarchy rather than outside it.

The second is cheapness without low treewidth. For cycles, $\mathrm{lih}(C_k,G)$ equals the number of closed non-backtracking walks of length $k$. This is the trace of the $k$-th power of the non-backtracking edge matrix, computable in time roughly proportional to $k$ times the number of edge-to-edge transitions. We conjecture that the local spasm of $C_k$ nevertheless contains merged graphs of growing treewidth. If so, these counts deliver, at polynomial cost, linear combinations of homomorphism counts that the pattern-enumeration methods behind MoSE and Deep Homomorphism Networks could only reach at cost exponential in treewidth. Exact and Approximate Pattern Counting in Degenerate Graphs proves that subgraph counting of $k$-cycles is #W[1]-hard even on sparse graphs, so the contrast with uncontracted counting is sharp.

The third is a predicted blind spot. On $d$-regular graphs, the Ihara–Bass identity ties non-backtracking walk counts to the adjacency spectrum. Cycle-pattern locally injective counts should therefore fail exactly on cospectral regular pairs, the core of BREC's "Regular" category. We predict that non-cycle patterns, beginning with theta graphs (two vertices joined by three disjoint paths), are required there. We would derive their counts by dynamic programming over non-backtracking path counts between vertex pairs.

Research Program

The theoretical work has three parts. First, we prove the local-spasm decomposition and compute $\mathcal{L}(F)$ and $c_\pi$ for all patterns up to eight vertices. Second, we determine for which patterns the local spasm lies within the Nested Ear Decomposition classes of Zhang et al. That answers which existing architectures can already express which locally injective counts, and whether directed-edge message passing reaches any of them. Third, we produce a pattern-to-complexity table for counting locally injective maps from fixed patterns into degenerate graphs. Bressan and Roth explicitly leave open the homomorphism-counting dichotomy in degenerate graphs. The table is a concrete partial step on a sibling question, and we would state clearly which entries are proved and which conjectured.

The engineering work builds two encodings. One is node-level: rooted closed non-backtracking walk counts at each vertex up to length $K$. The other is graph-level: theta-pattern counts computed from non-backtracking path matrices. We would provide both as drop-in replacements for RWSE and MoSE inside the same GIN, MLP and Graph Transformer backbones those papers use.

The two research silos enter as the method for doing this work, not as a topic studied separately. Every imported result is restated with explicit orientation (pattern into graph versus graph into fixed target) and explicit parameter. That table is itself a deliverable, so the next learning paper does not misread a source-side hardness result.

Baselines

The naive reference point is a GIN with no structural encoding. On ZINC, Homomorphism Counts for GNNs: All About That Basis reports an MAE (mean absolute error) of 0.294 for it. We would rerun it in our pipeline to confirm we reproduce that number before any comparison.

The closest encoding baseline is RWSE, the random-walk return probabilities used in Graph Transformers. It is the most direct competitor because it is the backtracking-allowed version of our cycle features at identical cost. We would use the same walk lengths $K$, the same backbone and the same hyperparameter search budget. Beating it means a consistent error reduction across backbones on ZINC-12K and Peptides, with seeds' standard deviations reported.

The strongest encoding baseline on molecules is MoSE from Homomorphism Counts as Structural Encodings, which reports an MAE of 0.056 on ZINC-12K. We would run it with the authors' motif set and with a motif set restricted to the same compute time as ours. Matching 0.056 at lower preprocessing cost counts as a practical win; going below it with confidence intervals that do not overlap counts as beating it.

The strongest expressiveness baseline is the homomorphism basis of Jin et al. They report 76.25% on BREC with PPGN plus the basis and an MAE of 0.146 on ZINC for GIN plus the basis. Behind it sits I²-GNN at 70.2% on BREC. Among architectures, Local 2-FGNN reports an MAE of 0.023 on ZINC-Full and 0.003 on the eight-pattern counting benchmark in Beyond Weisfeiler-Lehman. We would compare against PPGN plus basis under identical BREC evaluation, meaning the paired-comparison protocol with the Hotelling test that BREC prescribes, and report per-category accuracy. Beating it in total is not required. What counts is matching it on the Basic and Extension categories at a fraction of the counting time, plus the Regular-category prediction holding in both directions.

The key ablation isolates local injectivity itself. It holds the pattern list fixed and feeds, separately, plain homomorphism counts, locally injective counts, the explicit local-spasm homomorphism vector, and subgraph counts. If the explicit local-spasm vector matches locally injective counts everywhere, then the contribution is cost and pattern reach, not new information. We would report it that way.

Why not just…?

Why not just use the full homomorphism basis of Jin et al.? By our own decomposition, locally injective counts are linear combinations of spasm homomorphism counts, so the basis is at least as expressive for the same patterns. The real question is cost and reach. For a long cycle, the spasm contains merged graphs whose counting cost grows with treewidth, while the non-backtracking computation stays polynomial. The experiment that settles this plots BREC and ZINC accuracy against preprocessing time at walk lengths 6 through 12 for both methods. If the basis reaches the same accuracy at comparable cost at those lengths, the proposal reduces to a theoretical placement result, and we would say so.

Why not just use RWSE, which is already cheap? This is the most serious threat. On regular graphs, Ihara–Bass makes backtracking and non-backtracking cycle counts informationally equivalent, so any gain must come from irregular graphs. Bao et al. show RWSE confuses Dinitrile and Morpholine because backtracking walks blur local degree structure. Removing backtracking is a direct, testable repair of that specific failure. The head-to-head on ZINC-12K, Peptides and the Basic category of BREC decides it. A null result there would mean non-backtracking adds nothing in practice.

Why not just add more motifs to MoSE or Deep Homomorphism Networks? Both enumerate pattern maps, which the Deep Homomorphism Networks paper itself notes costs $\Omega(n^k)$ on dense graphs and cannot reach long cycles without listing them. Bressan and Roth rule out efficient exact subgraph counting of long cycles even on sparse graphs. A compute-matched comparison on Peptides, where long-range cycles matter, shows whether the cheaper long-cycle signal is worth having.

Why not just use higher-order Weisfeiler-Lehman networks? They cost cubic time or more and still top out at 70.2% on BREC for I²-GNN, with near-zero accuracy on the CFI category of hard Weisfeiler-Lehman counterexamples. We do not expect our encodings to solve CFI either, and we would report that category honestly as out of reach.

Decisive Checks

Four checks decide the proposal. The first runs first and is cheap: verify numerically on random graphs that the local-spasm formula reproduces brute-force locally injective counts for all patterns up to eight vertices. If it fails, the theory is wrong.

The second is the BREC Regular-category prediction. Cycle-only features should score near the plain-homomorphism level on cospectral strongly regular pairs, and adding theta patterns should raise it. If cycle-only features do separate those pairs, our spectral argument is mistaken and needs revisiting. If theta patterns do not help, the non-cycle extension fails.

The third tests the same spectral argument on the older CSL dataset. Its circulant graphs differ in spectrum, so cycle features alone should solve it completely.

The fourth is the cost-matched head-to-head against RWSE, MoSE and the homomorphism basis on ZINC-12K, ZINC-Full, Peptides and the eight-pattern counting benchmark, together with a measured accuracy-versus-preprocessing-time curve. That curve, not a single leaderboard number, is the result we would stake the paper on.