Skip to content

Commit

Permalink
owdiscretize: Fix quadratic complexitiy in the num. of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Apr 25, 2018
1 parent 5ab31e9 commit 32fc5f5
Showing 1 changed file with 15 additions and 15 deletions.
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

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

0 comments on commit 32fc5f5

Please sign in to comment.