Skip to content
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

[FIX] owdiscretize: Fix quadratic complexitiy in the n variables #3016

Merged
merged 1 commit into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Orange/widgets/data/owdiscretize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import namedtuple
from typing import Optional # pylint: disable=unused-import

from AnyQt.QtWidgets import (
QListView, QHBoxLayout, QStyledItemDelegate, QApplication
Expand Down Expand Up @@ -146,7 +147,7 @@ class Outputs:
want_main_area = False
resizing_enabled = False

def __init__(self):
def __init__(self):
super().__init__()

#: input data
Expand Down Expand Up @@ -433,14 +434,11 @@ def selected_indices(self):
rows = self.varview.selectionModel().selectedRows()
return [index.row() for index in rows]

def discretized_var(self, source):
index = list(self.varmodel).index(source)
def discretized_var(self, index):
# type: (int) -> Optional[Orange.data.DiscreteVariable]
state = self.var_state[index]
if state.disc_var is None:
return None
elif state.disc_var is source:
return source
elif state.points == []:
if state.disc_var is not None and state.points == []:
# Removed by MDL Entropy
return None
else:
return state.disc_var
Expand All @@ -452,20 +450,22 @@ def discretized_domain(self):
if self.data is None:
return None

# a mapping of all applied changes for variables in `varmodel`
mapping = {var: self.discretized_var(i)
for i, var in enumerate(self.varmodel)}

def disc_var(source):
if source and source.is_continuous:
return self.discretized_var(source)
else:
return source
return mapping.get(source, source)

# map the full input domain to the new variables (where applicable)
attributes = [disc_var(v) for v in self.data.domain.attributes]
attributes = [v for v in attributes if v is not None]

class_var = disc_var(self.data.domain.class_var)
class_vars = [disc_var(v) for v in self.data.domain.class_vars]
class_vars = [v for v in class_vars if v is not None]

domain = Orange.data.Domain(
attributes, class_var,
metas=self.data.domain.metas
attributes, class_vars, metas=self.data.domain.metas
)
return domain

Expand Down