Exact polynomial-time graph canonisation and isomorphism testing through comparison of ordered vertex eigenprojections

Motivation Graph canonisation and isomorphism testing representation are fundamental computational problems, whose complexity has remained unsolved to date. This study examines graph eigenprojections, demonstrating that linear-ordering transformations induce canonical properties therein to yield polynomial-time canonisation and isomorphism testing in all undirected graphs. Results This study presents an exact method to identify analogous vertices in isomorphic graphs, through comparison of vertices’ eigenprojection matrices, which are shown to be related by a linear permutation. Systematic perturbation strategies are developed to reduce degeneracy whilst conserving isomorphism, through the addition of characteristically weighted self-loops to analogous vertices. Repeated iterations of analogy testing and perturbation deliver canonical vertex labelling and recovery of isomorphic mappings in ℴ(n4) time in all graphs. Analytical proofs are provided to support claims and experimental performance is demonstrated in biological and synthetic data, with comparison to a commonly used heuristicalgorithm. Availability and Implementation Source code is provided at github.com/robertoshea/graph_isomorphism. Contact robert.1.oshea@kcl.ac.uk Supplementary Data Not applicable.


Introduction
The graph isomorphism problem requires the determination of structural equivalence of two graphs.
It is considered one of the most important unresolved problems in computer science (Grohe and Schweitzer, 2020) and arises in applications across the domains of image recognition, systems biology and cheminformatics (Grohe and Schweitzer, 2020). Although the problem's computational complexity has remained an open problem since its description in 1972 (Karp, 1972;Grohe and Schweitzer, 2020), it has been demonstrated that it is in the low hierarchy of the class NP (Schöning, 1988;Arvind and Torán, 2005). Graph canonisation is a closely related task, which requires graph representation in a form which is invariant under permutation and characteristic of the graph automorphism group. Thus, isomorphism testing may also be achieved by representing both graphs in canonical form and checking equality.
Exact polynomial time algorithms are available for some special cases of the graph isomorphism problem. Babai proposed a spectral assignment algorithm for graphs with bounded eigenvalue multiplicity (Babai et al., 1982). Luks proposed an algorithm for graphs of bounded degree (Luks, 1982) which was developed further by Babai to provide a quasipolynomial-time solution for the general case (Babai, 2016;Helfgott et al., 2017). Klus and Sahai developed a heuristic spectral assignment algorithm for degenerate graphs, in which vertex analogy is estimated by comparing vertex eigenpolytopes (Klus and Sahai, 2018). A graph perturbation strategy was introduced in which pairs of analogous vertices were sought and perturbations applied to induce unique analogies. Analogous vertices were estimated by sorting individual rows of vertices' eigenprojection matrices and subsequently testing equality. As the algorithm was not constrained to apply the same sorting permutation to each row, equality could be induced between some non-analogous vertex pairs, yielding false positives. Subsequently, when perturbations were erroneously applied to non-analogous vertex pairs, "backtracking" was required (Klus and Sahai, 2018). No exact polynomial-time algorithm has been identified for the general case graph isomorphism problem to date (Grohe and Schweitzer, 2020;Klus and Sahai, 2018).

Hypothesis and Objectives
It was hypothesised that Klus' heuristic could be developed into an exact method by modifying the ir analogy testing and perturbation strategies. It was hypothesised that a linear permutation would induce equality between analogous vertices' eigenprojection matrices, which would suffice to demonstrate analogy. The objective of this study is to prove this result and employ it to develop exact polynomial-time algorithms for graph canonisation and isomorphism testing. Accordingly, an exact method is developed to identify analogous vertex pairs through comparison of vertices' eigenprojection matrices. Klus' perturbation strategy is developed to reduce degeneracy in a canonically reproducible manner, conserving isomorphism of perturbed graph tuples by perturbing pairs of analogous vertices. Theoretical analysis is provided to support these claims and experimental performance is demonstrated in real and synthetic data.

Preliminaries and notation
Let denote the symmetric group of degree and denote the set of × dimensional permutation. Let ∈ and ∈ denote corresponding vector and matrix representations of the same permutation, such that: Throughout the article, vector and matrix representation of permutation functions will be used interchangeably.

Definition.
A permutation ∈ is termed an "isomorphic mapping" from to if it satisfies: ( ( ) , ( ) ) ∈ ℰ ⇔ ( , ) ∈ ℰ Equivalently, ∈ is termed an isomorphic mapping from to if it satisfies = . This is denoted : → . Likewise, a permutation ∈ is termed an isomorphic mapping from to if it satisfies: It is emphasised here that the double right arrow "⇒" will be used to denote implication of the right statement by the left., which is distinct from the single left-right arrow "→" used to denote function mappings.
Definition. "Analogy" of the th vertex in to the th vertex in , implies that there exists some ̂∈ such that ̂: → and ̂( ) = . This is denoted ( ) ↔ ( ). Likewise, ( ) ↔ ( ) implies that there exists some ̂∈ such that ̂: → and ̂( ) = . It is emphasised here that the double left-right arrow "⇔" will be used to denote equivalence of statements, which is distinct from the single left-right arrow "↔" used to denote analogy.

