-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[WIP][ENH] Neighbors: data info displayed in status bar #4141
Changes from all commits
58286ee
7d240ed
cf23784
a11a988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,12 +64,6 @@ def __init__(self): | |
self.reference = None | ||
self.distances = None | ||
|
||
box = gui.vBox(self.controlArea, "Info") | ||
self.data_info_label = gui.widgetLabel(box, "") | ||
self.reference_info_label = gui.widgetLabel(box, "") | ||
self._set_label_text("data") | ||
self._set_label_text("reference") | ||
|
||
box = gui.vBox(self.controlArea, box=True) | ||
gui.comboBox( | ||
box, self, "distance_index", orientation=Qt.Horizontal, | ||
|
@@ -88,24 +82,53 @@ def __init__(self): | |
|
||
self.apply_button = gui.auto_apply(self.controlArea, self, commit=self.apply) | ||
|
||
def _set_label_text(self, name): | ||
data = getattr(self, name) | ||
label = getattr(self, f"{name}_info_label") | ||
if data is None: | ||
label.setText(f"No {name} instances") | ||
def _set_input_summary(self): | ||
n_data, n_refs = 0, 0 | ||
if self.data is not None and self.reference is not None: | ||
n_data = len(self.data) | ||
n_refs = len(self.reference) | ||
elif self.data is not None: | ||
n_data = len(self.data) | ||
elif self.reference is not None: | ||
n_refs = len(self.reference) | ||
else: | ||
pl = "s" if data else "" | ||
label.setText(f"{len(data)} {name} instance{pl} on input.") | ||
self.info.set_input_summary(self.info.NoInput) | ||
return | ||
|
||
inst = f"{n_data} | {n_refs} " | ||
if n_data > 0 and n_refs > 0: | ||
details = f"{n_data} data instances on input; " \ | ||
f"{n_refs} reference instances on input " | ||
elif n_data > 0 and n_refs == 0: | ||
details = f"{n_data} data instances on input; " \ | ||
f"No reference instances on input " | ||
elif n_data == 0 and n_refs > 0: | ||
details = f"No data instances on input; " \ | ||
f"{n_refs} reference instances on input " | ||
|
||
self.info.set_input_summary(inst, details) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A shorter version:
|
||
|
||
def _set_output_summary(self): | ||
if self.data is None: | ||
self.Outputs.data.send(None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outputting the data is already handled in |
||
self.info.set_output_summary(self.info.NoOutput) | ||
return | ||
|
||
indices = self._compute_indices() | ||
if np.any(indices): | ||
neighbors = self._data_with_similarity(indices) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calculating the neighbors just for sake of the info is wasteful, and unnecessary. |
||
self.Outputs.data.send(neighbors) | ||
self.info.set_output_summary(str(len(neighbors))) | ||
|
||
@Inputs.data | ||
def set_data(self, data): | ||
self.data = data | ||
self._set_label_text("data") | ||
self._set_input_summary() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can place this into |
||
|
||
@Inputs.reference | ||
def set_ref(self, refs): | ||
self.reference = refs | ||
self._set_label_text("reference") | ||
self._set_input_summary() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
def handleNewSignals(self): | ||
self.compute_distances() | ||
|
@@ -146,6 +169,7 @@ def apply(self): | |
else: | ||
neighbors = self._data_with_similarity(indices) | ||
self.Outputs.data.send(neighbors) | ||
self._set_output_summary() | ||
|
||
def _compute_indices(self): | ||
self.Warning.all_data_as_reference.clear() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,7 +541,7 @@ def __init__(self, parent=None, **kwargs): | |
fixedrb = QRadioButton("Fixed", checked=True) | ||
group.addButton(fixedrb, RandomFeatureSelectEditor.Fixed) | ||
kspin = QSpinBox( | ||
minimum=1, value=self.__k, | ||
minimum=1, maximum=10000000, value=self.__k, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should be removed from this PR. |
||
enabled=self.__strategy == RandomFeatureSelectEditor.Fixed | ||
) | ||
kspin.valueChanged[int].connect(self.setK) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can shorten this by:
and move the following
else
statement into the secondif