Skip to content

Commit f54b64f

Browse files
committed
fix button event bindings
1 parent 99520d1 commit f54b64f

4 files changed

Lines changed: 60 additions & 56 deletions

File tree

SVMClassifier/Boundary.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ public static Pixbuf Plot(ManagedArray x, Model model, int width, int height, in
8585

8686
Points(pixbuf, x, classification, f1, f2);
8787

88+
// Plot bounding box
89+
var cw = pixbuf.Width - 1;
90+
var ch = pixbuf.Height;
91+
var border = new Color(128, 128, 128);
92+
93+
Common.Line(pixbuf, 0, 1, cw, 1, border);
94+
Common.Line(pixbuf, cw, 1, cw, ch, border);
95+
Common.Line(pixbuf, 0, ch, cw, ch, border);
96+
Common.Line(pixbuf, 0, 1, 0, ch, border);
97+
8898
ManagedOps.Free(classification);
8999

90100
return pixbuf;
@@ -96,16 +106,6 @@ public static void Plot(Pixbuf pixbuf, ManagedArray x, Model model, int f1 = 0,
96106

97107
Points(pixbuf, x, classification, f1, f2);
98108

99-
// Plot bounding box
100-
var cw = ContourGraph.Width - 1;
101-
var ch = ContourGraph.Height;
102-
var border = new Color(128, 128, 128);
103-
104-
Common.Line(pixbuf, 0, 1, cw, 1, border);
105-
Common.Line(pixbuf, cw, 1, cw, ch, border);
106-
Common.Line(pixbuf, 0, ch, cw, ch, border);
107-
Common.Line(pixbuf, 0, 1, 0, ch, border);
108-
109109
ManagedOps.Free(classification);
110110
}
111111

SVMClassifier/MainWindow.cs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ protected void UpdatePlotTypes()
9797
PlotType.PackStart(cell, false);
9898
PlotType.AddAttribute(cell, "text", 0);
9999
var store = new ListStore(typeof(string));
100+
100101
PlotType.Model = store;
101102

102-
store.AppendValues("Test data points");
103+
store.AppendValues("Data points");
103104
store.AppendValues("Decision boundaries");
104105

105106
PlotType.Active = 0;
@@ -662,64 +663,67 @@ protected void LoadClassifier(string FileName)
662663
{
663664
var json = Utility.LoadJson(FileName);
664665

665-
var models = Utility.Deserialize(json, NormalizationData);
666-
667-
if (models.Count > 0)
666+
if (!string.IsNullOrEmpty(json))
668667
{
669-
ResetModels();
668+
var models = Utility.Deserialize(json, NormalizationData);
670669

671-
Models.AddRange(models);
670+
if (models.Count > 0)
671+
{
672+
ResetModels();
672673

673-
DisableControls();
674+
Models.AddRange(models);
674675

675-
var categories = 0;
676-
var features = 0;
676+
DisableControls();
677677

678-
foreach (var model in models)
679-
{
680-
categories = model.Category > categories ? model.Category : categories;
681-
features = model.ModelX.x > features ? model.ModelX.x : features;
682-
}
683-
684-
if (Models.Count > 0)
685-
{
686-
UpdateTrainedModels(TrainedModelBox, Models);
687-
UpdateTrainedModels(ClassificationModelsBox, Models);
688-
UpdateTrainedModels(PlotModelBox, Models);
678+
var categories = 0;
679+
var features = 0;
689680

690-
ResetModelKernels();
681+
foreach (var model in models)
682+
{
683+
categories = model.Category > categories ? model.Category : categories;
684+
features = model.ModelX.x > features ? model.ModelX.x : features;
685+
}
691686

692-
foreach (var model in Models)
687+
if (Models.Count > 0)
693688
{
694-
var kclass = (int)model.Type;
695-
var kparams = new List<double>();
689+
UpdateTrainedModels(TrainedModelBox, Models);
690+
UpdateTrainedModels(ClassificationModelsBox, Models);
691+
UpdateTrainedModels(PlotModelBox, Models);
696692

697-
for (var i = 0; i < model.KernelParam.Length(); i++)
698-
kparams.Add(Convert.ToDouble(model.KernelParam[i], ci));
693+
ResetModelKernels();
699694

700-
var kernel = new KernelClass(Kernels[kclass].Name, model.Type, kparams, Kernels[kclass].ParameterNames);
695+
foreach (var model in Models)
696+
{
697+
var kclass = (int)model.Type;
698+
var kparams = new List<double>();
701699

702-
ModelKernels.Add(new ModelKernel(kernel, model.Category, model.C, model.Tolerance, model.MaxIterations));
703-
}
700+
for (var i = 0; i < model.KernelParam.Length(); i++)
701+
kparams.Add(Convert.ToDouble(model.KernelParam[i], ci));
704702

705-
UpdateModelsBox(ModelBox, ModelKernels);
706-
}
703+
var kernel = new KernelClass(Kernels[kclass].Name, model.Type, kparams, Kernels[kclass].ParameterNames);
707704

708-
if (DelimiterBox.Active < 0)
709-
DelimiterBox.Active = 0;
705+
ModelKernels.Add(new ModelKernel(kernel, model.Category, model.C, model.Tolerance, model.MaxIterations));
706+
}
710707

711-
UpdateTextView(NormalizationView, NormalizationData);
708+
UpdateModelsBox(ModelBox, ModelKernels);
709+
}
712710

713-
Features.Value = features;
714-
Categories.Value = categories;
711+
if (DelimiterBox.Active < 0)
712+
DelimiterBox.Active = 0;
715713

716-
ClassifierInitialized = true;
717-
TrainingDone = true;
714+
UpdateTextView(NormalizationView, NormalizationData);
718715

719-
TrainingProgress.Text = "Pre-trained models";
720-
TrainingProgress.Fraction = 1;
716+
Features.Value = features;
717+
Categories.Value = categories;
721718

722-
EnableControls();
719+
ClassifierInitialized = true;
720+
TrainingDone = true;
721+
722+
TrainingProgress.Text = "Pre-trained models";
723+
TrainingProgress.Fraction = 1;
724+
725+
EnableControls();
726+
}
723727
}
724728
}
725729

