Weisfeiler Leman Graph Isomorphism Test
   HOME

TheInfoList



OR:

In
graph theory In mathematics, graph theory is the study of ''graphs'', which are mathematical structures used to model pairwise relations between objects. A graph in this context is made up of '' vertices'' (also called ''nodes'' or ''points'') which are conne ...
, the Weisfeiler Leman graph isomorphism test is a heuristic test for the existence of an
isomorphism In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between them. The word is ...
between two
graphs Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discre ...
''G'' and ''H''. It is based on a normal form for graphs first described in an article by Weisfeiler and Leman in 1968. There are several versions of the test referred to in the literature by various names, which easily leads to confusion.


The basic Weisfeiler Leman graph isomorphism test

The basic version called WLtest takes a
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discre ...
as input, produces a partition of the nodes which is invariant under
automorphism In mathematics, an automorphism is an isomorphism from a mathematical object to itself. It is, in some sense, a symmetry of the object, and a way of mapping the object to itself while preserving all of its structure. The set of all automorphisms ...
s and outputs a string certificate encoding the partition. When applied to two graphs ''G'' and ''H'' we can compare the certificates. If the certificates do not agree the test fails and ''G'' and ''H'' cannot be isomorphic. If the certificates agree, ''G'' and ''H'' may or may not be isomorphic. The partition is produced in several rounds starting from the trivial partition where all nodes belong to the same component. In each round the partition is refined, which means that once two nodes are in different components they will also be in different components at future rounds. The partition refinement stops when the partition from the last round and the current partition are the same. This means that the refinement stops after n-1 rounds where ''n'' is the number of nodes in the graph. This is because the number of components need to grow by at least 1 in each step and the number of components cannot exceed ''n''. Membership of a node in a component is indicated by a label. In each round labels are recomputed and refined. After termination of the refinement, stringing together the labels after sorting yields the certificate. In order for isomorphic graphs to produce the same certificate one has to be very cautious with the labels because an isomorphism may swap nodes and may modify the order in which nodes are processed which in turn may alter the certificate. As an example the labels in the end may be 2-fold ''x'', a single ''y'' and 2-fold ''z'' for one graph and a 2-fold ''x'', 2-fold ''y'' and single ''z'' for an isomorphic graph yielding after sorting and stringing ''x_x_y_z_z'' resp. ''x_x_y_y_z''. One can be less careful with the labels, if one applies WLtest to a single graph created as the disjoint union of the two graphs ''G'' and ''H''. Applying to the disjoint union will ensure that both graphs are processed in parallel at each stage, which will avoid such a swap of labels, say ''x'' and ''y'' as in the example above. Additionally the parallel processing can distinguish even more pairs of non-isomorphic graphs, see the examples below. In what follows we will discuss this version WLpairs. The refinement of the partition in each step is by processing for each node its label and the labels of its nearest neighbors. Therefore WLtest can be viewed as a message passing algorithm.


Code

