Skip to content

Commit fe6e114

Browse files
authored
Merge pull request #60 from MunchLab/dect
Dect
2 parents 0b2a34b + 606c9a0 commit fe6e114

177 files changed

Lines changed: 12124 additions & 7664 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ doc_source/notebooks/Matisse/outlines/*
55

66
benchmarks/results/*
77

8+
src/ect/embed_graph.py
9+
src/ect/embed_cw.py
10+
811
# Byte-compiled / optimized / DLL files
912
__pycache__/
1013
*.py[cod]

docs/doctrees/nbsphinx/notebooks/tutorial_cw.ipynb renamed to Extra_Notebooks/tutorial_cw.ipynb

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
{
44
"cell_type": "markdown",
55
"metadata": {},
6-
"source": [
7-
"# Tutorial: ECT for CW complexes\n",
8-
"\n",
9-
"\n",
10-
"\n",
11-
" This tutorial walks you through how to build a CW complex with the `EmbeddedCW` class, and then use the `ECT` class to compute the Euler characteristic transform"
12-
]
6+
"source": "# Tutorial: ECT for CW complexes\n\nThis tutorial walks you through how to build a CW complex with the `EmbeddedCW` class, and then use the `ECT` class to compute the Euler characteristic transform.\\n\\n**Note**: This tutorial uses `EmbeddedCW`, which is now an alias for the unified `EmbeddedComplex` class. The new unified class supports arbitrary dimensional cells beyond just 2-cells (faces). See `Tutorial-EmbeddedComplex.ipynb` for comprehensive coverage of the new capabilities."
137
},
148
{
159
"cell_type": "code",
@@ -25,9 +19,7 @@
2519
{
2620
"cell_type": "markdown",
2721
"metadata": {},
28-
"source": [
29-
" The CW complex is the same as the `EmbeddedGraph` class with that additional ability to add faces. Faces are added by passing in a list of vertices. Note that we are generally assuming that these vertices follow around an empty region (as in, no other vertex is in the interior) in the graph bounded by the vertices, and further that all edges are already included in the graph. However the class does not yet check for this so you need to be careful!"
30-
]
22+
"source": "The CW complex class extends the `EmbeddedGraph` functionality with the ability to add faces (2-cells). With the new unified `EmbeddedComplex` class, you can now add cells of any dimension!\\n\\n**Face/Cell Addition Methods:**\\n- `add_face(vertices)` - Add 2-cells (backward compatible)\\n- `add_cell(vertices, dim=k)` - Add k-cells of any dimension (new!)\\n\\nFaces are added by passing in a list of vertices. We generally assume that these vertices form a cycle bounding an empty region, and that all boundary edges are already included in the complex."
3123
},
3224
{
3325
"cell_type": "code",
@@ -348,6 +340,28 @@
348340
"result = ect.calculate(K)\n",
349341
"result.plot()\n"
350342
]
343+
},
344+
{
345+
"cell_type": "code",
346+
"source": "# Example: Adding 3-cells to create a tetrahedron\\nK_tetra = EmbeddedCW() # Still works - now creates EmbeddedComplex\\n\\n# Add tetrahedron vertices\\ntetra_vertices = {\\n 'A': [0, 0, 0],\\n 'B': [1, 0, 0],\\n 'C': [0.5, 0.866, 0],\\n 'D': [0.5, 0.289, 0.816]\\n}\\n\\nfor name, coord in tetra_vertices.items():\\n K_tetra.add_node(name, coord)\\n\\n# Add all edges\\nfrom itertools import combinations\\nfor edge in combinations(['A', 'B', 'C', 'D'], 2):\\n K_tetra.add_edge(*edge)\\n\\n# Add all triangular faces (2-cells)\\nfor face in combinations(['A', 'B', 'C', 'D'], 3):\\n K_tetra.add_face(list(face)) # Using the familiar add_face method\\n\\n# NEW: Add the 3-cell (volume)\\nK_tetra.add_cell(['A', 'B', 'C', 'D'], dim=3)\\n\\nprint(f\\\"Tetrahedron complex:\\\")\\nprint(f\\\" 0-cells (vertices): {len(K_tetra.nodes())}\\\")\\nprint(f\\\" 1-cells (edges): {len(K_tetra.edges())}\\\")\\nprint(f\\\" 2-cells (faces): {len(K_tetra.faces)}\\\")\\nprint(f\\\" 3-cells (volumes): {len(K_tetra.cells[3])}\\\")\\n\\n# Plot the tetrahedron\\nfig = plt.figure(figsize=(8, 6))\\nax = fig.add_subplot(111, projection='3d')\\nK_tetra.plot(ax=ax, face_alpha=0.3, node_size=100)\\nax.set_title('Tetrahedron with 3-cell')\\nplt.show()\\n\\n# Compute ECT (now includes the 3-cell in the calculation!)\\nect_tetra = ECT(num_dirs=20, num_thresh=30)\\nresult_tetra = ect_tetra.calculate(K_tetra)\\nresult_tetra.plot()\\nplt.title('ECT of Tetrahedron (includes 3-cell contribution)')\\nplt.show()\"",
347+
"metadata": {},
348+
"execution_count": null,
349+
"outputs": []
350+
},
351+
{
352+
"cell_type": "markdown",
353+
"source": "## New Capabilities: Beyond 2-Cells\\n\\nWith the unified `EmbeddedComplex` class, you can now add cells of arbitrary dimension. Here's a quick example showing 3-cells:\"",
354+
"metadata": {}
355+
},
356+
{
357+
"cell_type": "markdown",
358+
"source": "## Enhanced ECT Computation\\n\\nThe ECT now properly computes the Euler characteristic using the alternating sum over **all** cell dimensions:\\n\\n**χ(threshold) = Σ(-1)^k × |{k-cells with projection ≤ threshold}|**\\n\\nThis means:\\n- 0-cells (vertices) contribute **+1** each\\n- 1-cells (edges) contribute **-1** each \\n- 2-cells (faces) contribute **+1** each\\n- 3-cells (volumes) contribute **-1** each\\n- And so on...\\n\\nCompare this to the traditional graph-only ECT which only considered vertices and edges!\"",
359+
"metadata": {}
360+
},
361+
{
362+
"cell_type": "markdown",
363+
"source": "## Summary and Next Steps\\n\\nThis tutorial showed CW complex functionality using `EmbeddedCW`. Key takeaways:\\n\\n- **Backward Compatibility**: All existing `EmbeddedCW` code continues to work\\n- **Enhanced Capabilities**: The unified `EmbeddedComplex` now supports arbitrary dimensional cells\\n- **Improved ECT**: Properly includes all cell dimensions in Euler characteristic computation\\n\\n### For More Advanced Features:\\n- See `Tutorial-EmbeddedComplex.ipynb` for comprehensive examples of high-dimensional cells\\n- The unified interface supports complexes with cells of any dimension\\n- Enhanced visualization and analysis capabilities\\n\\n### Migration Guide:\\n```python\\n# Old way (still works):\\nfrom ect import EmbeddedCW\\nK = EmbeddedCW()\\n\\n# New way (same result, more features):\\nfrom ect import EmbeddedComplex \\nK = EmbeddedComplex()\\n\\n# Both create the same object with identical functionality!\\n```\"",
364+
"metadata": {}
351365
}
352366
],
353367
"metadata": {
@@ -371,4 +385,4 @@
371385
},
372386
"nbformat": 4,
373387
"nbformat_minor": 2
374-
}
388+
}

docs/doctrees/nbsphinx/notebooks/tutorial_graph.ipynb renamed to Extra_Notebooks/tutorial_graph.ipynb

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
{
44
"cell_type": "markdown",
55
"metadata": {},
6-
"source": [
7-
"# Tutorial: ECT for Embedded Graphs\n",
8-
"\n",
9-
"\n",
10-
"\n",
11-
"This tutorial demonstrates how to use the `ect` package..."
12-
]
6+
"source": "# Tutorial: ECT for Embedded Graphs\n\nThis tutorial demonstrates how to use the `ect` package to compute the Euler Characteristic Transform (ECT) for embedded graphs.\n\n**Note**: This tutorial uses `EmbeddedGraph`, which is now an alias for the unified `EmbeddedComplex` class. All functionality shown here works identically, but `EmbeddedComplex` offers additional features like arbitrary dimensional cells. See the `Tutorial-EmbeddedComplex.ipynb` for the full capabilities."
137
},
148
{
159
"cell_type": "code",
@@ -25,14 +19,7 @@
2519
{
2620
"cell_type": "markdown",
2721
"metadata": {},
28-
"source": [
29-
"## Basic Usage\n",
30-
"\n",
31-
"\n",
32-
"\n",
33-
"First, let's create a simple graph\"\"\"\n",
34-
"\n"
35-
]
22+
"source": "## Basic Usage\n\nFirst, let's create a simple graph. The `EmbeddedGraph` class (now unified with `EmbeddedComplex`) allows you to create graphs with vertices embedded in Euclidean space."
3623
},
3724
{
3825
"cell_type": "code",
@@ -87,11 +74,7 @@
8774
{
8875
"cell_type": "markdown",
8976
"metadata": {},
90-
"source": [
91-
" The embedded graph class inherits from the networkx graph class with the additional attributes `coord_matrix` and `coord_dict`.\n",
92-
"\n",
93-
" The coordinates of all vertices can be accessed using the `coord_matrix` attribute."
94-
]
77+
"source": "The embedded graph class inherits from the networkx graph class with additional attributes for spatial embedding. The unified `EmbeddedComplex` class provides:\\n\\n- `coord_matrix`: N×D matrix of vertex coordinates\\n- `node_list`: Ordered list of vertex identifiers \\n- `cells`: Dictionary storing k-cells by dimension (new feature)\\n\\nThe coordinates of all vertices can be accessed using the `coord_matrix` attribute."
9578
},
9679
{
9780
"cell_type": "code",
@@ -770,6 +753,11 @@
770753
"result_3d = ect_3d.calculate(graph_3d)\n",
771754
"result_3d.plot()\n"
772755
]
756+
},
757+
{
758+
"cell_type": "markdown",
759+
"source": "## What's New: Unified EmbeddedComplex\\n\\nThis tutorial showed the graph functionality using `EmbeddedGraph`. The new unified `EmbeddedComplex` class provides all this functionality plus:\\n\\n- **Arbitrary dimensional cells**: Add 2-cells (faces), 3-cells (volumes), and higher\\n- **Enhanced ECT computation**: Properly includes all cell dimensions in Euler characteristic\\n- **Backward compatibility**: `EmbeddedGraph` is now an alias to `EmbeddedComplex`\\n\\n### Quick example with the same graph:\\n\\n```python\\n# This graph can now also have faces!\\nG.add_face(['A', 'B', 'C']) # Add a 2-cell if vertices form a triangle\\n\\n# Or even higher dimensional cells\\nG.add_cell(['A', 'B', 'C', 'D'], dim=3) # 3-cell if you have 4 vertices\\n```\\n\\nSee `Tutorial-EmbeddedComplex.ipynb` for comprehensive examples of these new capabilities!\"",
760+
"metadata": {}
773761
}
774762
],
775763
"metadata": {
@@ -788,4 +776,4 @@
788776
},
789777
"nbformat": 4,
790778
"nbformat_minor": 2
791-
}
779+
}

doc_source/directions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Directions
22

3+
The `Directions` class provides helper functions for selecting directions to compute the ECT along.
4+
5+
36
```{eval-rst}
47
.. automodule:: ect.directions
58
:members:

doc_source/ect_on_graphs.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# ECT on Graphs
22

33
```{eval-rst}
4-
.. automodule:: ect.ect_graph
4+
.. automodule:: ect.ect
55
:members:
66
```
77

88
```{eval-rst}
99
.. automodule:: ect.sect
1010
:members:
1111
```
12+
13+
```{eval-rst}
14+
.. automodule:: ect.dect
15+
:members:
16+
```

doc_source/embed_complex.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Embedded Complex
2+
3+
The `EmbeddedComplex` class is a unified representation for embedded cell complexes supporting arbitrary dimensional cells.
4+
5+
## Overview
6+
7+
`EmbeddedComplex` combines and extends the functionality of the previous `EmbeddedGraph` and `EmbeddedCW` classes into a single interface. It supports:
8+
9+
- **0-cells (vertices)**: Points embedded in Euclidean space
10+
- **1-cells (edges)**: Line segments between vertices
11+
- **k-cells for k ≥ 2**: Higher dimensional cells (faces, volumes, etc.)
12+
13+
14+
## Basic Usage
15+
16+
```python
17+
from ect import EmbeddedComplex
18+
19+
# Create a complex
20+
K = EmbeddedComplex()
21+
22+
# Add vertices
23+
K.add_node("A", [0, 0])
24+
K.add_node("B", [1, 0])
25+
K.add_node("C", [0.5, 1])
26+
27+
# Add edges
28+
K.add_edge("A", "B")
29+
K.add_edge("B", "C")
30+
K.add_edge("C", "A")
31+
32+
# Add a 2-cell (face)
33+
K.add_face(["A", "B", "C"])
34+
35+
# Or use the general method for any dimension
36+
K.add_cell(["A", "B", "C"], dim=2)
37+
```
38+
39+
## API Reference
40+
41+
```{eval-rst}
42+
.. automodule:: ect.embed_complex
43+
:members:
44+
:show-inheritance:
45+
:undoc-members:
46+
```

doc_source/embed_cw.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc_source/embed_graph.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

doc_source/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ect: Euler Characteristic Transform in Python
22
=============================================
33

4-
Python computation tools for computing the Euler Characteristic Transform of embedded graphs.
4+
Python computation tools for computing the Euler Characteristic Transform of embedded cell complexes with arbitrary dimensional cells.
55

66
Table of Contents
77
-----------------
@@ -13,15 +13,15 @@ Table of Contents
1313

1414
Getting Started <installation.rst>
1515
Modules <modules.rst>
16-
Tutorials <tutorials.md>
16+
Tutorials <tutorials.rst>
1717
Contributing <contributing.rst>
1818
License <license.md>
1919
Citing <citing.rst>
2020

2121
Description
2222
-----------
2323

24-
Right now, the content includes stuff for doing ECT on graphs embedded in 2D. Eventually the goal is to get voxel versions, higher dimensional simplicial complexes, etc in here.
24+
This package provides tools for computing the Euler Characteristic Transform (ECT) of embedded cell complexes efficienctly and provides many useful utilities for visualizing and comparing different ECTs.
2525

2626
For more information on the ECT, see:
2727

@@ -34,7 +34,7 @@ Documentation and tutorials
3434
^^^^^^^^^^^^^^^^^^^^^^^^^^^
3535

3636
* The documentation is available at: `munchlab.github.io/ect <https://munchlab.github.io/ect/>`_
37-
* A tutorial jupyter notebook can be found `here <https://munchlab.github.io/ect/notebooks/Tutorial-ECT_for_embedded_graphs.html>`_
37+
* A comprehensive tutorial for the unified `EmbeddedComplex` class can be found `here <https://munchlab.github.io/ect/notebooks/Tutorial-EmbeddedComplex.html>`_
3838
* The source code can be found at: `github.com/MunchLab/ect <https://github.com/MunchLab/ect>`_
3939

4040
Dependencies

doc_source/modules.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Table of Contents
55
:maxdepth: 2
66

77

8-
Embedded graphs <embed_graph.md>
9-
Embedded CW complex <embed_cw.md>
8+
Embedded Complex <embed_complex.md>
9+
Validation System <validation.md>
1010
ECT on graphs <ect_on_graphs.md>
1111
Directions <directions.md>

0 commit comments

Comments
 (0)