Skip to content

Commit

Permalink
Refactor igraph.Graph output of Nerve, modify fit behaviour of Nerv…
Browse files Browse the repository at this point in the history
…e, add `store_edge_elements` kwarg to Nerve and make_mapper_pipeline, add Nerve and ParallelClustering to docs (giotto-ai#447)

* Refactor igraph.Graph output, add Nerve and ParallelClustering to docs, add store_edge_elements kwarg to Nerve and make_mapper_pipeline

- Store node metadata not as a graph-level dictionary, but as vertex attributes accessible by graph.vs[attr_name][node_id] or graph.vs[node_id][attr_name] for attr_name in ["pullback_set_label", "partial_cluster_label", "node_elements"]
- Remove "node_id" from node attributes as it always coincided with the igraph.Graph node number anyway.
- Automatically store sizes of intersections as edge weights, accessible by graph.es["weight"].
- Add "store_intersections" kwarg to Nerve and make_mapper_pipeline to allow storing indices of node intersections as edge attributes, accessible via graph.es["edge_elements"].
- Simplify logic of Nerve.fit_transform code
- Change the attributes stored by Nerve.fit. Now the entire graph is stored as graph_ instead.
- Improve documentation of make_mapper_pipeline
- Expose ParallelClustering and Nerve in __init__ and docs.
- Adapt tests, mapper quickstart notebook, and mapper plotting functions.

* Add two tests for the behaviour of store_edge_elements and min_intersection

* Remove check for shape of `layout` in _calculate_graph_data

`layout` can only be a string or a callable, not an ndarray

* Improve test coverage of mapper visualization modules

* Create tests for plot_betti_surfaces and plot_betti_curves

* Add plotly_params to remaining plot methods in diagrams/representations, missed out in giotto-ai#441 

* Fix some linting and docstrings

* Minor improvements

* Avoid shadowing range function in plot_diagram
  • Loading branch information
ulupo committed Aug 4, 2020
1 parent 9b425b1 commit 4bc90b2
Show file tree
Hide file tree
Showing 20 changed files with 717 additions and 385 deletions.
13 changes: 13 additions & 0 deletions doc/modules/mapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ Clustering

mapper.FirstSimpleGap
mapper.FirstHistogramGap
mapper.ParallelClustering

Nerve (graph construction)
--------------------------

.. currentmodule:: gtda

.. autosummary::
:toctree: generated/mapper/nerve/
:template: class.rst

mapper.Nerve


Pipeline
--------
Expand Down
31 changes: 11 additions & 20 deletions examples/mapper_quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The resulting graph is a [`python-igraph`](https://igraph.org/python/) object that contains metadata that is stored in the form of dictionaries. We can access this data as follows:"
"The resulting graph is a [`python-igraph`](https://igraph.org/python/) object which stores node metadata in the form of attributes. We can access this data as follows:"
]
},
{
Expand All @@ -351,14 +351,14 @@
"metadata": {},
"outputs": [],
"source": [
"graph[\"node_metadata\"].keys()"
"graph.vs.attributes()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here `node_id` is a globally unique node identifier used to construct the graph, while `pullback_set_label` and `partial_cluster_label` refer to the interval and cluster sets described above. The `node_elements` refers to the indices of our original data that belong to each node. For example, to find which points belong to the first node of the graph we can access the desired data as follows:"
"Here `'pullback_set_label'` and `'partial_cluster_label'` refer to the interval and cluster sets described above. `'node_elements'` refers to the indices of our original data that belong to each node. For example, to find which points belong to the first node of the graph we can access the desired data as follows:"
]
},
{
Expand All @@ -367,23 +367,14 @@
"metadata": {},
"outputs": [],
"source": [
"node_id, node_elements = (\n",
" graph[\"node_metadata\"][\"node_id\"],\n",
" graph[\"node_metadata\"][\"node_elements\"],\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\n",
" \"Node ID: {}, \\nNode elements: {}, \\nData points: {}\".format(\n",
" node_id[0], node_elements[0], data[node_elements[0]]\n",
" )\n",
")"
"node_id = 0\n",
"node_elements = graph.vs[\"node_elements\"]\n",
"\n",
"print(f\"\"\"\n",
"Node ID: {node_id}\n",
"Node elements: {node_elements[node_id]}\n",
"Data points: {data[node_elements[node_id]]}\n",
"\"\"\")"
]
},
{
Expand Down
Loading

0 comments on commit 4bc90b2

Please sign in to comment.