async def do_cluster():
    app_state.generator = ClusterGenerator(dsm_mat=app_state.dsm)
    c_orig = app_state.generator.cluster(app_state.dsm)
    total_coord_cost = app_state.generator.total_coord_cost
    cost_history = app_state.generator.cost_history
    c = ClusterMatrix.reorder(c_orig)

    new_dsm = DSMMatrix.reorder_by_cluster(app_state.dsm, c)

    d_new_g = DSMMatrix.place_diag(new_dsm)
    app_state.cluster_result = c
    app_state.dsm_result = d_new_g
    app_state.dsm_annotated = DSMMatrix.annotate_clusters(d_new_g, c)

    return {
        "dsm": app_state.dsm_result.tojson(),
        "labels": app_state.dsm_result.labels,
        "cluster": app_state.cluster_result.tojson(),
        "dsm_a": app_state.dsm_annotated.tojson(),
    }
Exemple #2
0
    def test_place_diag(self):
        d_mat = np.array([[0, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 1, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 0, 1, 0],
                          [1, 0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0]])
        d_list = ["a", "b", "c", "d", "e", "f", "g", "h"]
        d = DSMMatrix(d_mat, activity_labels=d_list)

        d_diag = DSMMatrix.place_diag(d)

        d_mat_result = np.array([[1, 0, 1, 0, 0, 1, 0, 1],
                                 [1, 1, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 1, 1, 0, 0, 0, 1],
                                 [0, 0, 1, 1, 0, 0, 0, 1],
                                 [0, 0, 0, 0, 1, 1, 0, 0],
                                 [0, 1, 0, 0, 0, 1, 1, 0],
                                 [1, 0, 0, 1, 0, 0, 1, 0],
                                 [0, 0, 1, 0, 0, 0, 0, 1]])
        d_result = DSMMatrix(d_mat_result, activity_labels=d_list)

        assert np.equal(d_diag.mat, d_result.mat).all()