SVMClassifier/gtk-gui/MainWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected virtual void Build()
310310
this.MainNotebook.WidthRequest = 740;
311311
this.MainNotebook.HeightRequest = 510;
312312
this.MainNotebook.Name = "MainNotebook";
313-
this.MainNotebook.CurrentPage = 0;
313+
this.MainNotebook.CurrentPage = 2;
314314
// Container child MainNotebook.Gtk.Notebook+NotebookChild
315315
this.LayoutPageData = new global::Gtk.Fixed();
316316
this.LayoutPageData.Name = "LayoutPageData";
@@ -1317,7 +1317,7 @@ SVM learning algorithms attempt to enhance the distinction between categories b
13171317
this.KernelBox.Changed += new global::System.EventHandler(this.OnKernelBoxChanged);
13181318
this.ModelBox.Changed += new global::System.EventHandler(this.OnModelBoxChanged);
13191319
this.TrainedParametersBox.Changed += new global::System.EventHandler(this.OnTrainedParametersBoxChanged);
1320-
this.SaveTrainedModelButton.Clicked += new global::System.EventHandler(this.OnSaveModelButtonClicked);
1320+
this.SaveTrainedModelButton.Clicked += new global::System.EventHandler(this.OnSaveTrainedModelButton);
13211321
this.OpenTrainedModelButton.Clicked += new global::System.EventHandler(this.OnOpenTrainedModelButtonClicked);
13221322
this.TrainedModelBox.Changed += new global::System.EventHandler(this.OnTrainedModelBoxChanged);
13231323
}

SVMClassifier/gtk-gui/gui.stetic

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<stetic-interface>
33
<configuration>
44
<images-root-path>..</images-root-path>
@@ -899,7 +899,7 @@
899899
<property name="Icon">stock:gtk-save Menu</property>
900900
<property name="Label" translatable="yes" />
901901
<property name="FocusOnClick">False</property>
902-
<signal name="Clicked" handler="OnSaveModelButtonClicked" />
902+
<signal name="Clicked" handler="OnSaveTrainedModelButton" />
903903
</widget>
904904
<packing>
905905
<property name="X">270</property>
@@ -1405,4 +1405,4 @@ SVMClassifier utilizes the free JSON.NET library from https://www.newtonsoft.com
14051405
</widget>
14061406
</child>
14071407
</widget>
1408-
</stetic-interface>
1408+
</stetic-interface>

0 commit comments

Comments
 (0)