Definition.
A "unique analogy" of the th vertex in to the th vertex in implies that: If = and = then: Unique analogy of the th vertex in to the th vertex in is denoted ( ) ↔ ( ).
Definition. The "automorphism group" of , denoted Aut( ) is the set of all graphs satisfying ≅ .
Thus, we have: Definition. Let ( ) ( ) ∈ ℝ denote the th column of ( ) , representing the projection of the th vertex onto the th eigenspace. The matrix of a vertex's projections onto each eigenspace is termed the "vertex eigenprojection". ( ) ∈ ℝ × denotes the th vertex eigenprojection in , such that: Definition. For some matrix ∈ ℝ × , let ∈ be a row-permutation matrix satisfying: Thus, pre-multiplication by orders rows in ascension by the first column, then the second , then the third etc, resolving ties in former columns by elements of latter columns. It is noted that may have multiple solutions if some rows are identical. Let ∈ denote the permutation vector corresponding to .
Definition. The row-permutation of a vertex eigenprojection under is termed the "ordered vertex eigenprojection". The th ordered vertex eigenprojection in is given by ( ( )).

Definition.
Let ∈ ℝ × denote the matrix of ordered vertex eigenprojections in vectorised form, such that the th row, ( ) ∈ ℝ , is given by: Let denote the -dimensional identity matrix. Let 1 denote an × 1 column of ones and let 1 × denote a matrix of ones.

Algorithm Overview
This study presents an exact method to identify analogous vertices in isomorphic graphs, through modification of Klus' algorithm. It is demonstrated that the ordered eigenprojections of analogous vertices are equal. Furthermore, it is demonstrated that equality of ordered vertex eigenprojections implies analogy of vertices. These results may be exploited to test analogy of any vertex pair. An isomorphism-preserving perturbation strategy is introduced, in which pairs of analogous vertices are perturbed with characteristically weighted self-loops, inducing uniqueness of their analogy. The steps of analogy-testing and perturbation may be iterated until all analogies in the perturbed graphs are unique. It is demonstrated that fewer than iterations are required to infer an isomorphic 8 mapping in this way. Thus, isomorphic mappings may be extracted in ℴ( 4 ) time. Two algorithms are presented to infer mappings between isomorphic graph tuples. In the first algorithm, graphs are perturbed simultaneously. In the second algorithm, the procedure is optimised by iteratively generating canonical orderings for each graph, reducing the number of vertex analogy tests required.

Analogy Testing
When searching for an isomorphic mapping between two graphs, it is appropriate to presume graphs are isomorphic, and test this assumption when a candidate isomorphic mapping has been identified. Accordingly, we let ≅ . Lemma 1 demonstrates that is invariant to choice of eigenbasis, even when spectra are degenerate.

Proof
We have: As Λ is diagonal, it may be decomposed by eigenspace, such that: Removing , we have: Substituting the definition of ( ) and ( ) , we have:

End of lemma 1
Hence, the projections ( ) and ( ) are related by the same isomorphic mapping as and , such that: for all ∈ {1, … , }. Thus, we have: Likewise, we have: Lemma 2 demonstrates that the eigenprojection matrices of analogous vertices are related by a row-permutation.

Proof
From Lemma 1 we have: Extracting from each eigenspace we have: Substituting the vertex permutation, we have: Applying to each eigenspace ∈ {1, … , }:

End of lemma 2
The linearly permuted relationship between analogous vertices' eigenprojections allows reframing of the analogy detection task as a linear assignment problem. However, as may be underdefined, it may be not deducible from this equation alone. This issue may be circumvented by applying the row-sorting function to the vertex eigenprojections, neutralising the row-permutation effect of .
Lemma 3 demonstrates that induces equality between any two row-permutations of a matrix.

Proof
We have: Multiplying internally by , we have: Factorising by ( ), it is evident that is a solution to . Letting = , and multiplying from the right by , we have: = Thus: = Substituting for the definitions of ( ) and ( ), we have:

End of lemma 4a
Lemma 4b demonstrates that if ≅ , then equality of ordered vertex eigenprojections implies analogy of the corresponding vertices, such that:

