Skip to content

Commit

Permalink
OWSVM: Add references to gui elements
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Aug 29, 2016
1 parent cd53d2e commit fa75658
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 51 deletions.
52 changes: 25 additions & 27 deletions Orange/widgets/classify/owsvmclassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _add_kernel_box(self):
def _add_optimization_box(self):
self.optimization_box = gui.vBox(
self.controlArea, "Optimization Parameters")
gui.doubleSpin(
self.tol_spin = gui.doubleSpin(
self.optimization_box, self, "tol", 1e-6, 1.0, 1e-5,
label="Numerical tolerance:",
decimals=6, alignment=Qt.AlignRight, controlWidth=100,
Expand Down Expand Up @@ -129,7 +129,7 @@ class OWSVMClassification(OWBaseSVM):

outputs = [("Support vectors", Table)]

# 0: c_svc, 1: nu_svc
C_SVC, Nu_SVC = 0, 1
svmtype = settings.Setting(0)
C = settings.Setting(1.0)
nu = settings.Setting(0.5)
Expand All @@ -144,32 +144,30 @@ def _add_type_box(self):
self.controlArea, self, "svmtype", [], box="SVM Type",
orientation=form, callback=self.settings_changed)

form.addWidget(gui.appendRadioButton(box, "C-SVM", addToLayout=False),
0, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Cost (C):"),
0, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "C", 1e-3, 1000.0, 0.1,
decimals=3, alignment=Qt.AlignRight,
controlWidth=80, addToLayout=False,
callback=self.settings_changed),
0, 2)

form.addWidget(gui.appendRadioButton(box, "ν-SVM", addToLayout=False),
1, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Complexity (ν):"),
1, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "nu", 0.05, 1.0, 0.05,
decimals=2, alignment=Qt.AlignRight,
controlWidth=80, addToLayout=False,
callback=self.settings_changed),
1, 2)
self.c_radio = gui.appendRadioButton(box, "C-SVM", addToLayout=False)
self.nu_radio = gui.appendRadioButton(box, "ν-SVM", addToLayout=False)
self.c_spin = gui.doubleSpin(
box, self, "C", 1e-3, 1000.0, 0.1, decimals=3,
alignment=Qt.AlignRight, controlWidth=80, addToLayout=False,
callback=self.settings_changed)
self.nu_spin = gui.doubleSpin(
box, self, "nu", 0.05, 1.0, 0.05, decimals=2,
alignment=Qt.AlignRight, controlWidth=80, addToLayout=False,
callback=self.settings_changed)
form.addWidget(self.c_radio, 0, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Cost (C):"), 0, 1, Qt.AlignRight)
form.addWidget(self.c_spin, 0, 2)
form.addWidget(self.nu_radio, 1, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Complexity (ν):"), 1, 1, Qt.AlignRight)
form.addWidget(self.nu_spin, 1, 2)

def _add_optimization_box(self):
super()._add_optimization_box()
gui.spin(self.optimization_box, self, "max_iter", 50, 1e6, 50,
label="Iteration limit:", checked="limit_iter",
alignment=Qt.AlignRight, controlWidth=100,
callback=self.settings_changed)
self.max_iter_spin = gui.spin(
self.optimization_box, self, "max_iter", 50, 1e6, 50,
label="Iteration limit:", checked="limit_iter",
alignment=Qt.AlignRight, controlWidth=100,
callback=self.settings_changed)

def create_learner(self):
kernel = ["linear", "poly", "rbf", "sigmoid"][self.kernel_type]
Expand All @@ -183,14 +181,14 @@ def create_learner(self):
probability=True,
preprocessors=self.preprocessors
)
if self.svmtype == 0:
if self.svmtype == OWSVMClassification.C_SVC:
return SVMLearner(C=self.C, **common_args)
else:
return NuSVMLearner(nu=self.nu, **common_args)

def get_learner_parameters(self):
items = OrderedDict()
if self.svmtype == 0:
if self.svmtype == OWSVMClassification.C_SVC:
items["SVM type"] = "C-SVM, C={}".format(self.C)
else:
items["SVM type"] = "ν-SVM, ν={}".format(self.nu)
Expand Down
45 changes: 21 additions & 24 deletions Orange/widgets/regression/owsvmregression.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,28 @@ def _add_type_box(self):
self.controlArea, self, "svrtype", [], box="SVR Type",
orientation=form)

form.addWidget(gui.appendRadioButton(box, "ε-SVR", addToLayout=False),
0, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Cost (C):"),
0, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "epsilon_C", 0.1, 512.0, 0.1,
decimals=2, addToLayout=False),
0, 2)
form.addWidget(QLabel("Loss epsilon (ε):"),
1, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "epsilon", 0.1, 512.0, 0.1,
decimals=2, addToLayout=False),
1, 2)
self.epsilon_radio = gui.appendRadioButton(box, "ε-SVR",
addToLayout=False)
self.epsilon_C_spin = gui.doubleSpin(box, self, "epsilon_C", 0.1, 512.0,
0.1, decimals=2, addToLayout=False)
self.epsilon_spin = gui.doubleSpin(box, self, "epsilon", 0.1, 512.0,
0.1, decimals=2, addToLayout=False)
form.addWidget(self.epsilon_radio, 0, 0, Qt.AlignLeft)
form.addWidget(QtGui.QLabel("Cost (C):"), 0, 1, Qt.AlignRight)
form.addWidget(self.epsilon_C_spin, 0, 2)
form.addWidget(QLabel("Loss epsilon (ε):"), 1, 1, Qt.AlignRight)
form.addWidget(self.epsilon_spin, 1, 2)

form.addWidget(gui.appendRadioButton(box, "ν-SVR", addToLayout=False),
2, 0, Qt.AlignLeft)
form.addWidget(QLabel("Cost (C):"),
2, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "nu_C", 0.1, 512.0, 0.1,
decimals=2, addToLayout=False),
2, 2)
form.addWidget(QLabel("Complexity bound (ν):"),
3, 1, Qt.AlignRight)
form.addWidget(gui.doubleSpin(box, self, "nu", 0.05, 1.0, 0.05,
decimals=2, addToLayout=False),
3, 2)
self.nu_radio = gui.appendRadioButton(box, "ν-SVR", addToLayout=False)
self.nu_C_spin = gui.doubleSpin(box, self, "nu_C", 0.1, 512.0, 0.1,
decimals=2, addToLayout=False)
self.nu_spin = gui.doubleSpin(box, self, "nu", 0.05, 1.0, 0.05,
decimals=2, addToLayout=False)
form.addWidget(self.nu_radio, 2, 0, Qt.AlignLeft)
form.addWidget(QLabel("Cost (C):"), 2, 1, Qt.AlignRight)
form.addWidget(self.nu_C_spin, 2, 2)
form.addWidget(QLabel("Complexity bound (ν):"), 3, 1, Qt.AlignRight)
form.addWidget(self.nu_spin, 3, 2)

def create_learner(self):
kernel = ["linear", "poly", "rbf", "sigmoid"][self.kernel_type]
Expand Down

0 comments on commit fa75658

Please sign in to comment.