def generate():
no_edges = 5+4+3+2+1
weights = np.array([random.uniform(-999999,999999) for i in range(no_edges)])
normalised = np.multiply((no_edges)/(sum(weights)), weights)
while sum(normalised) != no_edges:
weights = np.array([random.uniform(-999999,999999) for i in range(no_edges)])
normalised = np.multiply((no_edges)/(sum(weights)), weights)
return(normalised)
def data_point(weight):
matrix = np.zeros((6,6))
for i in range(6):
for j in range(6):
if i != j:
matrix[i,j] = weight[i+j]
d = []
for i in range(0,len(matrix)):
d = np.append(d, np.sum(matrix[i,:]))
L = np.diag(d) - matrix
eigenvalues = LA.eig(L)[0]
eigenvalues = np.around(eigenvalues,2)
Dw = sum(abs(weight-1))
return [Dw, eigenvalues[1]]
I am trying to create a balanced weighted graph with 6 vertices. Since it is balanced the weights must add up to the total number of edges, i.e. 15. (Note it is an undirected graph)
Also note that the weight can be any real number. So I have come up with a code to generate weights. But when I was calculated the Laplacian, some of my eigenvalues are negative but I thought that since the Laplacian is positive semi-definite it cannot have negative eigenvalues. I don't understand where my code doesn't work. Can someone please help?
Thank you!
I want my eigenvalues to be greater than or equal to 0 but I am getting some eigenvalues as negative which should not be the case for the Laplacian