|
@@ -85,6 +85,15 @@ def make_densities(nb_clusters, centers=None, radius=None):
|
|
densities += make_gaussian(nb_clusters, center=c, radius=radius[n])
|
|
densities += make_gaussian(nb_clusters, center=c, radius=radius[n])
|
|
return densities
|
|
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
|
|
# random generators
|
|
# ------------------
|
|
# ------------------
|
|
|
|
|
|
@@ -101,8 +110,6 @@ def rand_node_xy(nodes, clusters, densities):
|
|
clusters = clusters.flatten()
|
|
clusters = clusters.flatten()
|
|
densities = densities.flatten()
|
|
densities = densities.flatten()
|
|
cluster = np.random.choice(clusters, p=densities/sum(densities))
|
|
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))]
|
|
node = cluster[np.random.randint(len(cluster))]
|
|
return (node.get('x'), node.get('y'))
|
|
return (node.get('x'), node.get('y'))
|
|
|
|
|