Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/ProblemView.cs @ 2363

Last change on this file since 2363 was 2290, checked in by gkronber, 15 years ago
  • introduced a variablename to index mapping for SVM models (to make sure we can use the model for prediction in the model analyzer)
  • added support to enable and disable algorithms in the dispatcher and removed DispatcherBase
  • fixed bugs when calculating variable impacts and reading the final model of GP algorithms

#722 (IModel should provide a Predict() method to get predicted values for an input vector)

File size: 9.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Core;
31using HeuristicLab.DataAnalysis;
32using System.Diagnostics;
33using HeuristicLab.CEDMA.Core;
34
35namespace HeuristicLab.CEDMA.Server {
36  public partial class ProblemView : ViewBase {
37    private Problem problem;
38
39    public ProblemView(Problem problem) {
40      this.problem = problem;
41      problem.Changed += (sender, args) => UpdateControls();
42      InitializeComponent();
43      UpdateControls();
44    }
45
46    protected override void UpdateControls() {
47      base.UpdateControls();
48      trainingSamplesStartTextBox.Text = problem.TrainingSamplesStart.ToString();
49      trainingSamplesEndTextBox.Text = problem.TrainingSamplesEnd.ToString();
50      validationSamplesStartTextBox.Text = problem.ValidationSamplesStart.ToString();
51      validationSamplesEndTextBox.Text = problem.ValidationSamplesEnd.ToString();
52      testSamplesStartTextBox.Text = problem.TestSamplesStart.ToString();
53      testSamplesEndTextBox.Text = problem.TestSamplesEnd.ToString();
54      minTimeOffsetTextBox.Text = problem.MinTimeOffset.ToString();
55      maxTimeOffsetTextBox.Text = problem.MaxTimeOffset.ToString();
56      autoregressiveCheckBox.Checked = problem.AutoRegressive;
57      switch (problem.LearningTask) {
58        case LearningTask.Classification: classificationRadioButton.Checked = true; break;
59        case LearningTask.Regression: regressionRadioButton.Checked = true; break;
60        case LearningTask.TimeSeries: timeSeriesRadioButton.Checked = true; break;
61      }
62    }
63
64    private void importButton_Click(object sender, EventArgs e) {
65      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
66        DatasetParser parser = new DatasetParser();
67        bool success = false;
68        try {
69          try {
70            parser.Import(openFileDialog.FileName, true);
71            success = true;
72          }
73          catch (DataFormatException ex) {
74            ShowWarningMessageBox(ex);
75            // not possible to parse strictly => clear and try to parse non-strict
76            parser.Reset();
77            parser.Import(openFileDialog.FileName, false);
78            success = true;
79          }
80        }
81        catch (DataFormatException ex) {
82          // if the non-strict parsing also failed then show the exception
83          ShowErrorMessageBox(ex);
84        }
85        if (success) {
86          Dataset dataset = (Dataset)problem.Dataset;
87          dataset.Rows = parser.Rows;
88          dataset.Columns = parser.Columns;
89          dataset.Name = parser.ProblemName;
90          dataset.Samples = new double[dataset.Rows * dataset.Columns];
91          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
92          datasetView1.Dataset = problem.Dataset;
93
94          problem.TrainingSamplesStart = parser.TrainingSamplesStart;
95          problem.ValidationSamplesEnd = parser.TrainingSamplesStart;
96          problem.TrainingSamplesEnd = parser.TrainingSamplesEnd;
97          problem.ValidationSamplesStart = parser.ValidationSamplesStart;
98          problem.ValidationSamplesEnd = parser.ValidationSamplesEnd;
99          problem.TestSamplesStart = parser.TestSamplesStart;
100          problem.TestSamplesEnd = parser.TestSamplesEnd;
101          for (int i = 0; i < parser.VariableNames.Length; i++) {
102            dataset.SetVariableName(i, parser.VariableNames[i]);
103          }
104
105          problem.FireChanged();
106          Refresh();
107        }
108      }
109    }
110
111    private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
112      problem.AutoRegressive = autoregressiveCheckBox.Checked;
113      problem.FireChanged();
114    }
115
116    private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
117      try {
118        int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
119        int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
120        int validationStart = int.Parse(validationSamplesStartTextBox.Text);
121        int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
122        int testStart = int.Parse(testSamplesStartTextBox.Text);
123        int testEnd = int.Parse(testSamplesEndTextBox.Text);
124        if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
125          trainingEnd >= problem.Dataset.Rows || validationEnd >= problem.Dataset.Rows || testEnd >= problem.Dataset.Rows ||
126          trainingStart >= trainingEnd ||
127          validationStart >= validationEnd ||
128          testStart >= testEnd ||
129          IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
130          IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
131          IsOverlapping(validationStart, validationEnd, testStart, testEnd))
132          ColorSamplesTextBoxes(Color.Red);
133        else
134          ColorSamplesTextBoxes(Color.White);
135      }
136      catch (FormatException ex) {
137        ColorSamplesTextBoxes(Color.Red);
138      }
139    }
140
141    private void samplesTextBox_Validated(object sender, EventArgs e) {
142      problem.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
143      problem.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
144      problem.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
145      problem.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
146      problem.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
147      problem.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
148      problem.FireChanged();
149    }
150
151    private void ColorSamplesTextBoxes(Color color) {
152      trainingSamplesStartTextBox.BackColor = color;
153      trainingSamplesEndTextBox.BackColor = color;
154      validationSamplesStartTextBox.BackColor = color;
155      validationSamplesEndTextBox.BackColor = color;
156      testSamplesStartTextBox.BackColor = color;
157      testSamplesEndTextBox.BackColor = color;
158    }
159
160    private bool IsOverlapping(int x0, int y0, int x1, int y1) {
161      Trace.Assert(x0 <= y0 && x1 <= y1);
162      int tmp;
163      // make sure that x0,y0 is the left interval
164      if (x1 < x0) {
165        tmp = x1;
166        x1 = x0;
167        x0 = tmp;
168        tmp = y1;
169        y1 = y0;
170        y0 = tmp;
171      }
172      return y0 > x1;
173    }
174    private void ShowWarningMessageBox(Exception ex) {
175      MessageBox.Show(ex.Message,
176                      "Warning - " + ex.GetType().Name,
177                      MessageBoxButtons.OK,
178                      MessageBoxIcon.Warning);
179    }
180    private void ShowErrorMessageBox(Exception ex) {
181      MessageBox.Show(BuildErrorMessage(ex),
182                      "Error - " + ex.GetType().Name,
183                      MessageBoxButtons.OK,
184                      MessageBoxIcon.Error);
185    }
186    private string BuildErrorMessage(Exception ex) {
187      StringBuilder sb = new StringBuilder();
188      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
189
190      while (ex.InnerException != null) {
191        ex = ex.InnerException;
192        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
193      }
194      return sb.ToString();
195    }
196
197    private void radioButton_CheckedChanged(object sender, EventArgs e) {
198      minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
199      minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
200      maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
201      maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
202      autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked;
203      autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked;
204      if (timeSeriesRadioButton.Checked) problem.LearningTask = LearningTask.TimeSeries;
205      else if (classificationRadioButton.Checked) problem.LearningTask = LearningTask.Classification;
206      else if (regressionRadioButton.Checked) problem.LearningTask = LearningTask.Regression;
207      problem.FireChanged();
208    }
209
210    private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) {
211      int min, max;
212      e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min);
213      e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max);
214      e.Cancel = min > max;
215    }
216    private void timeOffsetTextBox_Validated(object sender, EventArgs e) {
217      problem.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text);
218      problem.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text);
219      problem.FireChanged();
220    }
221  }
222}
Note: See TracBrowser for help on using the repository browser.