Exemplo n.º 1
0
        axs[i][j].imshow(z[j + i * K, :, :], cmap='gray')
        axs[i][j].set_axis_off()
plt.show()

# %% codecell
c = np.linalg.norm(data, axis=1)
cc = np.reshape(c, (20, 20))
fig, ax = plt.subplots()
ax.imshow(cc, cmap='cividis')
plt.show()

# %% codecell
# Compute the distance matrix and persistence.
D = sp.spatial.distance.cdist(data, data, metric='euclidean')
# TODO: improve this maxmin function.
sub_ind = pipeline.maxmin_subsample_distance_matrix(D, n_landmarks,
                                                    seed=[57])['indices']
D_sub = D[sub_ind, :][:, sub_ind]
p = 13
PH = ripser(D_sub, distance_matrix=True, maxdim=2, coeff=p, do_cocycles=True)
plot_diagrams(PH['dgms'])
plt_title = 'Persistence Diagram (coefficients in $\mathbb{F}_{%d}$)' % p
plt.title(plt_title)
plt.show()
# If the parameters are chosen well the PH should have a nice H^2 class.

# %% codecell
# Set up a random initial condition.
rng = np.random.default_rng(57)
X_rand = rng.uniform(-1, 1, (4, n_landmarks + 1))
# X_rand = rng.uniform(-1, 1, (4, K**2))
X_rand = X_rand / np.linalg.norm(X_rand, axis=0)
# Get DCT basis vectors.
v1, v2, v3, v4 = makeDCT()
# Set up parameters.
numalphas = 50
numthetas = 2 * numalphas
n_landmarks = 300
L, alphas, thetas = Klein(numalphas, numthetas)
L = np.squeeze(L)
print(L.shape)
D = sp.spatial.distance.pdist(L, 'euclidean')
D = sp.spatial.distance.squareform(D)
print(D.shape)

# %% codecell
# Downsample the dataset to remove the points that are on top of other points.
big_sub_ind = pipeline.maxmin_subsample_distance_matrix(D, 5 *
                                                        n_landmarks)['indices']
D = D[big_sub_ind, :][:, big_sub_ind]
L = L[big_sub_ind, :]
print(D.shape)
print(L.shape)
# Choose a landmark subset.
sub_ind = pipeline.maxmin_subsample_distance_matrix(D, n_landmarks)['indices']
D_sub = D[sub_ind, :][:, sub_ind]
L_sub = L[sub_ind, :]
print(D_sub.shape)
print(L_sub.shape)

# %% codecell
np.savez('examples/klein_bottle_image/klein_bottle_patch.npz',
         D=D,
         L=L,