Skip to content

Commit

Permalink
owsgd: Allow tol toggling + migrate settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzagar committed Feb 23, 2018
1 parent 936cf1f commit 9d208e8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Orange/widgets/model/owsgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class OWSGD(OWBaseLearner):
]
priority = 90

settings_version = 2

LEARNER = SGDLearner

class Outputs(OWBaseLearner.Outputs):
Expand Down Expand Up @@ -78,6 +80,7 @@ class Outputs(OWBaseLearner.Outputs):
power_t = Setting(.25)
max_iter = Setting(1000)
tol = Setting(1e-3)
tol_enabled = Setting(True)

def add_main_layout(self):
self._add_algorithm_to_layout()
Expand Down Expand Up @@ -158,8 +161,8 @@ def _add_learning_params_to_layout(self):

self.tol_spin = gui.spin(
box, self, 'tol', 0, 10., .1e-3, spinType=float, controlWidth=80,
label='Tolerance (stopping criterion): ', alignment=Qt.AlignRight,
callback=self.settings_changed)
label='Tolerance (stopping criterion): ', checked='tol_enabled',
alignment=Qt.AlignRight, callback=self.settings_changed)
gui.separator(box, height=12)

# Wrap shuffle_cbx inside another hbox to align it with the random_seed
Expand Down Expand Up @@ -255,7 +258,7 @@ def create_learner(self):
eta0=self.eta0,
power_t=self.power_t,
max_iter=self.max_iter,
tol=self.tol,
tol=self.tol if self.tol_enabled else None,
preprocessors=self.preprocessors,
**params)

Expand Down Expand Up @@ -315,6 +318,12 @@ def update_model(self):
coeffs.name = "coefficients"
self.Outputs.coefficients.send(coeffs)

@classmethod
def migrate_settings(cls, settings_, version):
if version < 2:
settings_["max_iter"] = settings_.pop("n_iter", 5)
settings_["tol_enabled"] = False


if __name__ == '__main__':
import sys
Expand All @@ -328,4 +337,4 @@ def update_model(self):
ow.set_data(d)
ow.show()
a.exec_()
ow.saveSettings()
ow.saveSettings()

0 comments on commit 9d208e8

Please sign in to comment.