<jupyter_start><jupyter_text>Use-Cases of TDA Usage on 3D Shapes<jupyter_code>%pylab inline
%load_ext autoreload
%autoreload 2

import warnings, tqdm

warnings.simplefilter('ignore')
from filtration.filtration import *

pyo.init_notebook_mode(connected=True)
from mpl_toolkits.mplot3d import Axes3D<jupyter_output>Populating the interactive namespace from numpy and matplotlib<jupyter_text>Load the 3D cloud point<jupyter_code>def load_3D_shape(filepath):

    vec = []
    num = sum(1 for line in open(filepath, 'r'))

    with open(filepath, 'r') as raw:
        for idx in tqdm.tqdm(range(num)):
            tmp = raw.readline().split(' ')
            if len(tmp) == 3: vec.append(np.asarray(tmp).astype('float'))

    vec = np.vstack(vec)
    
    return vec

vec = load_3D_shape('./samples/hand.off')<jupyter_output>100%|██████████| 21722/21722 [00:00<00:00, 382618.23it/s]<jupyter_text>Build the persistence, and extract the components of dimension 0<jupyter_code>flt = Filtration(vec, use_alpha=False)
flt.persistence(persistence_type='simple', dimension=0)<jupyter_output><empty_output><jupyter_text>Compute the relative betti curve, based on dimension 0 components<jupyter_code>btc = flt.betti_curve()<jupyter_output><empty_output><jupyter_text>Compute the relative landscapes, based on dimension 0 components<jupyter_code>ldc = flt.landscapes()<jupyter_output><empty_output><jupyter_text>General visualization<jupyter_code># Recast persistence diagram for gudhi visualization tools
dig = [(0, tuple(e)) for e in flt.fil]
plt.figure(figsize=(18,14))
fig = gds.GridSpec(4, 2)
ax0 = plt.subplot(fig[:,0], projection='3d')
ax0.set_title('Mapped 3 Dimensional Data Cloud')
ax0.set_xticks([])                               
ax0.set_yticks([])                               
ax0.set_zticks([])
ax0.scatter(vec[:,0], vec[:,1], vec[:,2], s=2, c='coral')
ax0.set_xlabel('x Coordinate')
ax0.set_ylabel('y Coordinate')
ax0.set_zlabel('z Coordinate')
plt.subplot(fig[0,1])
gudhi.plot_persistence_diagram(dig)
plt.subplot(fig[1,1])
gudhi.plot_persistence_barcode(dig)
plt.subplot(fig[2,1])
plt.title('Betti Curve')
plt.plot(btc)
plt.subplot(fig[3,1])
plt.title('Persistence Landscapes')
for ele in ldc: plt.plot(ele)
plt.tight_layout()
plt.show()<jupyter_output>Deprecated parameter. It has been replaced by max_intervals
Deprecated parameter. It has been replaced by max_intervals
{'fraction_non_alphanumeric': 0.13378207824989483, 'fraction_numerical': 0.030710980227177113, 'mean_word_length': 5.550964187327824, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '537404', 'license': 'Apache-2.0', 'n_tokens_mistral': 930, 'n_tokens_neox': 878, 'n_words': 174, 'path': 'tutorial-filtration.ipynb', 'repo_name': 'lironsoffer/TdaToolbox', 'size': '2377'}