def distLapla(G):
n=G.order()
M=zero_matrix(RDF,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=-x
M[j,i]=-x
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
return M
def InvTransMatrix(G):
n=G.order()
M=zero_matrix(RDF,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=0
M[j,i]=0
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
for i in range(n):
M[i,i]=M[i,i]^(-1)
return M
def InvTransDistLapla(G):
M=InvTransMatrix(G)*distLapla(G)
return M
def distLaplaQQ(G):
n=G.order()
M=zero_matrix(QQ,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=-x
M[j,i]=-x
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
return M
def InvTransMatrixQQ(G):
n=G.order()
M=zero_matrix(QQ,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=0
M[j,i]=0
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
for i in range(n):
M[i,i]=M[i,i]^(-1)
return M
def InvTransDistLaplaQQ(G):
M=InvTransMatrixQQ(G)*distLaplaQQ(G)
return M
def distLaplaSR(G):
n=G.order()
M=zero_matrix(SR,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=-x
M[j,i]=-x
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
return M
def HalfInvTransMatrixSR(G):
n=G.order()
M=zero_matrix(SR,n,n)
for i in range(n):
for j in range(i+1,n):
x=G.distance(i,j)
M[i,j]=0
M[j,i]=0
M[i,i]=M[i,i]+x
M[j,j]=M[j,j]+x
for i in range(n):
M[i,i]=M[i,i]^(-1/2)
return M
def NormDistLaplaSR(G):
M=HalfInvTransMatrixSR(G)*distLaplaSR(G)*HalfInvTransMatrixSR(G)
return M