Exemplo n.º 1
0
def test_image_kernel_4():
    A = barcode_basis([[1, 4], [2, 4], [3, 5]])
    B = barcode_basis([[0, 4], [0, 2], [1, 4], [1, 3]])
    F = np.array([[0, 1, 1], [1, 0, 0], [0, 4, 1], [0, 0, 0]])
    res_Im, res_Ker, PreIm = image_kernel(A, B, F, 5)
    Ker_basis = np.array([[2, 4], [4, 5]])
    Im_basis = np.array([[1, 2], [2, 4], [3, 4]])
    assert np.array_equal(Im_basis, res_Im.barcode)
    assert np.array_equal(Ker_basis, res_Ker.barcode)
Exemplo n.º 2
0
def test_image_kernel_8():
    # Test for quotients
    A = barcode_basis(np.array([[2.5, 5], [0, 5], [1, 4], [2, 3]]))
    B = barcode_basis(np.array([[0, 5], [1, 4], [2, 3]]))
    F = np.array([[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]])
    res_Im, res_Ker, PreIm = image_kernel(A, B, F, 5, start_index=1)
    Im_bar = np.array([[0., 4.], [1., 3.], [2., 2.5]])
    Im_coord = np.array([[1., 1., 1.], [0., 1., 1.], [0., 0., 1.]])
    assert np.array_equal(Im_bar, res_Im.barcode)
    assert np.array_equal(Im_coord, res_Im.coordinates)
Exemplo n.º 3
0
def test_image_kernel_1():
    A = barcode_basis([[1, 5], [1, 4], [2, 5]])
    B = barcode_basis([[0, 5], [0, 3], [1, 4]])
    F = np.array([[0, 0, 1], [1, 0, 0], [1, 1, 1]])
    Im = np.array([[0, 0, 1], [4, 4, 0], [4, 0, 0]])
    Ker = np.array([[4, 1, 0]]).T
    PreIm = np.array([[4, 4, 0], [0, 1, 4], [0, 0, 1]])
    res_Im, res_Ker, res_PreIm = image_kernel(A, B, F, 5)
    assert np.array_equal(res_Im.coordinates, Im)
    assert np.array_equal(res_Ker.coordinates, Ker)
    assert np.array_equal(res_PreIm, PreIm)
Exemplo n.º 4
0
def test_image_kernel_5():
    A = barcode_basis([[0, 4], [0, 2], [1, 4], [1, 3]])
    A_rel = barcode_basis([[0, 2], [1, 4], [1, 3]])
    B = barcode_basis([[0, 3], [0, 2], [0, 2]])
    F = np.array([[0, 0, 0, 1], [4, 0, 1, 3], [1, 0, 1, 4]])
    res_Im, PreIm = image_kernel(A, B, F, 5, start_index=1, prev_basis=A_rel)
    # Ker_basis = np.array([[0, 2], [2, 4]])
    Im_basis = np.array([[1, 3], [1, 2]])
    res_PreIm = np.array([[0, 0], [4, 1], [1, 0]])
    assert np.array_equal(Im_basis, res_Im.barcode.astype(float))
    # assert np.array_equal(Ker_basis, res_Ker.barcode)
    assert np.array_equal(res_PreIm, PreIm.astype(float))
Exemplo n.º 5
0
def test_image_kernel_7():
    A = barcode_basis(
        np.array([[0.20065389, 0.21080812], [0.25135865, 0.29062369],
                  [0.25135865, 0.27869416], [0.25403887,
                                             0.3], [0.28256212, 0.3],
                  [0.29679942, 0.3], [0.24715565, 0.29062369]]))
    B = barcode_basis(
        np.array([[0.20065389, 0.21080812], [0.25135865, 0.29062369],
                  [0.25135865, 0.27869416], [0.25403887,
                                             0.3], [0.28256212, 0.3],
                  [0.29679942, 0.3], [0.24715565, 0.25135865]]))
    F = np.array([[1., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0., 3.],
                  [0., 0., 1., 0., 0., 0., 3.], [0., 0., 0., 1., 0., 0., 0.],
                  [0., 0., 0., 0., 1., 0., 0.], [0., 0., 0., 0., 0., 1., 0.],
                  [0., 0., 0., 0., 0., 0., 1.]])
    res_Im, res_Ker, PreIm = image_kernel(A, B, F, 5)
    Im_bar = np.array([[0.20065389, 0.21080812], [0.24715565, 0.29062369],
                       [0.25135865, 0.27869416], [0.25403887, 0.3],
                       [0.28256212, 0.3], [0.29679942, 0.3]])
    assert np.array_equal(Im_bar, res_Im.barcode)
