Skip to content

Commit

Permalink
Merge pull request #3358 from VesnaT/fix_owfreeviz
Browse files Browse the repository at this point in the history
[FIX]OWFreeViz: Fix optimization for data with missing values
  • Loading branch information
janezd authored Nov 6, 2018
2 parents 1fe7a11 + 3e2bd8d commit dec74fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Orange/widgets/visualize/owfreeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ def prepare_projection_data(self):
self._X = self._Y = self.valid_data = None
return

self._X = self.data.X.copy()
self._X -= np.nanmean(self._X, axis=0)
span = np.ptp(self._X[self.valid_data], axis=0)
self._X = self.data.X[self.valid_data]
self._X -= np.mean(self._X, axis=0)
span = np.ptp(self._X, axis=0)
self._X[:, span > 0] /= span[span > 0].reshape(1, -1)

self._Y = self.data.Y
self._Y = self.data.Y[self.valid_data]
if self.data.domain.class_var.is_discrete:
self._Y = self._Y.astype(int)

Expand All @@ -370,9 +370,10 @@ def init_embedding_coords(self):
def get_embedding(self):
if self.data is None:
return None
embedding = np.dot(self._X, self.projection)
embedding /= \
np.max(np.linalg.norm(embedding[self.valid_data], axis=1)) or 1
EX = np.dot(self._X, self.projection)
EX /= np.max(np.linalg.norm(EX, axis=1)) or 1
embedding = np.zeros((len(self.data), 2), dtype=np.float)
embedding[self.valid_data] = EX
return embedding

def get_anchors(self):
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/visualize/tests/test_owfreeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_error_msg(self):
self.assertFalse(self.widget.Error.not_enough_class_vars.is_shown())

def test_optimization(self):
self.send_signal(self.widget.Inputs.data, self.data)
self.send_signal(self.widget.Inputs.data, self.heart_disease)
self.widget.btn_start.click()

def test_optimization_cancelled(self):
Expand Down
1 change: 1 addition & 0 deletions Orange/widgets/visualize/utils/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def clear(self):
self.data = None
self.valid_data = None
self.selection = None
self.graph.selection = None

def onDeleteWidget(self):
super().onDeleteWidget()
Expand Down

0 comments on commit dec74fb

Please sign in to comment.