Skip to content

Commit

Permalink
rename color_function (#195)
Browse files Browse the repository at this point in the history
* rename `color_function`

rename it to `color_values`; raise deprecation warning if old used.

* resolve confusion comment
  • Loading branch information
deargle authored Aug 28, 2020
1 parent 4c573af commit 956b8c9
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ _modules
.tox/
.python-version

# Kepler-Mapper specific things
mapper_visualization_output.html
20 changes: 10 additions & 10 deletions docs/notebooks/Cancer-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
"metadata": {},
"outputs": [],
"source": [
"color_function = lens [:,0] - lens[:,0].min()\n",
"color_values = lens [:,0] - lens[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down Expand Up @@ -471,11 +471,11 @@
],
"source": [
"# visualise scomplex_isoForest\n",
"color_function = lens1[:,0] - lens1[:,0].min()\n",
"color_values = lens1[:,0] - lens1[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex_isoForest, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down Expand Up @@ -537,11 +537,11 @@
],
"source": [
"# visualise scomplex_isoForest_pca\n",
"color_function = isoForest_pca[:,0] - isoForest_pca[:,0].min()\n",
"color_values = isoForest_pca[:,0] - isoForest_pca[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex_isoForest_pca, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down Expand Up @@ -683,11 +683,11 @@
],
"source": [
"# visualise scomplex_radius\n",
"color_function = lens4[:,0] - lens4[:,0].min()\n",
"color_values = lens4[:,0] - lens4[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex_texture, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down Expand Up @@ -749,11 +749,11 @@
],
"source": [
"# visualise scomplex_radius_l2norm\n",
"color_function = texture_l2norm[:,0] - texture_l2norm[:,0].min()\n",
"color_values = texture_l2norm[:,0] - texture_l2norm[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex_texture_l2norm, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/Confidence-Graphs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@
" lens=X_projected_test,\n",
" lens_names=[\"Uncertainty\", \"Error\"],\n",
" custom_tooltips=tooltip_s,\n",
" color_function=color_function_output.values,\n",
" color_values=color_function_output.values,\n",
" title=\"Confidence Graph for a MLP trained on MNIST\",\n",
" path_html=\"confidence_graph_output.html\")"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/KeplerMapper-Newsgroup20-Pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
" projected_X_names=[\"ISOMAP1\", \"ISOMAP2\"],\n",
" title=\"Newsgroups20: Latent Semantic Char-gram Analysis with Isometric Embedding\",\n",
" custom_tooltips=np.array([target_names[ys] for ys in y]),\n",
" color_function=y)\n",
" color_values=y)\n",
"# jupyter.display(\"newsgroups20.html\")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/TOR-XGB-TDA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
"_ = mapper.visualize(\n",
" G,\n",
" custom_tooltips=y,\n",
" color_function=y,\n",
" color_values=y,\n",
" path_html=\"tor-tda.html\",\n",
" inverse_X=X,\n",
" inverse_X_names=list(df[features].columns),\n",
Expand Down
11 changes: 9 additions & 2 deletions docs/reference/stubs/kmapper.adapter.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
kmapper.adapter
kmapper.adapter
===============

.. automodule:: kmapper.adapter







.. rubric:: Functions

.. autosummary::
Expand All @@ -20,4 +24,7 @@ kmapper.adapter








11 changes: 9 additions & 2 deletions docs/reference/stubs/kmapper.jupyter.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
kmapper.jupyter
kmapper.jupyter
===============

.. automodule:: kmapper.jupyter







.. rubric:: Functions

.. autosummary::
Expand All @@ -19,4 +23,7 @@ kmapper.jupyter








4 changes: 2 additions & 2 deletions examples/breast-cancer/breast-cancer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@
"metadata": {},
"outputs": [],
"source": [
"color_function = lens [:,0] - lens[:,0].min()\n",
"color_values = lens [:,0] - lens[:,0].min()\n",
"my_colorscale = pl_brewer\n",
"kmgraph, mapper_summary, colorf_distribution = get_mapper_graph(scomplex, \n",
" color_function, \n",
" color_values, \n",
" color_function_name='Distance to x-min', \n",
" colorscale=my_colorscale)\n",
"\n",
Expand Down
10 changes: 5 additions & 5 deletions examples/digits/digits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The mapper graph nodes associated to this data set are colored according to the `color_function` values with Viridis colorscale,\n",
"The mapper graph nodes associated to this data set are colored according to the `color_values` values with Viridis colorscale,\n",
"which is the default color scale, defined in `plotlyviz`."
]
},
Expand All @@ -90,10 +90,10 @@
"metadata": {},
"outputs": [],
"source": [
"color_function = projected_data[:, 1]-projected_data[:, 1].min()\n",
"color_values = projected_data[:, 1]-projected_data[:, 1].min()\n",
"plotlyviz(scomplex, \n",
" title='Mapper graph of digits dataset',\n",
" color_function=color_function, \n",
" color_values=color_values, \n",
" color_function_name='Distance to y-min', \n",
" node_linecolor='rgb(100,100,100)',\n",
" bgcolor='rgb(240,240,240)',\n",
Expand All @@ -111,10 +111,10 @@
"metadata": {},
"outputs": [],
"source": [
"color_function = projected_data[:, 1]-projected_data[:, 1].min()\n",
"color_values = projected_data[:, 1]-projected_data[:, 1].min()\n",
"plotlyviz(scomplex, \n",
" title='Mapper graph of digits dataset',\n",
" color_function=color_function, \n",
" color_values=color_values, \n",
" color_function_name='Distance to y-min', \n",
" node_linecolor='rgb(100,100,100)',\n",
" bgcolor='rgb(240,240,240)',\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/makecircles/make_circles_distmean.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
mapper.visualize(simplicial_complex, path_html="keplermapper-makecircles-distmean.html",
custom_meta={"Data:": "datasets.make_circles(n_samples=5000, noise=0.05, factor=0.3)"},
custom_tooltips=labels,
color_function=labels)
color_values=labels)
52 changes: 26 additions & 26 deletions examples/output/breast-cancer.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/output/cat.html
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ <h3>n_cubes </h3> <p> 15</p>

<h3>perc_overlap </h3> <p> 0.2</p>

<h3>clusterer </h3> <p> DBSCAN(algorithm='auto', eps=0.1, leaf_size=30, metric='euclidean',<br> metric_params=None, min_samples=5, n_jobs=None, p=None)</p>
<h3>clusterer </h3> <p> DBSCAN(eps=0.1)</p>

<h3>scaler </h3> <p> MinMaxScaler(copy=True, feature_range=(0, 1))</p>
<h3>scaler </h3> <p> MinMaxScaler()</p>



Expand Down
4 changes: 2 additions & 2 deletions examples/output/horse.html
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ <h3>n_cubes </h3> <p> 30</p>

<h3>perc_overlap </h3> <p> 0.2</p>

<h3>clusterer </h3> <p> DBSCAN(algorithm='auto', eps=0.1, leaf_size=30, metric='euclidean',<br> metric_params=None, min_samples=5, n_jobs=None, p=None)</p>
<h3>clusterer </h3> <p> DBSCAN(eps=0.1)</p>

<h3>scaler </h3> <p> MinMaxScaler(copy=True, feature_range=(0, 1))</p>
<h3>scaler </h3> <p> MinMaxScaler()</p>



Expand Down
6 changes: 3 additions & 3 deletions examples/plot_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Digits Dataset
================
This digits example shows two ways of customizing the tooltips options in the HTML visualization. It generates the visualization with tooltips set as the y-label, or number of the image. The second generated result uses the actual image in the tooltips.
This digits example shows two ways of customizing the tooltips options in the HTML visualization. It generates the visualization with tooltips set as the y-label, or number of the image. The second generated result uses the actual image in the tooltips.
`Visualization with y-label tooltip <../../_static/digits_ylabel_tooltips.html>`_
Expand Down Expand Up @@ -63,7 +63,7 @@
mapper.visualize(graph,
title="Handwritten digits Mapper",
path_html="output/digits_custom_tooltips.html",
color_function=labels,
color_values=labels,
custom_tooltips=tooltip_s)
# Tooltips with the target y-labels for every cluster member
mapper.visualize(graph,
Expand All @@ -73,4 +73,4 @@

# Matplotlib examples
km.draw_matplotlib(graph, layout="spring")
plt.show()
plt.show()
15 changes: 11 additions & 4 deletions kmapper/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def draw_matplotlib(g, ax=None, fig=None, layout="kk"):
ax: matplotlib Axes object
A matplotlib axes object to plot graph on. If none, then use ``plt.gca()``
fig: matplotlib Figure object
A matplotlib Figure object to plot graph on. If none, then use ``plt.figure()``
layout: string
Key for which of NetworkX's layout functions.
Key options implemented are:
Key for which of NetworkX's layout functions.
Key options implemented are:
::
>>> "kk": nx.kamada_kawai_layout,
>>> "spring": nx.spring_layout,
>>> "bi": nx.bipartite_layout,
Expand All @@ -41,6 +41,13 @@ def draw_matplotlib(g, ax=None, fig=None, layout="kk"):
"""
import networkx as nx
import os
# https://stackoverflow.com/a/50089385/5917194
import matplotlib as mpl
if os.environ.get('DISPLAY','') == '':
print('no display found. Using non-interactive Agg backend')
mpl.use('Agg')

import matplotlib.pyplot as plt

fig = fig if fig else plt.figure()
Expand Down
27 changes: 16 additions & 11 deletions kmapper/kmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
from .cover import Cover
from .nerve import GraphNerve
from .visuals import (
init_color_function,
init_color_values,
format_meta,
format_mapper_data,
build_histogram,
graph_data_distribution,
colorscale_default,
)
from .utils import deprecated_alias

__all__ = [
"KeplerMapper",
Expand Down Expand Up @@ -601,17 +602,18 @@ def _remove_duplicate_nodes(self, nodes):
return deduped_nodes

def _summary(self, graph, time):
# TODO: this summary is dependant on the type of Nerve being built.
# TODO: this summary is dependent on the type of Nerve being built.
links = graph["links"]
nodes = graph["nodes"]
nr_links = sum(len(v) for k, v in links.items())

print("\nCreated %s edges and %s nodes in %s." % (nr_links, len(nodes), time))

@deprecated_alias(color_function='color_values')
def visualize(
self,
graph,
color_function=None,
color_values=None,
colorscale=None,
custom_tooltips=None,
custom_meta=None,
Expand All @@ -633,6 +635,10 @@ def visualize(
Simplicial complex output from the `map` method.
color_function : list or 1d array
.. deprecated:: 1.4.1
Use `color_values` instead.
color_values : list or 1d array
A 1d vector with length equal to number of data points used to build Mapper. Each value should correspond to a value for each data point and color of node is computed as the average value for members in a node.
colorscale : list
Expand Down Expand Up @@ -693,17 +699,17 @@ def visualize(
>>> "Cluster": "HBSCAN()"}
>>> )
>>> # Custom coloring function based on your 1d lens
>>> # Custom coloring data based on your 1d lens
>>> html = mapper.visualize(
>>> graph,
>>> color_function=lens
>>> color_values=lens
>>> )
>>> # Custom coloring function based on the first variable
>>> # Custom coloring data based on the first variable
>>> cf = mapper.project(X, projection=[0])
>>> html = mapper.visualize(
>>> graph,
>>> color_function=cf
>>> color_values=cf
>>> )
>>> # Customizing the tooltips with binary target variables
Expand Down Expand Up @@ -741,8 +747,7 @@ def visualize(
# Find the module absolute path and locate templates
module_root = os.path.join(os.path.dirname(__file__), "templates")
env = Environment(loader=FileSystemLoader(module_root))
# Color function is a vector of colors?
color_function = init_color_function(graph, color_function)
color_values = init_color_values(graph, color_values)

if X_names is None:
X_names = []
Expand All @@ -752,7 +757,7 @@ def visualize(

mapper_data = format_mapper_data(
graph,
color_function,
color_values,
X,
X_names,
lens,
Expand All @@ -763,7 +768,7 @@ def visualize(
colorscale=colorscale,
)

histogram = graph_data_distribution(graph, color_function, colorscale)
histogram = graph_data_distribution(graph, color_values, colorscale)

mapper_summary = format_meta(graph, custom_meta)

Expand Down
Loading

0 comments on commit 956b8c9

Please sign in to comment.