.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/dowker/plot_dowker_homology.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_dowker_plot_dowker_homology.py: .. _dowker_homology_gallery: Homology ========================================= In this example we compute the homology of a Dowker complex. .. GENERATED FROM PYTHON SOURCE LINES 9-12 .. code-block:: Python import oat_python as oat .. GENERATED FROM PYTHON SOURCE LINES 13-18 Define a dowker complex ------------------------ Dowker complexes are represented as a list of sorted-lists of integers. Each sorted list represents a simplex, and the Dowker complex consists of all subsets of these simplices. .. GENERATED FROM PYTHON SOURCE LINES 18-30 .. code-block:: Python dowker_simplices = [ [0,1,2,6], # simplex 0 [0,1,2], # simplex 1 [0,1,3], # simplex 2 [0,2,3], # simplex 3 [1,2,3], # simplex 4 [3,4], # simplex 5 [4,5], # simplex 6 [3,5], # simplex 7 ] .. GENERATED FROM PYTHON SOURCE LINES 31-35 Plot the Dowker complex ------------------------ This step isn't necessary, but the complex is small and it will help to visualize it. .. GENERATED FROM PYTHON SOURCE LINES 35-53 .. code-block:: Python points = oat.plot.vertex_embedding_for_simplices( dowker_simplices, dimension = 3, # 3D embedding ) fig = oat.plot.fig_3d_for_simplices( simplices = dowker_simplices, points = points, kwargs_points = dict( mode="markers+text", # indicates we want to plot text labels on points text=[str(i) for i in range(len(points))] # text labels for each vertex ), kwargs_triangles= dict(color="white") # color the triangles (transparent) black ) fig.update_layout(template="plotly_dark") # dark theme fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 56-62 Compute homology by decomposing the boundary matrix ----------------------------------------------------- Each row of the homology dataframe represents a homology class. Taken together, these homology classes form a basis for the homology groups of the Dowker complex in dimensions 0 .. max_homology_dimension. .. GENERATED FROM PYTHON SOURCE LINES 62-70 .. code-block:: Python decomposition = oat.core.dowker.BoundaryMatrixDecompositionDowker( dowker_simplices = dowker_simplices, max_homology_dimension = 2 ) homology = decomposition.homology() homology .. raw:: html
dimension cycle_representative cycle_representative_nonzero_coefficient_count unique_simplex_id
0 0 simplex coefficient 0 (0,) 1 1 (0,)
1 1 simplex coefficient 0 (3, 4) 1 1 ... 3 (4, 5)
2 2 simplex coefficient 0 (0, 1, 2) ... 4 (1, 2, 3)


.. GENERATED FROM PYTHON SOURCE LINES 71-77 Cycle representatives ----------------------------------------------------- The "cycle representative" column in the homology dataframe contains a cycle representative for each homology class. .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: Python homology["cycle_representative"][1] .. raw:: html
simplex coefficient
0 (3, 4) 1
1 (3, 5) -1
2 (4, 5) 1


.. GENERATED FROM PYTHON SOURCE LINES 81-92 Plotting ----------------------------------------------------- Let's plot some cycle representatives from the homology dataframe. See also ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - :ref:`vertex_embedding_gallery` - :ref:`cycle_representative_strategies_gallery` - :ref:`styling_3d_gallery` .. GENERATED FROM PYTHON SOURCE LINES 94-96 Plot a 1-cycle ^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 98-99 Pull the cycle from the homology dataframe. .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: Python one_cycle = homology["cycle_representative"][1] one_cycle .. raw:: html
simplex coefficient
0 (3, 4) 1
1 (3, 5) -1
2 (4, 5) 1


.. GENERATED FROM PYTHON SOURCE LINES 105-118 .. code-block:: Python edges = one_cycle.simplex trace_1cycle = oat.plot.trace_3d_for_edges( edges = edges, points = points, line = dict( width=10, color="red" ), opacity = 1.0, showlegend = True, name = "1-cycle" ) fig.add_trace(trace_1cycle) fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 119-122 Plot a 2-cycle ^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 124-125 Pull the cycle from the homology dataframe. .. GENERATED FROM PYTHON SOURCE LINES 127-130 .. code-block:: Python two_cycle = homology["cycle_representative"][2] two_cycle .. raw:: html
simplex coefficient
0 (0, 1, 2) -1
1 (0, 1, 3) 1
2 (0, 2, 3) -1
3 (1, 2, 3) 1


.. GENERATED FROM PYTHON SOURCE LINES 131-132 Toggle off the one-cycle (but don't remove it from the figure). .. GENERATED FROM PYTHON SOURCE LINES 134-136 .. code-block:: Python fig.data[3].visible = "legendonly" .. GENERATED FROM PYTHON SOURCE LINES 137-138 Add a trace for the 2-cycle, colored red. .. GENERATED FROM PYTHON SOURCE LINES 140-156 .. code-block:: Python triangles = two_cycle.simplex trace_2cycle = oat.plot.trace_3d_for_triangles( triangles = triangles, points = points, color = "red", opacity = 0.5, showlegend = True, name = "2-cycle" ) fig.add_trace(trace_2cycle) fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 157-162 Fundamental subspaces ----------------------------------------------------- The ``.fundamental_subspace_dimensions()`` method returns a data frame with the dimensions of the spaces of chains, cycles, and boundaries. .. GENERATED FROM PYTHON SOURCE LINES 162-165 .. code-block:: Python decomposition.fundamental_subspace_dimensions() .. raw:: html
homology space_of_chains space_of_cycles space_of_boundaries
dimension
0 1 7 7 6
1 1 12 6 5
2 1 7 2 1


.. GENERATED FROM PYTHON SOURCE LINES 166-171 Betti numbers ----------------------------------------------------- The ``.betti_numbers()`` method returns a list [b_0, b_1, ..., b_max_homology_dimension], where b_i is the dimension of the i-th homology group. .. GENERATED FROM PYTHON SOURCE LINES 171-173 .. code-block:: Python decomposition.betti_numbers() .. rst-class:: sphx-glr-script-out .. code-block:: none [1, 1, 1] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.174 seconds) .. _sphx_glr_download_auto_examples_dowker_plot_dowker_homology.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dowker_homology.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dowker_homology.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dowker_homology.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_