End of lemma 4b
Thus, equality of ( ( )) and ( ( )) determines analogy of the corresponding vertices, such that: This result implies that the row-ordered vertex eigenprojections may be used to identify analogous vertex pairs, without inferring . Thus, the vertex analogy testing problem is linearised exactly, providing a polynomial time route to extract an isomorphic mapping ̂: → .
At this point, a critical distinction from Klus' method must be noted (Klus and Sahai, 2018). Klus sorted the columns of ( ) separately, such that the ordered vertex eigenprojection was given by: Consequently, different permutations may be applied to each column, so that the vertex eigenprojection and its ordered image may not be related by a linear permutation. Clearly, Klus' ordering transformation maps analogous vertices to equal ordered vertex eigenprojections, such that: However, the converse does not hold, as Klus' method may also map some non-analogous vertices to the same ordered vertex eigenprojection if the columns of their eigenprojections can be sorted equally. Therefore: ( ) ( ( )) = ( ) ( ( ( ) )) ⇏ ( ) ↔ ( ) We now return to the description of our method. As ( ) = ( ( ( ))), equality of ( ) and ( ) may also be employed to test analogy of ( ) and ( ). By applying a second rowordering transformation to and it is observed that they are brought into a matrix form, ( ), which is invariant to graph permutation. Lemma 5 demonstrates that ( ) is a permutation invariant representation of Aut( ).

Constructing the isomorphic mapping
Now that individual vertex analogies may be identified, the problem of constructing the isomorphic mapping from individual analogies is addressed. A precursor to the permutation matrix, ̌∈ {0,1} × , may be generated by testing each vertex pair for analogy, such that:

̌≔ ( ( ) ↔ ( ))
If the solution to is unique, each vertex has only one analogy and ̌= . However, if multiple isomorphisms exist, some vertices will have multiple analogies and ̌∉ . To resolve this issue, analogy-preserving perturbations must be applied to and to induce uniqueness to the isomorphic mapping. Let * , * ∈ ℝ × denote the perturbed matrices. Let ( ) ↔ ( ).
and may be perturbed at and to generate isomorphic matrices * and * with a unique isomorphism * ( ) ↔ * ( ).

End of lemma 7.
Here, a subtle distinction from Klus' perturbation strategy is noted. Klus also perturbed graphs through the addition of self-loops, which were weighted ∈ ℕ at the th iteration. This strategy does not guarantee induction of a unique analogy as identical self-loops may already exist on other vertices. By weighting the new self-loop as (1 + max( )) uniqueness is guaranteed.
If a non-uniquely analogous vertex pair is perturbed in this way, a unique analogy is induced and the number of isomorphisms is thereby reduced. Vertex analogies may now be checked in the perturbed matrices * and * , such that:

̌≔ ( * ( ) = * ( ))
If * and * remain degenerate, other non-uniquely analogous vertex pairs may be sought in the perturbed graphs. Thus, perturbations may be applied iteratively, such that: * +1 ≔ * + ( ) • (1 + max( * ) − * ) * +1 ≔ * + ( ) • (1 + max( * ) − * ) where * and * denote the graphs after ∈ ℕ perturbation iterations and , ∈ such that * ( ) ↔ * ( ). Naively, analogies could be sought, and perturbations applied for each vertex in turn. After − 1 iterative perturbations, each entry on the perturbed matrix diagonals would be distinct, implying that any solution to ̂: * → * would be unique. However, if some vertices already have unique analogies, these need not be perturbed. Thus, fewer than iterations are required to induce a unique isomorphism between * and * . This procedure constitutes Algorithm 1, a naïve approach which is included here to aid understanding. Now the task of graph canonical labelling is addressed. From lemma 1 it is known that is invariant to . Likewise, for all ∈ the ordered vertex eigenprojections ( ) remain invariant across the permutation group of . Thus, vertices ( ) and ( ) may be ordered canonically by ( ) and ( ) if ( ) ↮ ( ). However, analogous vertices cannot be ordered canonically in this manner, as ( ) = ( ) iff ( ) ⟷ ( ). Therefore, using the ordered eigenprojections, vertices may only be ordered up to analogy. This result is consistent with our definition of analogy, which implies equivalence of analogous vertices under permutation. Hence, uniqueness of the canonical ordering requires that no analogous vertices exist within the graph. Thus, a perturbation strategy must be implemented to order vertices canonically. This is achieved by partially ordering the vertices according to the row-ordering of , then applying a perturbation to the first vertex in the ordering with an analogy. It is observed that, as analogous vertices are identified by identical rows in , that any non-random row-ordering operation will assign adjacent order positions to analogous vertices. Thus, it is guaranteed that no analogy will be missed if only rows with adjacent order positions are tested. This procedure constitutes Algorithm 2, which dominates Algorithm 1 in terms of computational efficiency, as fewer analogy tests are required.

