Esempio n. 1
0
# %% [markdown]
# # Fitting divisive cluster model with GraspyGMM
name_base = f"-{cluster_type}-{embed_type}-{ptr_type}-{brain_type_short}-{GRAPH_TYPE}"

base = f"maggot_models/notebooks/outs/{FNAME}/objs/"
filename = base + "dc" + name_base + ".pickle"
clean_start = False
if os.path.isfile(filename) and not clean_start:
    print("Attempting to load file")
    with open(filename, "rb") as f:
        dc = pickle.load(f)
    print(f"Loaded file from {filename}")
else:
    print("Fitting DivisiveCluster model")
    start = timer()
    dc = DivisiveCluster(n_init=N_INIT, cluster_method=CLUSTER_METHOD)
    dc.fit(cluster_latent)
    end = end = timer()
    print()
    print(f"DivisiveCluster took {(end - start)/60.0} minutes to fit")
    print()
dc.print_tree(print_val="bic_ratio")
true_pred_labels = dc.predict(cluster_latent)
pred_labels = np.empty(shape=class_labels.shape, dtype="<U100")
pred_labels[nonsensory_inds] = true_pred_labels
pred_labels[sensory_inds] = sensory_labels

# %% [markdown]
# # Plotting and saving divisive cluster hierarchy results for GraspyGMM

stashobj(dc, "dc" + name_base)
Esempio n. 2
0
degrees = degrees[d_sort]
plt.figure(figsize=(10, 5))
sns.scatterplot(x=range(len(degrees)), y=degrees, s=30, linewidth=0)

known_inds = np.where(class_labels != "Unk")[0]

# %% [markdown]
# #
n_verts = adj.shape[0]
latent = lse(adj, n_components, regularizer=None, ptr=PTR)
pairplot(latent, labels=class_labels, title=embed)

# %% [markdown]
# #

dc = DivisiveCluster(n_init=200)
dc.fit(latent)
dc.print_tree()
linkage, labels = dc.build_linkage()
pred_labels = dc.predict(latent)

# %% [markdown]
# #
show_props = False
text_pad = 0.01

fig = plt.figure(figsize=(22, 20))
r = fig.canvas.get_renderer()
gs0 = plt.GridSpec(1, 2, figure=fig, width_ratios=[0.1, 0.9], wspace=0)
gs1 = plt.GridSpec(1, 1, figure=fig, width_ratios=[0.2], wspace=0.1)
ax0 = fig.add_subplot(gs0[0])
Esempio n. 3
0
left_latent = latent[left_inds, :]
right_latent = latent[right_inds, :]

base = f"maggot_models/notebooks/outs/{FNAME}/objs/"
filename = base + "dc" + name_base + ".pickle"
# clean_start = True
# if os.path.isfile(filename) and not clean_start:
#     print("Attempting to load file")
#     with open(filename, "rb") as f:
#         dc = pickle.load(f)
#     print(f"Loaded file from {filename}")
# else:
print("Fitting DivisiveCluster model")
start = timer()
left_dc = DivisiveCluster(n_init=N_INIT, cluster_method=CLUSTER_METHOD)
left_dc.fit(left_latent)
end = end = timer()
print()
print(f"DivisiveCluster took {(end - start)/60.0} minutes to fit")
print()
left_dc.print_tree(print_val="bic_ratio")

print("Fitting DivisiveCluster model")
start = timer()
right_dc = DivisiveCluster(n_init=N_INIT, cluster_method=CLUSTER_METHOD)
right_dc.fit(right_latent)
end = end = timer()
print()
print(f"DivisiveCluster took {(end - start)/60.0} minutes to fit")
print()
Esempio n. 4
0
pairplot(latent)

norm_latent = latent.copy()
norm_latent /= np.linalg.norm(latent, axis=1)[:, np.newaxis]
pairplot(norm_latent, labels=block_labels)

# %% [markdown]
# # Embedding
adj = graph
n_verts = adj.shape[0]
class_labels = block_labels

# %% [markdown]
# # Fitting divisive cluster model
start = timer()
dc = DivisiveCluster(n_init=N_INIT, cluster_method=CLUSTER_METHOD)
dc.fit(latent)
end = end = timer()
print()
print(f"DivisiveCluster took {(end - start)/60.0} minutes to fit")
print()
dc.print_tree(print_val="bic_ratio")
# %% [markdown]
# # Plotting divisive cluster hierarchy results

title = (
    f"Divisive hierarchical clustering, {cluster_type}, {embed_type}, {ptr_type},"
    + f" {brain_type}, {graph_type}"
)
class_labels = subblock_labels
name_base = f"-{cluster_type}-{embed_type}-{ptr_type}-{brain_type}-{graph_type}"