Esempio n. 1
0
def run_fit(
    seed,
    n_components_try_range,
    n_components_try_rdpg,
    n_block_try_range,
    directed,
    n_sims_sbm,
):
    graph = load_drosophila_left()
    if not directed:
        graph = symmetrize(graph, method="avg")
    graph = binarize(graph)

    connected = is_fully_connected(graph)

    if not connected:
        heatmap(graph)
        plt.show()
        raise ValueError("input graph not connected")

    np.random.seed(seed)

    columns = columns = [
        "n_params_gmm",
        "n_params_sbm",
        "rss",
        "mse",
        "score",
        "n_components_try",
        "n_block_try",
        "sim_ind",
    ]
    sbm_master_df = pd.DataFrame(columns=columns)
    for i in range(n_sims_sbm):
        sbm_df = select_sbm(graph,
                            n_components_try_range,
                            n_block_try_range,
                            directed=directed)
        sbm_df["sim_ind"] = i
        sbm_master_df = sbm_master_df.append(sbm_df,
                                             ignore_index=True,
                                             sort=True)

    rdpg_df = select_rdpg(graph, n_components_try_rdpg, directed)

    def metric(assignments, *args):
        return -compute_mse_from_assignments(
            assignments, graph, directed=directed)

    tsbm_master_df = select_sbm(
        graph,
        n_components_try_range,
        n_block_try_range,
        directed=directed,
        method="bc-metric",
        metric=metric,
    )
    return (sbm_master_df, rdpg_df, tsbm_master_df)
Esempio n. 2
0
def run_fit(
    seed,
    n_components_try_range,
    n_components_try_rdpg,
    n_block_try_range,
    directed,
    n_sims_sbm,
):
    graph = load_drosophila_left()
    if not directed:
        graph = symmetrize(graph, method="avg")
    graph = binarize(graph)

    connected = is_fully_connected(graph)

    if not connected:
        heatmap(graph)
        plt.show()
        raise ValueError("input graph not connected")

    np.random.seed(seed)

    columns = columns = [
        "n_params_gmm",
        "n_params_sbm",
        "rss",
        "mse",
        "score",
        "n_components_try",
        "n_block_try",
        "sim_ind",
    ]
    sbm_master_df = pd.DataFrame(columns=columns)
    for i in range(n_sims_sbm):
        sbm_df = select_sbm(
            graph,
            n_components_try_range,
            n_block_try_range,
            directed=directed,
            rank="sweep",
        )
        sbm_df["sim_ind"] = i
        sbm_master_df = sbm_master_df.append(sbm_df,
                                             ignore_index=True,
                                             sort=True)

    save_obj(sbm_master_df, file_obs, "sbm_master_df")
    return 0
Esempio n. 3
0
def run_fit(seed, n_components_try_range, n_components_try_rdpg,
            n_block_try_range, directed):
    graph = load_drosophila_left()
    if not directed:
        graph = symmetrize(graph, method="avg")
    graph = binarize(graph)

    connected = is_fully_connected(graph)

    if not connected:
        heatmap(graph)
        plt.show()
        raise ValueError("input graph not connected")

    np.random.seed(seed)

    sbm_df = select_sbm(graph,
                        n_components_try_range,
                        n_block_try_range,
                        directed=directed)
    rdpg_df = select_rdpg(graph, n_components_try_rdpg, directed)
    return (sbm_df, rdpg_df)
Esempio n. 4
0
# %% [markdown]
# # Imports
from src.graph import MetaGraph
from src.data import load_networkx
from graspy.utils import is_fully_connected

# %% [markdown]
# # Constants
BRAIN_VERSION = "2019-12-18"
GRAPH_TYPE = "Gad"
# %% [markdown]
# # Loads
g = load_networkx(GRAPH_TYPE, BRAIN_VERSION)
mg = MetaGraph(g)

# %% [markdown]
# # Show that getting LCC works
print(is_fully_connected(mg.g))
print(mg.n_verts)
print(mg.meta.shape)
print()
mg = mg.make_lcc()
print(is_fully_connected(mg.g))
print(mg.n_verts)
print(mg.meta.shape)

# %% [markdown]
# #
#%%
graph_types = ["Gaan", "Gadn", "Gdan", "Gddn"]
n_components = 4

# load the right side
use_graph = "Gn"
hemisphere = "right"
print(f"Using graph {use_graph}")
Gn = load_graph(use_graph)
Gn = get_subgraph(Gn, "Hemisphere", hemisphere)
n_verts_original = len(Gn)
print(f"Selected {hemisphere} side")

print("Checking if graph is fully connected")
print(is_fully_connected(Gn))
Gn, inds = get_lcc(Gn, return_inds=True)
num_removed = n_verts_original - len(Gn)
print(f"Removed {num_removed} node")

# select metadata
classes = meta_to_array(Gn, "Class")
simple_classes = to_simple_class(classes)
names = meta_to_array(Gn, "Name")
ids = meta_to_array(Gn, "ID")

# load adjacency and preprocess
Gn_adj = import_graph(Gn)
Gn_adj = remove_loops(Gn_adj)
# Gn = pass_to_ranks(Gn)
Gn_adj = binarize(Gn_adj)