Algorithm 1
In algorithm 1, the ordered vertex eigenprojection matrices are extracted for both graphs and every vertex pair is compared. If vertices have multiple analogies, one of the non-uniquely analogous pairs is selected and a characteristic perturbation applied to both vertices. This concludes the first iteration. Ordered vertex eigenprojection matrices may now be extracted from the perturbed graphs and further perturbation are applied in this manner until no vertices remain with multiple analogies.

Implementation
The performance of algorithm 2 was tested on real-word and synthetic graphs. Real-world graphs were extracted from a public repository of brain networks (Amunts et al., 2013;Rossi and Ahmed, 2015). As regularly structured synthetic graphs present some of the most challenging problems for traditional algorithms (Babai et al., 1982), a 100-vertex ring graph and Johnson graphs (Holton and Sheehan, 1993) with parameters (n=9, k=4) and (n=10, k=3) were also included. In each experiment, a permutation was applied to one of the graphs to generating a tuple of isomorphic graphs. The algorithm was subsequently applied to infer an isomorphic mapping. Computation was performed with R and RStudio using iGraph and abind libraries (R Core Team, 2021;RStudio Team, 2021;Csardi and Nepusz, 2006;Plate and Heiburger, 2016). Algorithm 2 was employed to infer isomorphic mappings. To minimise discrepancies between matrix eigenvalues due to numerical fuzz, the presumption of isomorphism was invoked, and eigenvalues of both matrices were averaged. This procedure is permissible if isomorphism is formally tested later through validation of the isomorphic mapping. A numerical tolerance of 10 −10 was applied when testing equality of eigenvalues and eigenvectors, respectively. All code required to reproduce the findings of this study is provided at github.com/robertoshea/graph_isomorphism. The BLISS canonical labelling algorithm (Junttila and Kaski, 2007) was included for comparison, via iGraph. Experiments were conducted on a standard laptop with 16Gb RAM and an Intel Core i7 CPU.

Results
Algorithm 2 identified a correct isomorphic mapping in each experiment ( applied to the input graph and each algorithm was applied to infer an isomorphic mappings.
Algorithm 2 was employed for Eigenprojection Ordering. BLISS iterations were not provided by the implementation used.

Discussion
This analysis unifies the problems of graph canonisation and isomorphism testing via the tensor of eigenprojections. It is demonstrated that the ordered vertex eigenprojections provide a signature by which vertex analogy may be tested. By reshaping the ordered vertex eigenprojections into a matrix structure and applying a second ordering, a permutation invariant graph representation ( ) is achieved. This result is consistent with the quadratic nature of the problem -that two ordering operations should be required to recover the equivalence broken by two permutation operations. It is conjectured that this representation is unique to ( ), and is therefore a canonical form. This hypothesis is supported by the observation that equality of ( ) and ( ) implies that every vertex in has an analogy in and vice versa. Correctness of this hypothesis would imply that ( ) is invariant over Aut( ) and unique to Aut( ), fulfilling the requirements of a canonical representation. Therefore, if this conjecture was proven correct, isomorphism testing could proceed in ℴ( 3 ) time through equality testing of ( ) and ( ). Analysis of this conjecture is left for further research.
This study demonstrates that a graph with analogous vertices may be labelled canonically through repeated iterations of partial ordering and perturbation. As such iterations may be required, this algorithm guarantees canonical vertex labelling in ℴ( 4 ) time. Algorithm 2 dominates algorithm 1, by ordering vertices such that analogous vertices are assigned adjacent positions in the ordering.
Consequently, analogy tests are only required between vertices with adjacent positions in the ordering. Thus, − 1 analogy tests are required to demonstrate uniqueness of each vertex in algorithm 2, compared with 2 − in algorithm 1.
The algorithms described in this paper assume that the graph is undirected. If the graph is directed, the adjacency matrix may be asymmetric and uniqueness of the tensor of eigenprojections is not guaranteed. The extension of these algorithms to directed graphs is left for further research. The algorithms do not require any spectral conditions, such as positive definiteness or bounded eigenvalue multiplicity. Where multiple isomorphic mappings exist, a single solution to ̂ is returned, however the full set of solutions may also be computed by changing the order of perturbations.
As the algorithm tests equality of eigenvalues and elements of eigenprojections, numerical stability issues are expected (Klus and Sahai, 2018). This is a critical limitation of the above algorithms to practical graph isomorphism problems. In some cases, numerical stability may be achieved through appropriate rounding or numerical tolerance. However, errors are likely in large graphs with similar eigenvalues. To assess the suitability of the algorithm for a particular use case it is recommended to perform simulations by duplicating one of the graphs, permuting it and attempting to recover an isomorphic mapping. This procedure may also be used to optimise numerical tolerance settings.
The algorithm presented here demonstrates that any problem which may be reduced to a graph isomorphism problem may be solved in polynomial time. Further research will investigate developments to the algorithm to solve the subgraph isomorphism problem and the general casequadratic assignment problem in polynomial time.