예제 #1
0
def test_filtrations_d5(flag_file, filtration):
    """Test all filtrations available for dataset d5.flag, see conftest.py"""
    adjacency_matrix = load_weighted_flag(flag_file, fmt='coo')
    res = flagser_weighted(adjacency_matrix, max_dimension=1,
                           directed=False, filtration=filtration)
    for filt, tests in filtrations_results.items():
        if filtration == filt:
            tmp = res["dgms"]
            tmp2 = tests["dgms"]
            assert are_matrices_equal(tmp, tmp2), \
                "Diagrams {} \n and {} \n are not equal"\
                .format(tmp, tmp2)
예제 #2
0
    def _flagser_diagram(self, X):
        Xdgms = flagser_weighted(X,
                                 max_edge_weight=self.max_edge_weight,
                                 min_dimension=self._min_homology_dimension,
                                 max_dimension=self._max_homology_dimension,
                                 directed=self.directed,
                                 filtration=self.filtration,
                                 coeff=self.coeff,
                                 approximation=self.max_entries)['dgms']

        if 0 in self._homology_dimensions:
            Xdgms[0] = Xdgms[0][:-1, :]  # Remove final death at np.inf

        return Xdgms
def top_summary(graphs,dim = 7,approx = None):
    '''
    graphs: list of networkx directed graphs
    dim: maximum dimension to calculate Betti numbers and simplex counts
    approx: integer that determines the approximation used in pyflagser
    This function returns a list containing the Betti numbers up to dimension dim
    and another list containing the simplex counts up to dimension dim
    '''
    list_Betti = []
    list_simplex = []
    i = 0
    print('Generating Topological Summary')
    for g in graphs:
        resbetti = np.zeros((dim,))
        rescell = np.zeros((dim,))
        G_matrix = nx.to_scipy_sparse_matrix(g) #returns scipy sparse matrix
        out = pf.flagser_weighted(G_matrix + sp.sparse.identity(nx.number_of_nodes(g)),
                                min_dimension=0,
                                max_dimension=dim,
                                directed=True, approximation= approx)
        betti = out['betti']
        cell_count = out['cell_count']
        for i in range(dim):
            if i < len(betti):
                resbetti[i] = betti[i]
            else:
                resbetti[i] = 0

        for i in range(dim):
            if i < len(cell_count):
                rescell[i] = cell_count[i]
            else:
                rescell[i] = 0
        list_Betti.append(resbetti)
        list_simplex.append(rescell)
    return(np.array(list_Betti), np.array(list_simplex))
예제 #4
0
def test_higher_coefficients():
    """Regression test for issue #45"""
    x = np.random.random((5, 5))
    np.fill_diagonal(x, 0.)
    flagser_weighted(x, coeff=3)