W = np.arange(1,17).reshape(4, 4)
G = graphs.Graph(W)
d = 4*np.ones([4])
dw = np.sum(W,axis=1).squeeze()
self.assertAlmostEqual(np.linalg.norm(G.d-d),0)
self.assertAlmostEqual(np.linalg.norm(G.dw-dw),0)
G = graphs.Sensor()
After Change
def test_degree(self):
W = 0.3 * (np.ones((4, 4)) - np.diag(4 * [1]))
G = graphs.Graph(W)
A = np.ones(W.shape) - np.diag(np.ones(4))
np.testing.assert_allclose(G.A.toarray(), A)
np.testing.assert_allclose(G.d, 3 * np.ones([4]))
np.testing.assert_allclose(G.dw, 3 * 0.3)