def test_exact_neg(self): P = PersLandscapeExact( critical_pairs=[[[0, 0], [1, 1], [2, 1], [3, 1], [4, 0]]]) assert (-P).critical_pairs == [[[0, 0], [1, -1], [2, -1], [3, -1], [4, 0]]] Q = PersLandscapeExact(critical_pairs=[[[0, 0], [5, 0]]]) assert (-Q).critical_pairs == Q.critical_pairs
def test_exact_hom_deg(self): P = PersLandscapeExact( dgms=[np.array([[1.0, 5.0]])], hom_deg=0, ) assert P.hom_deg == 0 with pytest.raises(ValueError): PersLandscapeExact(hom_deg=-1)
def test_exact_add(self): with pytest.raises(ValueError): PersLandscapeExact(critical_pairs=[[[0, 0], [1, 1]]], hom_deg=0) + PersLandscapeExact( critical_pairs=[[[0, 0], [1, 1]]], hom_deg=1) Q = PersLandscapeExact( critical_pairs=[[[0, 0], [1, 1], [2, 2]]]) + PersLandscapeExact( critical_pairs=[[[0, 0], [0.5, 1], [1.5, 3]]]) np.testing.assert_array_equal( Q.critical_pairs, [[[0, 0], [0.5, 1.5], [1, 3], [1.5, 4.5], [2, 5]]])
def test_exact_div(self): P = PersLandscapeExact( critical_pairs=[[[0, 0], [1, 2], [2, 0], [3, -1], [4, 0]]]) np.testing.assert_array_equal( (P / 2).critical_pairs, [[[0, 0], [1, 1], [2, 0], [3, -0.5], [4, 0]]]) with pytest.raises(ValueError): P / 0
def test_exact_mul(self): P = PersLandscapeExact( critical_pairs=[[[0, 0], [1, 2], [2, 0], [3, -1], [4, 0]]]) np.testing.assert_array_equal( (4 * P).critical_pairs, [[[0, 0], [1, 8], [2, 0], [3, -4], [4, 0]]]) np.testing.assert_array_equal( (P * (-1)).critical_pairs, [[[0, 0], [1, -2], [2, 0], [3, 1], [4, 0]]])
def test_exact_norm(self): P = PersLandscapeExact(critical_pairs=[[[0, 0], [1, 1], [2, 1], [3, 1], [4, 0]]], hom_deg=0) negP = PersLandscapeExact(critical_pairs=[[[0, 0], [1, -1], [2, -1], [3, -1], [4, 0]]], hom_deg=0) assert P.sup_norm() == 1 assert P.p_norm(p=2) == pytest.approx(np.sqrt(2 + (2.0 / 3.0))) assert P.p_norm(p=5) == pytest.approx((2 + (1.0 / 3.0))**(1.0 / 5.0)) assert P.p_norm(p=113) == pytest.approx( (2 + (1.0 / 57.0))**(1.0 / 113.0)) assert negP.sup_norm() == 1 assert negP.p_norm(p=2) == pytest.approx(np.sqrt(2 + (2.0 / 3.0))) assert negP.p_norm(p=5) == pytest.approx( (2 + (1.0 / 3.0))**(1.0 / 5.0)) assert negP.p_norm(p=113) == pytest.approx( (2 + (1.0 / 57.0))**(1.0 / 113.0))
def test_vectorize(self): P = PersLandscapeExact(dgms=[np.array([[0, 5], [1, 4]])]) Q = vectorize(P, start=0, stop=5, num_steps=6) assert Q.hom_deg == P.hom_deg assert Q.start == 0 assert Q.stop == 5 np.testing.assert_array_equal( Q.values, np.array([[0, 1, 2, 2, 1, 0], [0, 0, 1, 1, 0, 0]])) R = vectorize(P) assert R.start == 0 assert R.stop == 5
def test_exact_critical_pairs(self): assert not PersLandscapeExact(dgms=[np.array([[0, 3]])], compute=False).critical_pairs # example from Peter & Pavel's paper P = PersLandscapeExact( dgms=[ np.array([[1.0, 5.0], [2.0, 8.0], [3.0, 4.0], [5.0, 9.0], [6.0, 7.0]]) ], hom_deg=0, ) P.compute_landscape() # duplicate bars Q = PersLandscapeExact(dgms=[np.array([[1, 5], [1, 5], [3, 6]])], hom_deg=0) Q.compute_landscape() np.testing.assert_array_equal( P.critical_pairs, [ [ [1.0, 0], [3.0, 2.0], [3.5, 1.5], [5.0, 3.0], [6.5, 1.5], [7.0, 2.0], [9.0, 0], ], [[2.0, 0], [3.5, 1.5], [5.0, 0], [6.5, 1.5], [8.0, 0]], [[3.0, 0], [3.5, 0.5], [4.0, 0], [6.0, 0], [6.5, 0.5], [7.0, 0]], ], ) np.testing.assert_array_equal( Q.critical_pairs, [ [[1, 0], [3.0, 2.0], [4.0, 1.0], [4.5, 1.5], [6, 0]], [[1, 0], [3.0, 2.0], [4.0, 1.0], [4.5, 1.5], [6, 0]], [[3, 0], [4.0, 1.0], [5, 0]], ], )
def test_exact_empty(self): with pytest.raises(ValueError): PersLandscapeExact()
def test_exact_get_item(self): P = PersLandscapeExact(dgms=[np.array([[1, 5], [1, 5], [3, 6]])]) np.testing.assert_array_equal( P[1], [[1, 0], [3, 2], [4, 1], [4.5, 1.5], [6, 0]]) with pytest.raises(IndexError): P[3]