How to use the ripser.Rips function in ripser

To help you get started, we’ve selected a few ripser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_verbose_false(self):
        data = np.array([[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0]])
        rips = Rips(verbose=False)
        dgm = rips.fit_transform(data)
        assert dgm[0].shape == (4,2)
        assert dgm[1].shape == (1,2)
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_maxdim(self):
        np.random.seed(3100)
        data = np.random.random((100, 3))

        # maxdim refers to the max H_p class, generate all less than

        rips0 = Rips(maxdim=0)
        dgm0 = rips0.fit_transform(data)
        assert len(dgm0) == 1

        rips1 = Rips(maxdim=1)
        dgm1 = rips1.fit_transform(data)
        assert len(dgm1) == 2

        rips2 = Rips(maxdim=2)
        dgm2 = rips2.fit_transform(data)
        assert len(dgm2) == 3
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_defaults(self):
        data = np.random.random((100, 3))

        rips = Rips()
        dgm = rips.fit_transform(data)

        assert len(dgm) == 2
        assert rips.coeff == 2
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_thresh(self):
        np.random.seed(3100)
        data = np.random.random((100, 3))

        rips0 = Rips(thresh=0.1)
        dgm0 = rips0.fit_transform(data)

        rips1 = Rips(thresh=1)
        dgm1 = rips1.fit_transform(data)

        # Barcode of H_1 diagram will be smaller, right?
        assert len(dgm0[1]) < len(dgm1[1]), "Usually"
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_instantiate(self):
        rip = Rips()
        assert rip is not None
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_maxdim(self):
        np.random.seed(3100)
        data = np.random.random((100, 3))

        # maxdim refers to the max H_p class, generate all less than

        rips0 = Rips(maxdim=0)
        dgm0 = rips0.fit_transform(data)
        assert len(dgm0) == 1

        rips1 = Rips(maxdim=1)
        dgm1 = rips1.fit_transform(data)
        assert len(dgm1) == 2

        rips2 = Rips(maxdim=2)
        dgm2 = rips2.fit_transform(data)
        assert len(dgm2) == 3
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_sparse(self):
        np.random.seed(10)
        thresh = 1.1

        # Do dense filtration with threshold
        data = datasets.make_circles(n_samples=100)[
            0] + 5 * datasets.make_circles(n_samples=100)[0]
        rips0 = Rips(thresh=thresh, maxdim=1)
        dgms0 = rips0.fit_transform(data)

        # Convert to sparse matrix first based on threshold,
        # then do full filtration
        rips1 = Rips(maxdim=1)
        D = makeSparseDM(data, thresh)
        dgms1 = rips1.fit_transform(D, distance_matrix=True)

        # The same number of edges should have been added
        assert rips0.num_edges_ == rips1.num_edges_

        I10 = dgms0[1]
        I11 = dgms1[1]
        idx = np.argsort(I10[:, 0])
        I10 = I10[idx, :]
        idx = np.argsort(I11[:, 0])
        I11 = I11[idx, :]
        assert np.allclose(I10, I11)
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_input_warnings(self):

        rips = Rips()
        data = np.random.random((3, 10))

        with pytest.warns(UserWarning, match='has more columns than rows') as w:
            rips.transform(data)

        data = np.random.random((3, 3))
        with pytest.warns(UserWarning, match='input matrix is square, but the distance_matrix') as w:
            rips.transform(data)
github scikit-tda / ripser.py / test / test_ripser_sklearn.py View on Github external
def test_non_square_dist_matrix(self):
        
        rips = Rips()
        data = np.random.random((3, 10))

        with pytest.raises(Exception):
            rips.transform(data, distance_matrix=True)
github scikit-tda / ripser.py / examples / moebius_strip.py View on Github external
N = 50
t = np.linspace(0, 2*np.pi, N)
X = np.zeros((N,3))
X[:,0] = (2 + np.cos(t)) * np.cos(2*t)
X[:,1] = (2 + np.cos(t)) * np.sin(2*t)
X[:,2] = np.sin(t)


print('Computing over Z2...')
r = Rips(maxdim=1, coeff=2)
dgmZ2 = r.fit_transform(X)
print('Finished Z2')

print('Computing over Z3...')
r = Rips(maxdim=1, coeff=3)
dgmZ3 = r.fit_transform(X)
print('Finished Z3')


# Plot the two diagrams
plt.figure(1)

# linear
plt.subplot(121)
r.plot(dgmZ2, show=False)
plt.title("Diagram over Z2")

plt.subplot(122)
r.plot(dgmZ3, show=False)
plt.title("Diagram over Z3")
plt.show()

ripser

A Lean Persistent Homology Library for Python

MIT
Latest version published 4 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages