Skip to content

Commit

Permalink
OwLouvain: Display number of cluster in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlin-policar committed Feb 2, 2019
1 parent b20aa02 commit 37c041e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Orange/widgets/unsupervised/owlouvainclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from AnyQt.QtCore import (
Qt, QObject, QTimer, pyqtSignal as Signal, pyqtSlot as Slot
)
from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget
from AnyQt.QtWidgets import QSlider, QCheckBox, QWidget, QLabel

from Orange.clustering.louvain import table_to_knn_graph, Louvain
from Orange.data import Table, DiscreteVariable
Expand Down Expand Up @@ -98,6 +98,10 @@ def __init__(self):
self.__commit_timer = QTimer(self, singleShot=True)
self.__commit_timer.timeout.connect(self.commit)

# Set up UI
info_box = gui.vBox(self.controlArea, "Info")
self.info_label = gui.widgetLabel(info_box, "No data on input.") # type: QLabel

pca_box = gui.vBox(self.controlArea, "PCA Preprocessing")
self.apply_pca_cbx = gui.checkBox(
pca_box, self, "apply_pca", label="Apply PCA preprocessing",
Expand Down Expand Up @@ -248,6 +252,7 @@ def commit(self):
run_on_graph, graph, resolution=self.resolution, state=state
)

self.info_label.setText("Running...")
self.__set_state_busy()
self.__start_task(task, state)

Expand Down Expand Up @@ -282,6 +287,7 @@ def __on_done(self, future):
result = future.result()
except Exception as err: # pylint: disable=broad-except
self.Error.general_error(str(err), exc_info=True)
self.info_label.setText("An error occurred during clustering.")
else:
self.__set_results(result)

Expand Down Expand Up @@ -346,6 +352,11 @@ def __set_results(self, results):
assert results.resolution == self.resolution
assert self.partition is results.partition
self.partition = results.partition

# Display the number of found clusters in the UI
num_clusters = len(np.unique(self.partition))
self.info_label.setText("%d clusters found." % num_clusters)

self._send_data()

def _send_data(self):
Expand Down Expand Up @@ -406,6 +417,8 @@ def set_data(self, data):
self.k_neighbors_spin.setMaximum(min(_MAX_K_NEIGBOURS, len(data) - 1))
self.k_neighbors_spin.setValue(min(_DEFAULT_K_NEIGHBORS, len(data) - 1))

self.info_label.setText("Clustering not yet run.")

self.commit()

def clear(self):
Expand All @@ -416,6 +429,7 @@ def clear(self):
self.partition = None
self.Error.clear()
self.Information.modified.clear()
self.info_label.setText("No data on input.")

def onDeleteWidget(self):
self.__cancel_task(wait=True)
Expand Down

0 comments on commit 37c041e

Please sign in to comment.