# ALGORITHM WLpairs # INPUT: two graphs G and H to be tested for isomorphism # OUTPUT: Certificates for G and H and whether they agree U = combineTwo(G, H) glabels = initializeLabels(U) # dictionary where every node gets the same label 0 labels = # dictionary that will provide translation from a string of labels of a node and its neighbors to an integer newLabel = 1 done = False while not(done): glabelsNew = # set up the dictionary of labels for the next step for node in U: label = str(glabels
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
+ str( labels[xfor_x_in_neighbors_of_node.html" ;"title=".html" ;"title="labels[x">labels[xfor x in neighbors of node">.html" ;"title="labels[x">labels[xfor x in neighbors of nodesort()) if not(label in labels): # a combination of labels from the node and its neighbors is encountered for the first time labels
abel Abel ''Hábel''; ar, هابيل, Hābīl is a Biblical figure in the Book of Genesis within Abrahamic religions. He was the younger brother of Cain, and the younger son of Adam and Eve, the first couple in Biblical history. He was a shepher ...
= newLabel # assign the string of labels to a new number as an abbreviated label newLabel += 1 # increase the counter for assigning new abbreviated labels glabelsNew
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
= labels
abel Abel ''Hábel''; ar, هابيل, Hābīl is a Biblical figure in the Book of Genesis within Abrahamic religions. He was the younger brother of Cain, and the younger son of Adam and Eve, the first couple in Biblical history. He was a shepher ...
if (number of different labels in glabels)

(number of different labels in glabelsNew): done = True else: glabels = glabelsNew.copy() certificateG = certificate for G from the sorted labels of the G-part of U certificateH = certificate for H from the sorted labels of the H-part of U if certificateG

certificateH: test = True else: test = False
Here is some actual
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
code which includes the description of the first examples. g5_00 = g5_01 = g5_02 = def combineTwo(g1, g2): g = n = len(g1) for node in g1: s = set() for neighbor in g1
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
s.add(neighbor) g
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
= s.copy() for node in g2: s = set() for neighbor in g2
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
s.add(neighbor + n) g ode + n= s.copy() return g g = combineTwo(g5_00, g5_02) labels = glabels = for i in range(len(g)): glabels = 0 glabelsCount = 1 newlabel = 1 done = False while not (done): glabelsNew = glabelsCountNew = 0 for node in g: label = str(glabels
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
s2 = [] for neighbor in g
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
s2.append(glabels eighbor s2.sort() for i in range(len(s2)): label += "_" + str(s2 if not (label in labels): labels
abel Abel ''Hábel''; ar, هابيل, Hābīl is a Biblical figure in the Book of Genesis within Abrahamic religions. He was the younger brother of Cain, and the younger son of Adam and Eve, the first couple in Biblical history. He was a shepher ...
= newlabel newlabel += 1 glabelsCountNew += 1 glabelsNew
ode An ode (from grc, ᾠδή, ōdḗ) is a type of lyric poetry. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structured in three majo ...
= labels
abel Abel ''Hábel''; ar, هابيل, Hābīl is a Biblical figure in the Book of Genesis within Abrahamic religions. He was the younger brother of Cain, and the younger son of Adam and Eve, the first couple in Biblical history. He was a shepher ...
if glabelsCount

glabelsCountNew: done = True else: glabelsCount = glabelsCountNew glabels = glabelsNew.copy() print(glabels) g0labels = [] for i in range(len(g0)): g0labels.append(glabels g0labels.sort() certificate0 = "" for i in range(len(g0)): certificate0 += str(g0labels + "_" g1labels = [] for i in range(len(g1)): g1labels.append(glabels[i + len(g0)]) g1labels.sort() certificate1 = "" for i in range(len(g1)): certificate1 += str(g1labels + "_" if certificate0

certificate1: test = True else: test = False print("Certificate 0:", certificate0) print("Certificate 1:", certificate1) print("Test yields:", test)


Examples

The first three examples are for graphs of
order Order, ORDER or Orders may refer to: * Categorization, the process in which ideas and objects are recognized, differentiated, and understood * Heterarchy, a system of organization wherein the elements have the potential to be ranked a number of d ...
5. WLpair takes 3 rounds on 'G0' and 'G1'. The test succeeds as the certificates agree. WLpair takes 4 rounds on 'G0' and 'G2'. The test fails as the certificates disagree. Indeed 'G0' has a cycle of length 5, while 'G2' doesn't, thus 'G0' and 'G2' cannot be isomorphic. WLpair takes 4 rounds on 'G1' and 'G2'. The test fails as the certificates disagree. From the previous two instances we already know G_1\cong G_0\not\cong G_2. Indeed ''G0'' and ''G1'' are isomorphic. Any isomorphism must respect the components and therefore the labels. This can be used for
kernelization In computer science, a kernelization is a technique for designing efficient algorithms that achieve their efficiency by a preprocessing stage in which inputs to the algorithm are replaced by a smaller input, called a "kernel". The result of solvi ...
of the graph isomorphism problem. Note that not every map of vertices that respects the labels gives an isomorphism. Let \varphi: G_0\rightarrow G_1 and \psi: G_0\rightarrow G_1 be maps given by \varphi(a)=D,\varphi(b)=C,\varphi(c)=B,\varphi(d)=E,\varphi(e)=A resp. \psi(a)=B,\psi(b)=C,\psi(c)=D,\psi(d)=E,\psi(e)=A. While \varphi is not an isomorphism \psi constitutes an isomorphism. When applying WLpair to ''G0'' and ''G2'' we get for ''G0'' the certificate ''7_7_8_9_9''. But the isomorphic ''G1'' gets the certificate ''7_7_8_8_9'' when applying WLpair to ''G1'' and ''G2''. This illustrates the phenomenon about labels depending on the execution order of the WLtest on the nodes. Either one finds another relabeling method that keeps uniqueness of labels, which becomes rather technical, or one skips the relabeling altogether and keeps the label strings, which blows up the length of the certificate significantly, or one applies WLtest to the union of the two tested graphs, as we did in the variant WLpair. Note that although ''G1'' and ''G2'' can get distinct certificates when WLtest is executed on them separately, they do get the same certificate by WLpair. The next example is about
regular graphs In graph theory, a regular graph is a Graph (discrete mathematics), graph where each Vertex (graph theory), vertex has the same number of neighbors; i.e. every vertex has the same Degree (graph theory), degree or valency. A regular directed grap ...
. WLtest cannot distinguish regular graphs of equal order, but WLpair can distinguish regular graphs of distinct
degree Degree may refer to: As a unit of measurement * Degree (angle), a unit of angle measurement ** Degree of geographical latitude ** Degree of geographical longitude * Degree symbol (°), a notation used in science, engineering, and mathematics ...
even if they have the same order. In fact WLtest terminates after a single round as seen in these examples of order 8, which are all 3-regular except the last one which is 5-regular. All four graphs are pairwise non-isomorphic. ''G8_00'' has two connected components, while the others do not. ''G8_03'' is 5-regular, while the others are 3-regular. ''G8_01'' has no 3-cycle while ''G8_02'' does have 3-cycles. Another example example of two non-isomorphic graphs that WLpair cannot distinguish is given
here Here is an adverb that means "in, on, or at this place". It may also refer to: Software * Here Technologies, a mapping company * Here WeGo (formerly Here Maps), a mobile app and map website by Here Television * Here TV (formerly "here!"), a TV ...
.


Applications

The theory behind the Weisfeiler Leman test is applied in graph neural networks.


Weisfeiler Leman graph kernels

In
machine learning Machine learning (ML) is a field of inquiry devoted to understanding and building methods that 'learn', that is, methods that leverage data to improve performance on some set of tasks. It is seen as a part of artificial intelligence. Machine ...
of nonlinear data one uses
kernels Kernel may refer to: Computing * Kernel (operating system), the central component of most operating systems * Kernel (image processing), a matrix used for image convolution * Compute kernel, in GPGPU programming * Kernel method, in machine learnin ...
to represent the data in a high dimensional feature space after which linear techniques such as
support vector machines In machine learning, support vector machines (SVMs, also support vector networks) are supervised learning models with associated learning algorithms that analyze data for classification and regression analysis. Developed at AT&T Bell Laboratorie ...
can be applied. Data represented as graphs often behave
nonlinear In mathematics and science, a nonlinear system is a system in which the change of the output is not proportional to the change of the input. Nonlinear problems are of interest to engineers, biologists, physicists, mathematicians, and many other ...
.
Graph kernel In structure mining, a graph kernel is a kernel function that computes an inner product on graphs. Graph kernels can be intuitively understood as functions measuring the similarity of pairs of graphs. They allow kernelized learning algorithms su ...
s are method to preprocess such graph based nonlinear data to simplify subsequent learning methods. Such graph kernels can be constructed by partially executing a Weisfeiler Leman test and processing the partition that has been constructed up to that point. These Weisfeiler Leman graph kernels have attracted considerable research in the decade after their publication. They are also implemented in dedicated libraries for graph kernels such as GraKeL. Note that
kernels Kernel may refer to: Computing * Kernel (operating system), the central component of most operating systems * Kernel (image processing), a matrix used for image convolution * Compute kernel, in GPGPU programming * Kernel method, in machine learnin ...
for
artificial neural network Artificial neural networks (ANNs), usually simply called neural networks (NNs) or neural nets, are computing systems inspired by the biological neural networks that constitute animal brains. An ANN is based on a collection of connected unit ...
in the context of
machine learning Machine learning (ML) is a field of inquiry devoted to understanding and building methods that 'learn', that is, methods that leverage data to improve performance on some set of tasks. It is seen as a part of artificial intelligence. Machine ...
such as
graph kernel In structure mining, a graph kernel is a kernel function that computes an inner product on graphs. Graph kernels can be intuitively understood as functions measuring the similarity of pairs of graphs. They allow kernelized learning algorithms su ...
s are not to be confused with
kernels Kernel may refer to: Computing * Kernel (operating system), the central component of most operating systems * Kernel (image processing), a matrix used for image convolution * Compute kernel, in GPGPU programming * Kernel method, in machine learnin ...
applied in heuristic algorithms to reduce the computational cost for solving problems of high complexity such as instances of
NP-hard In computational complexity theory, NP-hardness ( non-deterministic polynomial-time hardness) is the defining property of a class of problems that are informally "at least as hard as the hardest problems in NP". A simple example of an NP-hard pr ...
problems in the field of complexity theory. As stated above the Weisfeiler Leman test can also be applied in the later context.


See also

*
Graph isomorphism In graph theory, an isomorphism of graphs ''G'' and ''H'' is a bijection between the vertex sets of ''G'' and ''H'' : f \colon V(G) \to V(H) such that any two vertices ''u'' and ''v'' of ''G'' are adjacent in ''G'' if and only if f(u) and f(v) a ...
*
Graph neural network A graph neural network (GNN) belongs to a class of artificial neural networks for processing data that can be represented as Graph (abstract data type), graphs. In the more general subject of "geometric deep learning", certain existing neural ...


References

{{reflist Articles with example Python (programming language) code Graph theory