Skip to content

Commit

Permalink
OwLouvain: Move data preprocessing to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlin-policar committed Feb 11, 2019
1 parent 1fa8e7a commit ee5d4f3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Orange/widgets/unsupervised/owlouvainclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def __init__(self):
callback=lambda: self._on_auto_commit_changed(),
) # type: QWidget

def _preprocess_data(self):
if self.preprocessed_data is None:
if self.normalize:
normalizer = preprocess.Normalize(center=False)
self.preprocessed_data = normalizer(self.data)
else:
self.preprocessed_data = self.data

def _apply_pca_changed(self):
self.controls.pca_components.setEnabled(self.apply_pca)
self._invalidate_graph()
Expand Down Expand Up @@ -208,11 +216,9 @@ def cancel(self):
self.__set_state_ready()

def commit(self):
# pylint: disable=too-many-branches
self.__commit_timer.stop()
self.__invalidated = False
self._set_modified(False)
self.Error.clear()

# Cancel current running task
self.__cancel_task(wait=False)
Expand All @@ -221,24 +227,14 @@ def commit(self):
self.__set_state_ready()
return

# Make sure the dataset is ok
if len(self.data.domain.attributes) < 1:
self.Error.empty_dataset()
self.__set_state_ready()
return
self.Error.clear()

if self.partition is not None:
self.__set_state_ready()
self._send_data()
return

# Preprocess the dataset
if self.preprocessed_data is None:
if self.normalize:
normalizer = preprocess.Normalize(center=False)
self.preprocessed_data = normalizer(self.data)
else:
self.preprocessed_data = self.data
self._preprocess_data()

state = TaskState(self)

Expand Down Expand Up @@ -425,6 +421,12 @@ def set_data(self, data):
# Clear internal state
self.clear()
self._invalidate_pca_projection()

# Make sure the dataset is ok
if self.data is not None and len(self.data.domain.attributes) < 1:
self.Error.empty_dataset()
self.data = None

if self.data is None:
return

Expand Down

0 comments on commit ee5d4f3

Please sign in to comment.