.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/vietoris_rips/plot_vector_index_tool.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_vietoris_rips_plot_vector_index_tool.py: Vector Index Tool ======================================== .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: Python import oat_python as oat from fractions import Fraction import numpy as np import pandas as pd .. GENERATED FROM PYTHON SOURCE LINES 14-15 Create a Vietoris-Rips complex from a points of points .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python points = np.random.rand(5, 3) dissimilarity_matrix = oat.dissimilarity.sparse_matrix_for_points(points, max_dissimilarity=np.inf) vietoris_rips_complex = oat.core.vietoris_rips.VietorisRipsComplex(dissimilarity_matrix) boundary_matrix = vietoris_rips_complex.boundary_matrix_oracle() .. GENERATED FROM PYTHON SOURCE LINES 21-22 Generate a VectorIndexTool .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python vector_index_tool = vietoris_rips_complex.vector_index_tool(dimensions=[0,1]) vector_index_tool .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 26-27 Convert a dataframe to a dense 1d numpy.ndarray .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python simplices_in_index_tool = vector_index_tool.simplices() vector_as_dataframe = boundary_matrix.column_for_simplex([0,1,2]) vector_as_ndarray = vector_index_tool.dense_array_for_dataframe(vector_as_dataframe) html = oat.plot.display_dataframes_side_by_side( vector_as_dataframe, pd.DataFrame(dict(coefficient=vector_as_ndarray)), simplices_in_index_tool, titles=['Vector as DataFrame', 'Vector as dense array', 'Simplices in index tool'] ) html .. raw:: html

Vector as DataFrame

simplex filtration coefficient
0 (0, 2) 0.342480 -1
1 (0, 1) 0.377622 1
2 (1, 2) 0.559060 1

Vector as dense array

coefficient
0 0.0
1 0.0
2 0.0
3 0.0
4 0.0
5 -1.0
6 1.0
7 0.0
8 0.0
9 1.0
10 0.0
11 0.0
12 0.0
13 0.0
14 0.0

Simplices in index tool

simplex filtration
0 (0,) 0.000000
1 (1,) 0.000000
2 (2,) 0.000000
3 (3,) 0.000000
4 (4,) 0.000000
5 (0, 2) 0.342480
6 (0, 1) 0.377622
7 (0, 3) 0.389864
8 (1, 3) 0.497502
9 (1, 2) 0.559060
10 (2, 3) 0.586859
11 (0, 4) 0.752891
12 (3, 4) 0.790280
13 (2, 4) 0.812302
14 (1, 4) 1.116900


.. GENERATED FROM PYTHON SOURCE LINES 39-40 Convert the dense 1d numpy.ndarray back to a dataframe .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python vector_as_dataframe.equals( vector_index_tool.dataframe_for_dense_array(vector_as_ndarray) ) .. rst-class:: sphx-glr-script-out .. code-block:: none False .. GENERATED FROM PYTHON SOURCE LINES 45-46 Look up the index for a given simplex .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python vector_index_tool.index_number_for_simplex((1,3)) .. rst-class:: sphx-glr-script-out .. code-block:: none 8 .. GENERATED FROM PYTHON SOURCE LINES 49-50 Errors for invalid simplices .. GENERATED FROM PYTHON SOURCE LINES 50-60 .. code-block:: Python try: vector_index_tool.index_number_for_simplex((3,2,1)) # not strictly sorted except Exception as e: print(f"Caught error: {type(e).__name__}: {e}") try: vector_index_tool.index_number_for_simplex((10,20)) # not in the Vietoris-Rips complex except Exception as e: print(f"Caught error: {type(e).__name__}: {e}") .. rst-class:: sphx-glr-script-out .. code-block:: none Caught error: TypeError: The VectorIndexTool does not contain a simplex represented by [3, 2, 1]. Caught error: TypeError: The VectorIndexTool does not contain a simplex represented by [10, 20]. .. GENERATED FROM PYTHON SOURCE LINES 61-62 Check that a simplex is in the index tool .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python vector_index_tool.contains_simplex((1,4)) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 65-66 Check that a simplex is not in the index tool .. GENERATED FROM PYTHON SOURCE LINES 66-66 .. code-block:: Python vector_index_tool.contains_simplex((1,5)) .. rst-class:: sphx-glr-script-out .. code-block:: none False .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.009 seconds) .. _sphx_glr_download_auto_examples_vietoris_rips_plot_vector_index_tool.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_vector_index_tool.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_vector_index_tool.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_vector_index_tool.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_