def test_plot2d_graph(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [2, 1], [5, 5], [7, 6]]) pregraph = knn_graph(df, 3) graph = pre_part_graph(pregraph, 10, df) plot2d_graph(graph)
def test_pre_part_graph(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [5, 5], [7, 2]]) k = 3 pregraph = knn_graph(df, k, verbose=False) _ = pre_part_graph(pregraph, 2, df, verbose=False) print(df["cluster"].values) assert (df["cluster"].values == np.array([0, 1, 1, 0, 0, 1, 1])).all()
def test_rebuild_labels(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [5, 5], [7, 2]]) pregraph = knn_graph(df, 3, verbose=False) _ = pre_part_graph(pregraph, 10, df, verbose=False) df_bis = rebuild_labels(df) assert sorted(list(df_bis["cluster"])) == [1, 1, 1, 1, 2, 2, 2]
def test_len_edges(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [5, 5], [7, 2]]) pregraph = knn_graph(df, 3, verbose=False) graph = pre_part_graph(pregraph, 10, df, verbose=False) condition0 = len_edges(graph, [0, 3, 4]) == 3 condition1 = len_edges(graph, [1, 2, 5, 6]) == 6 assert condition0 & condition1
def test_connecting_edges(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [5, 5], [7, 2]]) pregraph = knn_graph(df, 3, verbose=False) graph = pre_part_graph(pregraph, 10, df, verbose=False) assert connecting_edges(([0, 3, 4], [1, 2, 5, 6]), graph) == [ (0, 5), (3, 5), (4, 5), ]
def test_get_cluster(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [5, 5], [7, 2]]) k = 3 pregraph = knn_graph(df, 3, verbose=False) graph = pre_part_graph(pregraph, k, df, verbose=False) condition0 = get_cluster(graph, [0]) == [0, 3, 4] condition1 = get_cluster(graph, [k - 1]) == [1, 2, 5, 6] assert condition0 & condition1
def test_conn_comp(): df = pd.DataFrame([[1, 1], [6, 5], [6, 6], [0, 0], [1, 2], [2, 1], [5, 5], [7, 6]]) pregraph = knn_graph(df, 3) graph = pre_part_graph(pregraph, 10, df) res = conn_comp(graph) condition0 = sorted(res[0]) == [0, 3, 4, 5] condition1 = sorted(res[1]) == [1, 2, 6, 7] assert condition0 & condition1
def test_plot2d_data(): df = pd.DataFrame(make_blobs(60, random_state=42)[0]) knn = 6 pregraph = knn_graph(df, knn, verbose=False) graph = pre_part_graph(pregraph, 10, df, verbose=False) df, max_score, ci = merge_best(graph=graph, df=df, a=2, k=3, verbose=False, verbose2=False) plot2d_data(df)
def test_merge_best(): df = pd.DataFrame(make_blobs(60, random_state=42)[0]) knn = 6 pregraph = knn_graph(df, knn, verbose=False) graph = pre_part_graph(pregraph, 10, df, verbose=False) df, max_score, ci = merge_best(graph=graph, df=df, a=2, k=3, verbose=False, verbose2=False) condition0 = round(max_score) == 1 condition1 = ci == 5 assert condition0 & condition1