Beispiel #1
0
    def threshold(self, cost, mst=True):
        '''
        Create a binary graph by thresholding weighted BrainNetwork G

        First creates the minimum spanning tree for the graph, and then adds
        in edges according to their connection strength up to cost.

        Parameters
        ----------
        cost : float
            A number between 0 and 100. The resulting graph will have the
            ``cost*n/100`` highest weighted edges from G, where
            ``n`` is the number of edges in G.
        mst : bool, optional
            If ``False``, skip creation of minimum spanning tree. This may
            cause output graph to be disconnected

        Returns
        -------
        :class:`BrainNetwork`
            A binary graph

        Raises
        ------
        Exception
            If it is impossible to create a minimum_spanning_tree at the given
            cost

        See Also
        --------
        :func:`threshold_graph`
        '''
        return threshold_graph(self, cost, mst=True)
Beispiel #2
0
def test_threshold_graph_mst_false():
    G1 = mkg.threshold_graph(simple_anatomical_graph(), 30, mst=False)
    G2 = nx.Graph()
    G2.add_nodes_from(G1.nodes)
    G2._node = simple_anatomical_graph()._node
    G2.add_edge(0, 2)
    assert nx.is_isomorphic(G1, G2, edge_match=em(), node_match=nm())
Beispiel #3
0
def test_graph_at_cost_array():
    G1 = mkg.graph_at_cost(symmetric_matrix_1(), 70)
    G2 = mkg.threshold_graph(simple_weighted_graph(), 70)
    assert nx.is_isomorphic(G1, G2, edge_match=em())
Beispiel #4
0
def test_threshold_graph_mst_too_large_exception():
    with pytest.raises(Exception):
        mkg.threshold_graph(simple_weighted_graph(), 30)