|
@@ -85,6 +85,15 @@ def make_densities(nb_clusters, centers=None, radius=None):
|
|
|
densities += make_gaussian(nb_clusters, center=c, radius=radius[n])
|
|
|
return densities
|
|
|
|
|
|
+def clean_densities(densities, clusters):
|
|
|
+ ''' clean density probability if a cluster is empty '''
|
|
|
+ densities = densities.flatten()
|
|
|
+ clusters = clusters.flatten()
|
|
|
+ for n, c in enumerate(clusters):
|
|
|
+ if c is None:
|
|
|
+ densities[n] = 0.0
|
|
|
+ return densities
|
|
|
+
|
|
|
# random generators
|
|
|
# ------------------
|
|
|
|
|
@@ -101,8 +110,6 @@ def rand_node_xy(nodes, clusters, densities):
|
|
|
clusters = clusters.flatten()
|
|
|
densities = densities.flatten()
|
|
|
cluster = np.random.choice(clusters, p=densities/sum(densities))
|
|
|
- while cluster is None:
|
|
|
- cluster = np.random.choice(clusters, p=densities/sum(densities))
|
|
|
node = cluster[np.random.randint(len(cluster))]
|
|
|
return (node.get('x'), node.get('y'))
|
|
|
|