Exemplo n.º 6
0
def test_module_persistence_homology():
    A_bas = barcode_basis([[1, 4], [2, 4], [3, 5]])
    B_bas = barcode_basis([[0, 4], [0, 2], [1, 4], [1, 3]])
    C_bas = barcode_basis([[0, 3], [0, 2], [0, 2]])
    Base = [C_bas, B_bas, A_bas]
    f = np.array([[0, 1, 1], [1, 0, 0], [0, 4, 1], [0, 0, 0]])
    g = np.array([[0, 0, 0, 1], [4, 0, 1, 3], [1, 0, 1, 4]])
    D = [0, g, f]
    Hom, Im, PreIm = module_persistence_homology(D, Base, 5)
    H0 = np.array([[0, 1], [0, 1]])
    H1 = np.array([[0, 1], [2, 3]])
    H2 = np.array([[2, 4], [4, 5]])
    H = [H0, H1, H2]
    PreIm0 = []
    PreIm1 = np.array([[1, 2, 4], [0, 0, 0], [0, 4, 1], [0, 1, 0]])
    PreIm2 = np.array([[1, 0, 0], [0, 1, 1], [0, 0, 1]])
    PreImages = [PreIm0, PreIm1, PreIm2]
    for j in range(3):
        assert np.array_equal(Hom[j].barcode, H[j])
        assert np.array_equal(PreIm[j], PreImages[j])
Exemplo n.º 7
0
def test_image_kernel_9():
    # Test for dying dependent classes in Kernel after adding them
    # through the image reduction.
    A = barcode_basis([[1, 8], [2, 8], [3, 5]])
    B = barcode_basis([[0, 5], [1, 8], [2, 5]])
    F = np.array([[1, 0, -1], [1, -1, 0], [0, 1, -1]])
    res_Im, res_Ker, res_PreIm = image_kernel(A, B, F, 5)
    # expected results
    Im_barcode = np.array([[1., 8.], [2., 5.]])
    Im_coord = np.array([[1., 1.], [1., 0.], [0., 1.]])
    Ker_barcode = np.array([[3., 8.]])
    Ker_coord = np.array([[1.], [1.], [1.]])
    PreIm = np.array([[1., 1.], [0., 1.], [0., 0.]])
    print(res_Im)
    print(res_Ker)
    print(res_PreIm)
    assert np.array_equal(Im_barcode, res_Im.barcode)
    assert np.array_equal(Im_coord, res_Im.coordinates)
    assert np.array_equal(Ker_barcode, res_Ker.barcode)
    assert np.array_equal(Ker_coord, res_Ker.coordinates)
    assert np.array_equal(res_PreIm, PreIm)
Exemplo n.º 8
0
def test_barcode_basis():
    barcode = [[1, 2], [1, 4], [-0.25, 5], [0.1, 1]]
    bas = barcode_basis(barcode)
    order = bas.sort(send_order=True)
    assert np.array_equal(order[np.argsort(order)], range(4))
    assert np.array_equal(np.array([
        [-0.25, 5.], [0.1, 1.], [1., 4.], [1., 2.]]), bas.barcode)
    assert np.array_equal(bas.active(1.1), np.array([0, 2, 3]))
    assert np.array_equal(bas.birth(1), np.array([2, 3]))
    assert np.array_equal(bas.death(4), np.array([2]))
    assert np.array_equal(bas.changes_list(),
                          np.array([-0.25, 0.1, 1, 2, 4, 5]))
