None
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
# Functions
def permute(M, P):
return P@(P@M).transpose()
def make_perm_matrix(l):
P = np.zeros((len(l),len(l)))
for i,j in enumerate(l):
P[i,j] = 1
P[j,i] = 1
return P
def drawmatrix(M):
plt.figure(np.random.randint(20000))
nx.draw(nx.Graph(M))
REMEMBER: DO NOT SOLVE PROBLEMS FOR THE ASSIGNMENT - AUTOMATICALLY CHECKING THE NUMBER OF AUTOMORPHISMS IS THE ASSIGNMENT!
Let P1 and P2 be two permutation matrices. Is P1 × P2 also a permutation matrix? Argue for or against your answer.
# Example:
A = np.array([[0,0,0,1],[0,1,0,0],[0,0,1,0],[1,0,0,0]])
B = np.array([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])
A@B
In general, yes. Consider P1 as an adjacency matrix of a graph instead. This graph has the property that every vertex has in- and out- degree exactly 1 (Permutation matrices have one '1' in each row and column). P2 now permutes this graph, but it still satisfies the same condition.
Corresponds to composing the permutations.
A = np.array([[0,1,1,1],[1,0,1,0],[1,1,0,1],[1,0,1,0]])
B = np.array([[0,1,1,0],[1,0,1,1],[1,1,0,1],[0,1,1,0]])
# Draw
plt.figure(1)
nx.draw(nx.Graph(A))
plt.figure(2)
nx.draw(nx.Graph(B))
Yes, the graphs are clearly isomorphic
GA are there?
All four nodes can be permuted, so 4! = 12
GB are there?
Ditto, 4! = 12
Yes, as they are clearly isomorphic
# Brute-force check all permutations of the two deg2 nodes and deg3 nodes (only 4 total)
print(make_perm_matrix([0,1,2,3])) #Trivial
print(make_perm_matrix([2,1,0,3]))
print(make_perm_matrix([0,3,2,1]))
print(make_perm_matrix([2,3,0,1]))
print('Permutation test')
print(permute( np.array([[1,2],[3,4]]), np.array([[0,1],[1,0]]) ))
#etc
A = np.array([[0,1,1],[1,0,1],[1,1,0]])
drawmatrix(A)
This is the only one!
All possible permutation matrices hold, as the graph is completely symmetric, 3! = 6
A = np.array([[0,1,1,0,0],[0,0,1,1,0],[0,1,0,1,0],[0,1,1,0,1],[0,0,0,1,0]])
drawmatrix(A)
Two different, vertices 1, 2 can be permuted
GA = np.array([[0,1,1,0],[1,0,1,0],[1,1,0,1],[0,0,1,0]])
drawmatrix(GA)
GB = np.array([[0,1,0],[1,0,1],[0,1,0]])
drawmatrix(GB)
Yes, clearly (both induced and not)
Need to make n(A) x n(B) matrix as a 'permutation matrix'
At least 4
The following is from the unit-testing of the graph theory assignment. Explain the expected result 10.
A = np.array([[ 0, 1, 0, 0, 1], \
[ 1, 0, 1, 0, 0], \
[ 0, 1, 0, 1, 0], \
[ 0, 0, 1, 0, 1], \
[ 1, 0, 0, 1, 0]])
drawmatrix(A)
Number of isomorphisms from/to itself.
10 automorphisms:
Use sigma aldrich https://www.sigmaaldrich.com/DK/en/structure-search to look for chemical structures. How many structures can you find which have the following as a substructure?
Good example of application - subgraph of LSD
A = np.array([[0,0,]])
A = np.array([[0,0,1,1,1],[0,0,0,1,1],[1,0,0,0,0],[1,1,0,0,1],[1,1,0,1,0]])
P = make_perm_matrix([0,1,2,4,3])
print(P)
drawmatrix(A)
B = P@(P@A).T
print(A)
print(B)
drawmatrix(B)
A = np.array([[ 0, 1, 0, 0, 1], \
[ 1, 0, 1, 0, 0], \
[ 0, 1, 0, 1, 0], \
[ 0, 0, 1, 0, 1], \
[ 1, 0, 0, 1, 0]])
drawmatrix(A)