Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] MDS: Handle subset data #3620

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Orange/widgets/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,21 @@ def test_plot_once(self, timeout=DEFAULT_TIMEOUT):
self.widget.setup_plot.assert_called_once()
self.widget.commit.assert_called_once()

def test_subset_data_color(self, timeout=DEFAULT_TIMEOUT):
self.send_signal(self.widget.Inputs.data, self.data)

if self.widget.isBlocking():
spy = QSignalSpy(self.widget.blockingStateChanged)
self.assertTrue(spy.wait(timeout))

self.send_signal(self.widget.Inputs.data_subset, self.data[:10])
subset = [brush.color().name() == "#46befa" for brush in
self.widget.graph.scatterplot_item.data['brush'][:10]]
other = [brush.color().name() == "#000000" for brush in
self.widget.graph.scatterplot_item.data['brush'][10:]]
self.assertTrue(all(subset))
self.assertTrue(all(other))

def test_class_density(self, timeout=DEFAULT_TIMEOUT):
"""Check class density update"""
self.send_signal(self.widget.Inputs.data, self.data)
Expand Down
27 changes: 12 additions & 15 deletions Orange/widgets/unsupervised/owmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def __init__(self):
#: Input data table
self.signal_data = None

self.__invalidated = True
self.embedding = None
self.effective_matrix = None

Expand Down Expand Up @@ -243,7 +242,7 @@ def clear(self):
def _initialize(self):
matrix_existed = self.effective_matrix is not None
effective_matrix = self.effective_matrix
self.__invalidated = True
self._invalidated = True
self.data = None
self.effective_matrix = None
self.closeContext()
Expand Down Expand Up @@ -285,11 +284,11 @@ def _initialize(self):

self.init_attr_values()
self.openContext(self.data)
self.__invalidated = not (matrix_existed and
self.effective_matrix is not None and
np.array_equal(effective_matrix,
self.effective_matrix))
if self.__invalidated:
self._invalidated = not (matrix_existed and
self.effective_matrix is not None and
np.array_equal(effective_matrix,
self.effective_matrix))
if self._invalidated:
self.clear()
self.graph.set_effective_matrix(self.effective_matrix)

Expand Down Expand Up @@ -444,12 +443,15 @@ def __next_step(self):

def do_PCA(self):
self.__invalidate_embedding(self.PCA)
self.setup_plot()

def do_random(self):
self.__invalidate_embedding(self.Random)
self.setup_plot()

def do_jitter(self):
self.__invalidate_embedding(self.Jitter)
self.setup_plot()

def __invalidate_embedding(self, initialization=PCA):
def jitter_coord(part):
Expand All @@ -476,8 +478,6 @@ def jitter_coord(part):
jitter_coord(self.embedding[:, 0])
jitter_coord(self.embedding[:, 1])

self.setup_plot()

# restart the optimization if it was interrupted.
if state == OWMDS.Running:
self.__start()
Expand All @@ -496,15 +496,12 @@ def __invalidate_refresh(self):

def handleNewSignals(self):
self._initialize()
if self.__invalidated:
if self._invalidated:
self.graph.pause_drawing_pairs()
self.__invalidated = False
self.__invalidate_embedding()
self.cb_class_density.setEnabled(self.can_draw_density())
self.enable_controls()
self.start()
else:
self.graph.update_point_props()
self.commit()
super().handleNewSignals()

def _invalidate_output(self):
self.commit()
Expand Down
16 changes: 9 additions & 7 deletions Orange/widgets/visualize/utils/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ def set_subset_data(self, subset):
self.controls.graph.alpha_value.setEnabled(subset is None)

def handleNewSignals(self):
self._handle_subset_data()
if self._invalidated:
self._invalidated = False
self.setup_plot()
else:
self.graph.update_point_props()
self.commit()

def _handle_subset_data(self):
self.Warning.subset_independent.clear()
self.Warning.subset_not_subset.clear()
if self.data is None or self.subset_data is None:
Expand All @@ -471,13 +480,6 @@ def handleNewSignals(self):
elif self.subset_indices - ids:
self.Warning.subset_not_subset()

if self._invalidated:
self._invalidated = False
self.setup_plot()
else:
self.graph.update_point_props()
self.commit()

def get_subset_mask(self):
if not self.subset_indices:
return None
Expand Down