From 2529f101aaea8fb98eaa90f83c193739b6c7d18b Mon Sep 17 00:00:00 2001 From: Dhruv Kohli Date: Thu, 6 Aug 2026 19:51:19 -0700 Subject: [PATCH] bug fix in sequence of intermediate views, add spacing in clusters --- src/pyRATS/_utils.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pyRATS/_utils.py b/src/pyRATS/_utils.py index 3f15953..94af2b4 100755 --- a/src/pyRATS/_utils.py +++ b/src/pyRATS/_utils.py @@ -1115,13 +1115,13 @@ def target_proc(p_num): n_comp, comp_labels = connected_components(W, directed=False, return_labels=True) # Remove edges to force clusters if desired - if n_forced_clusters > n_comp: - inds = np.argsort(W.data)[-(n_forced_clusters - n_comp) :] - W.data[inds] = 0 - W.eliminate_zeros() - n_comp, comp_labels = connected_components( - W, directed=False, return_labels=True - ) + # if n_forced_clusters > n_comp: + # inds = np.argsort(W.data)[-(n_forced_clusters - n_comp) :] + # W.data[inds] = 0 + # W.eliminate_zeros() + # n_comp, comp_labels = connected_components( + # W, directed=False, return_labels=True + # ) if verbose: print("No. of connected components (manifolds):", n_comp) @@ -1172,7 +1172,7 @@ def target_proc(p_num): T, center_i, directed=False ) # (ignores edge weights) seq = views_in_this_comp[seq] - mask = rho_ > 0 + mask = rho_ >= 0 rho_[mask] = views_in_this_comp[rho_[mask]] rho = np.zeros(n_views, dtype=int) - 9999 rho[views_in_this_comp] = rho_ @@ -2080,9 +2080,14 @@ def add_spacing_between_clusters(y, seq_of_intermed_views_in_cluster, param, C): param.v[seq, 0] += offset - offset_ y[pts_in_cluster_i, 0] += offset - offset_ - # recompute the offset as the x coordinate of - # rightmost point of the current cluster - offset = 1.25 * np.max(y[pts_in_cluster_i, 0]) + # Calculate the width of the newly placed cluster + cluster_min = np.min(y[pts_in_cluster_i, 0]) + cluster_max = np.max(y[pts_in_cluster_i, 0]) + cluster_width = cluster_max - cluster_min + + # Next cluster starts at the current max edge plus a gap + # (e.g., 25% of the current cluster's width) + offset = cluster_max + (0.25 * cluster_width) return cluster_label