Skip to content

Commit 4ae5e39

Browse files
committed
Mosaic Vizrank: Add docstrings
1 parent 0e109f9 commit 4ae5e39

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

Orange/widgets/visualize/owmosaic.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
class MosaicVizRank(VizRankDialog, OWComponent):
32+
"""VizRank dialog for Mosaic"""
3233
captionTitle = "Mosaic Ranking"
3334
K = 10 # for ReliefF
3435
max_attrs = Setting(3)
@@ -37,6 +38,7 @@ class MosaicVizRank(VizRankDialog, OWComponent):
3738
_AttrRole = next(gui.OrangeUserRole)
3839

3940
def __init__(self, master):
41+
"""Add the spin box for maximal number of attributes"""
4042
VizRankDialog.__init__(self, master)
4143
OWComponent.__init__(self, master)
4244

@@ -53,11 +55,16 @@ def __init__(self, master):
5355
self.last_run_max_attr = None
5456

5557
def sizeHint(self):
56-
"""Assuming two columns in the table, return `QSize(320, 512)` as
57-
a reasonable default size."""
5858
return QSize(320, 512)
5959

6060
def run(self):
61+
"""
62+
Add handling of the spin box for maximal number of attributes.
63+
64+
Disable the box before running and enable afterwards.
65+
Also, if the number of attributes is different than in the last run,
66+
reset the saved state (if it was paused).
67+
"""
6168
if self.max_attrs != self.last_run_max_attr:
6269
self.saved_state = None
6370
self.saved_progress = 0
@@ -72,10 +79,17 @@ def run(self):
7279
self.max_attr_spin.setDisabled(False)
7380

7481
def max_attr_changed(self):
82+
"""
83+
Change the button label when the maximal number of attributes changes.
84+
85+
The method does not reset anything so the user can still see the
86+
results until actually restarting the search.
87+
"""
7588
self.button.setText("Start")
7689
self.button.setEnabled(self.check_preconditions())
7790

7891
def check_preconditions(self):
92+
"""Require at least one variable to allow ranking."""
7993
self.Information.add_message("no_attributes", "No variables to rank.")
8094
self.Information.no_attributes.clear()
8195
if not super().check_preconditions():
@@ -86,6 +100,10 @@ def check_preconditions(self):
86100
return True
87101

88102
def score_heuristic(self):
103+
"""
104+
Order attributes by ReliefF or RReliefF if there is a target
105+
variable. In case of ties or without target, other by name.
106+
"""
89107
data = self.master.discrete_data
90108
if data.domain.class_var is None:
91109
return data.domain.attributes
@@ -101,13 +119,22 @@ def _compute_class_dists(self):
101119
master.data.domain.has_discrete_class
102120

103121
def state_count(self):
122+
"""
123+
Return the number of combinations, starting with a single attribute
124+
if Mosaic is colored by class distributions, and two if by Pearson
125+
"""
104126
n_attrs = len(self.master.discrete_data.domain.attributes)
105127
min_attrs = 1 if self._compute_class_dists() else 2
106128
max_attrs = min(n_attrs, self.max_attrs)
107129
return sum(comb(n_attrs, k, exact=True)
108130
for k in range(min_attrs, max_attrs + 1))
109131

110132
def iterate_states(self, state):
133+
"""
134+
Iterate through all combinations of attributes as ordered by Relief,
135+
starting with a single attribute if Mosaic is colored by class
136+
distributions, and two if by Pearson.
137+
"""
111138
# If we put initialization of `self.attrs` to `initialize`,
112139
# `score_heuristic` would be run on every call to `set_data`.
113140
master = self.master
@@ -138,6 +165,13 @@ def iterate_states(self, state):
138165
break
139166

140167
def compute_score(self, state):
168+
"""
169+
Compute score using chi-square test of independence.
170+
171+
If mosaic colors by class distribution, chi-square is computed by
172+
comparing the expected (prior) and observed class distribution in
173+
each cell. Otherwise, compute the independence of the shown attributes.
174+
"""
141175
master = self.master
142176
data = master.discrete_data
143177
domain = data.domain

0 commit comments

Comments
 (0)