Vector Index Tool

import oat_python as oat

from fractions import Fraction
import numpy as np
import pandas as pd

Create a Vietoris-Rips complex from a points of points

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()

Generate a VectorIndexTool

vector_index_tool           =   vietoris_rips_complex.vector_index_tool(dimensions=[0,1])
vector_index_tool
<VectorIndexTool with 15 unique simplices>

Convert a dataframe to a dense 1d numpy.ndarray

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

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


Convert the dense 1d numpy.ndarray back to a dataframe

vector_as_dataframe.equals(
    vector_index_tool.dataframe_for_dense_array(vector_as_ndarray)
)
False

Look up the index for a given simplex

vector_index_tool.index_number_for_simplex((1,3))
8

Errors for invalid simplices

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}")
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].

Check that a simplex is in the index tool

vector_index_tool.contains_simplex((1,4))
True

Check that a simplex is not in the index tool

vector_index_tool.contains_simplex((1,5))
False

Total running time of the script: (0 minutes 0.009 seconds)

Gallery generated by Sphinx-Gallery