Exemplo n.º 9
0
def test_barcode_basis():
    barcode = [[1, 2], [1, 4], [-0.25, 5], [0.1, 1]]
    bas = barcode_basis(barcode)
    order = bas.sort(send_order=True)
    assert np.array_equal(order[np.argsort(order)], range(4))
    assert np.array_equal(
        np.array([[-0.25, 5.], [0.1, 1.], [1., 4.], [1., 2.]]), bas.barcode)
    assert np.array_equal(bas.active(1.1), np.array([0, 2, 3]))
    assert np.array_equal(bas.active(1.1, start=2), np.array([0, 1]))
    assert np.array_equal(bas.trans_active_coord([0, 1, 1], 1.2),
                          np.array([0, 0, 1, 1]))
    assert np.array_equal(bas.death(4), np.array([2]))
    assert np.array_equal(bas.death(4, start=2), np.array([0]))
    assert bas.birth_radius(np.array([1, 1, 0, 0])) == 0.1
    assert bas.death_radius(np.array([1, 1, 0, 1])) == 5
    assert np.array_equal(bas.changes_list(),
                          np.array([-0.25, 0.1, 1, 2, 4, 5]))
Exemplo n.º 10
0
def test_image_kernel_6():
    # Test for unordered bases
    start_idx = 4
    A = np.array([[0., 2.], [0., 1.], [0., 0.4], [0., 0.4], [0., 2.], [0., 2.],
                  [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.],
                  [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.],
                  [0., 0.4], [0., 0.4], [0., 0.4], [0., 0.4]])
    A_dim = np.size(A, 0)
    shuffleA = np.append(range(4, A_dim, 2), range(5, A_dim, 2), axis=0)
    shifted_shuffleA = np.append(range(4), shuffleA, axis=0)
    A_shuffle = barcode_basis(A[shifted_shuffleA])
    A_rel = barcode_basis(A[start_idx:])
    A = barcode_basis(A)
    B = np.array([[0., 2.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.],
                  [0., 1.], [0., 0.4], [0., 0.4], [0., 2.], [0., 1.], [0., 1.],
                  [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 0.4], [0.,
                                                                      0.4]])
    B_dim = np.size(B, 0)
    shuffleB = np.append(range(0, B_dim, 2), range(1, B_dim, 2), axis=0)
    B_shuffle = barcode_basis(B[shuffleB])
    B = barcode_basis(B)
    F = np.array([[
        1., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0.
    ],
                  [
                      4., 4., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      4., 4., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 1., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 1., 0., 0., 0.
                  ],
                  [
                      0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 1., 0., 0.
                  ],
                  [
                      4., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
                      0., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      1., 0., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 1., 0., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 1., 0., 0., 0., 0., 0.
                  ],
                  [
                      0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 1., 0., 0., 0., 0.
                  ],
                  [
                      0., 0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 1., 0.
                  ],
                  [
                      0., 0., 0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
                      0., 0., 0., 0., 0., 0., 0., 1.
                  ]])
    F_shuffle = F[shuffleB]
    F_shuffle = F_shuffle[:, shifted_shuffleA]
    Im = np.array([[0., 2.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.],
                   [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.],
                   [0., 0.4], [0., 0.4]])
    res_Im_sh, res_Ker_sh, PreIm_sh = image_kernel(A_shuffle,
                                                   B_shuffle,
                                                   F_shuffle,
                                                   5,
                                                   start_index=start_idx,
                                                   prev_basis=A_rel)
    res_Im, res_Ker, PreIm = image_kernel(A,
                                          B,
                                          F,
                                          5,
                                          start_index=start_idx,
                                          prev_basis=A_rel)
    shuffleA = shuffleA - start_idx
    assert np.array_equal(res_Im_sh.barcode, Im)
    assert np.array_equal(res_Im.barcode, Im)
    assert np.array_equal(res_Ker_sh.coordinates,
                          res_Ker.coordinates[shuffleA])