MCPcopy Create free account
hub / github.com/PythonOT/POT / get_sbm

Function get_sbm

examples/backends/plot_optim_gromov_pytorch.py:49–66  ·  view source on GitHub ↗
(n, nc, ratio, P)

Source from the content-addressed store, hash-verified

47
48
49def get_sbm(n, nc, ratio, P):
50 nbpc = np.round(n * ratio).astype(int)
51 n = np.sum(nbpc)
52 C = np.zeros((n, n))
53 for c1 in range(nc):
54 for c2 in range(c1 + 1):
55 if c1 == c2:
56 for i in range(np.sum(nbpc[:c1]), np.sum(nbpc[: c1 + 1])):
57 for j in range(np.sum(nbpc[:c2]), i):
58 if rng.rand() <= P[c1, c2]:
59 C[i, j] = 1
60 else:
61 for i in range(np.sum(nbpc[:c1]), np.sum(nbpc[: c1 + 1])):
62 for j in range(np.sum(nbpc[:c2]), np.sum(nbpc[: c2 + 1])):
63 if rng.rand() <= P[c1, c2]:
64 C[i, j] = 1
65
66 return C + C.T
67
68
69n = 100

Callers 1

Calls 3

sumMethod · 0.45
zerosMethod · 0.45
randMethod · 0.45

Tested by

no test coverage detected