Skip to content

Commit 892cf33

Browse files
authored
Merge pull request #46 from KrishnaswamyLab/dev
v0.2.8.5: bugfix graph reset and plotting tools
2 parents 7646f35 + 6183eb1 commit 892cf33

File tree

7 files changed

+55
-48
lines changed

7 files changed

+55
-48
lines changed

.travis.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66

77
sudo: required
88

9-
before_install:
10-
- pip install nose2
11-
129
install:
13-
- cd Python
14-
- python setup.py install
15-
- cd ..
10+
- cd Python; python setup.py install; cd ..
1611

1712
script:
18-
- cd Python
13+
- cd Python; pip install -U .[test,doc]
1914
- python setup.py test
20-
- cd doc
21-
- pip install -r source/requirements.txt
22-
- make html
15+
- cd doc; make html; cd ../..

Python/doc/source/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ pandas>=0.21.0
44
scipy>=1.1.0
55
matplotlib
66
future
7-
graphtools>=0.1.7
7+
graphtools>=0.1.8.1
88
sphinx
99
sphinxcontrib-napoleon

Python/phate/phate.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ def _set_graph_params(self, **params):
281281
# graph not defined
282282
pass
283283

284+
def _reset_graph(self):
285+
self.graph = None
286+
self._reset_potential()
287+
288+
def _reset_potential(self):
289+
self.diff_potential = None
290+
self._reset_embedding()
291+
292+
def _reset_embedding(self):
293+
self.embedding = None
294+
284295
def set_params(self, **params):
285296
"""Set the parameters on this estimator.
286297
@@ -443,7 +454,7 @@ def set_params(self, **params):
443454
if 'n_landmark' in params and params['n_landmark'] != self.n_landmark:
444455
if self.n_landmark is None or params['n_landmark'] is None:
445456
# need a different type of graph, reset entirely
446-
self.graph = None
457+
self._reset_graph()
447458
else:
448459
self._set_graph_params(n_landmark=params['n_landmark'])
449460
self.n_landmark = params['n_landmark']
@@ -466,13 +477,11 @@ def set_params(self, **params):
466477

467478
if reset_kernel:
468479
# can't reset the graph kernel without making a new graph
469-
self.graph = None
470-
reset_potential = True
480+
self._reset_graph()
471481
if reset_potential:
472-
reset_embedding = True
473-
self.diff_potential = None
482+
self._reset_potential()
474483
if reset_embedding:
475-
self.embedding = None
484+
self._reset_embedding()
476485

477486
self._check_params()
478487
return self
@@ -583,7 +592,7 @@ def fit(self, X):
583592
If the same data is used, we can reuse existing kernel and
584593
diffusion matrices. Otherwise we have to recompute.
585594
"""
586-
self.graph = None
595+
self._reset_graph()
587596
else:
588597
try:
589598
self.graph.set_params(
@@ -596,7 +605,7 @@ def fit(self, X):
596605
except ValueError as e:
597606
# something changed that should have invalidated the graph
598607
log_debug("Reset graph due to {}".format(str(e)))
599-
self.graph = None
608+
self._reset_graph()
600609

601610
self.X = X
602611

Python/phate/plot.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ def _get_plot_data(data, ndim=None):
5858
def _auto_params(data, c, discrete, cmap, legend):
5959
"""Automatically select nice parameters for a scatter plot
6060
"""
61+
for d in data[1:]:
62+
if d.shape[0] != data[0].shape[0]:
63+
raise ValueError("Expected all axis of data to have the same length"
64+
". Got {}".format([d.shape[0] for d in data]))
6165
if c is not None and not mpl.colors.is_color_like(c):
6266
try:
6367
c = c.values
6468
except AttributeError:
6569
# not a pandas Series
6670
pass
71+
if not len(c) == data[0].shape[0]:
72+
raise ValueError("Expected c of length {} or 1. Got {}".format(
73+
len(c), data.shape[0]))
6774
if discrete is None:
6875
# guess
6976
if isinstance(cmap, dict) or \
@@ -124,7 +131,7 @@ def scatter(data,
124131
xlabel="PHATE1",
125132
ylabel="PHATE2",
126133
zlabel="PHATE3",
127-
legend_title=None,
134+
legend_title="",
128135
**plot_kwargs):
129136
"""Create a scatter plot
130137
@@ -184,7 +191,7 @@ def scatter(data,
184191
Label for the y axis. If None, no label is set.
185192
zlabel : str or None (default : "PHATE3")
186193
Label for the z axis. If None, no label is set. Only used for 3D plots
187-
legend_title : str or None (default: None)
194+
legend_title : str (default: "")
188195
title for the colorbar of legend
189196
**plot_kwargs : keyword arguments
190197
Extra arguments passed to `matplotlib.pyplot.scatter`.
@@ -208,10 +215,12 @@ def scatter(data,
208215
else:
209216
show = False
210217
if legend and not discrete:
211-
im = ax.imshow(np.arange(10).reshape(-1, 1),
218+
im = ax.imshow(np.linspace(np.min(data[1]), np.max(data[1]), 10).reshape(-1, 1),
212219
vmin=np.min(c), vmax=np.max(c), cmap=cmap,
213-
aspect='auto')
220+
aspect='auto', origin='lower')
214221
im.remove()
222+
ax.relim()
223+
ax.autoscale()
215224
try:
216225
if c is not None and not mpl.colors.is_color_like(c):
217226
c = c[plot_idx]

Python/phate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.8.4"
1+
__version__ = "0.2.8.5"

Python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ scipy>=1.1.0
44
matplotlib>=2.0.1
55
scikit-learn>=0.19.1
66
future
7-
graphtools>=0.1.7
7+
graphtools>=0.1.8.1

Python/setup.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
import sys
33
from setuptools import setup
44

5+
install_requires = [
6+
'numpy>=1.14.0',
7+
'pandas>=0.21.0',
8+
'scipy>=1.1.0',
9+
'matplotlib>=2.0.1',
10+
'scikit-learn>=0.19.1',
11+
'future',
12+
'graphtools>=0.1.8.1']
13+
14+
test_requires = [
15+
'nose2']
16+
17+
doc_requires = [
18+
'sphinx',
19+
'sphinxcontrib-napoleon']
20+
521
version_py = os.path.join(os.path.dirname(__file__), 'phate', 'version.py')
622
version = open(version_py).read().strip().split(
723
'=')[-1].replace('"', '').strip()
@@ -18,30 +34,10 @@
1834
author_email='daniel.burkhardt@yale.edu',
1935
packages=['phate', ],
2036
license='GNU General Public License Version 2',
21-
install_requires=['numpy>=1.14.0',
22-
'pandas>=0.21.0',
23-
'scipy>=1.1.0',
24-
'matplotlib>=2.0.1',
25-
'scikit-learn>=0.19.1',
26-
'future',
27-
'graphtools>=0.1.7'],
37+
install_requires=install_requires,
2838
extras_require={
29-
'tests': [
30-
'doctest',
31-
'nose2',
32-
],
33-
'docs': [
34-
'sphinx>=1.6.5',
35-
'sphinx-rtd-theme<0.3',
36-
'readthedocs-sphinx-ext<0.6',
37-
'recommonmark>=0.4.0',
38-
'commonmark>=0.5.4',
39-
'alabaster!=0.7.5,<0.8,>=0.7',
40-
'pillow==2.6.1',
41-
'mock==1.0.1',
42-
'docutils==0.13.1',
43-
'Pygments==2.2.0',
44-
]},
39+
'test': test_requires,
40+
'doc': doc_requires},
4541
test_suite='nose2.collector.collector',
4642
long_description=readme,
4743
url='https://github.com/KrishnaswamyLab/PHATE',

0 commit comments

Comments
 (0)