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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 | using HeuristicLab.DataAnalysis;
|
---|
32 | using System.Diagnostics;
|
---|
33 | using HeuristicLab.CEDMA.Core;
|
---|
34 |
|
---|
35 | namespace 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 | for (int i = 0; i < parser.VariableNames.Length; i++) {
|
---|
90 | dataset.SetVariableName(i, parser.VariableNames[i]);
|
---|
91 | }
|
---|
92 | dataset.Name = parser.ProblemName;
|
---|
93 | dataset.Samples = new double[dataset.Rows * dataset.Columns];
|
---|
94 | Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
|
---|
95 | datasetView1.Dataset = problem.Dataset;
|
---|
96 |
|
---|
97 | problem.TrainingSamplesStart = parser.TrainingSamplesStart;
|
---|
98 | problem.ValidationSamplesEnd = parser.TrainingSamplesStart;
|
---|
99 | problem.TrainingSamplesEnd = parser.TrainingSamplesEnd;
|
---|
100 | problem.ValidationSamplesStart = parser.ValidationSamplesStart;
|
---|
101 | problem.ValidationSamplesEnd = parser.ValidationSamplesEnd;
|
---|
102 | problem.TestSamplesStart = parser.TestSamplesStart;
|
---|
103 | problem.TestSamplesEnd = parser.TestSamplesEnd;
|
---|
104 | problem.FireChanged();
|
---|
105 | Refresh();
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
111 | problem.AutoRegressive = autoregressiveCheckBox.Checked;
|
---|
112 | }
|
---|
113 |
|
---|
114 | private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
115 | try {
|
---|
116 | int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
|
---|
117 | int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
|
---|
118 | int validationStart = int.Parse(validationSamplesStartTextBox.Text);
|
---|
119 | int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
|
---|
120 | int testStart = int.Parse(testSamplesStartTextBox.Text);
|
---|
121 | int testEnd = int.Parse(testSamplesEndTextBox.Text);
|
---|
122 | if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
|
---|
123 | trainingEnd >= problem.Dataset.Rows || validationEnd >= problem.Dataset.Rows || testEnd >= problem.Dataset.Rows ||
|
---|
124 | trainingStart >= trainingEnd ||
|
---|
125 | validationStart >= validationEnd ||
|
---|
126 | testStart >= testEnd ||
|
---|
127 | IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
|
---|
128 | IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
|
---|
129 | IsOverlapping(validationStart, validationEnd, testStart, testEnd))
|
---|
130 | ColorSamplesTextBoxes(Color.Red);
|
---|
131 | else
|
---|
132 | ColorSamplesTextBoxes(Color.White);
|
---|
133 | }
|
---|
134 | catch (FormatException ex) {
|
---|
135 | ColorSamplesTextBoxes(Color.Red);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | private void samplesTextBox_Validated(object sender, EventArgs e) {
|
---|
140 | problem.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
|
---|
141 | problem.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
|
---|
142 | problem.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
|
---|
143 | problem.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
|
---|
144 | problem.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
|
---|
145 | problem.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
|
---|
146 | }
|
---|
147 |
|
---|
148 | private void ColorSamplesTextBoxes(Color color) {
|
---|
149 | trainingSamplesStartTextBox.BackColor = color;
|
---|
150 | trainingSamplesEndTextBox.BackColor = color;
|
---|
151 | validationSamplesStartTextBox.BackColor = color;
|
---|
152 | validationSamplesEndTextBox.BackColor = color;
|
---|
153 | testSamplesStartTextBox.BackColor = color;
|
---|
154 | testSamplesEndTextBox.BackColor = color;
|
---|
155 | }
|
---|
156 |
|
---|
157 | private bool IsOverlapping(int x0, int y0, int x1, int y1) {
|
---|
158 | Trace.Assert(x0 <= y0 && x1 <= y1);
|
---|
159 | int tmp;
|
---|
160 | // make sure that x0,y0 is the left interval
|
---|
161 | if (x1 < x0) {
|
---|
162 | tmp = x1;
|
---|
163 | x1 = x0;
|
---|
164 | x0 = tmp;
|
---|
165 | tmp = y1;
|
---|
166 | y1 = y0;
|
---|
167 | y0 = tmp;
|
---|
168 | }
|
---|
169 | return y0 > x1;
|
---|
170 | }
|
---|
171 | private void ShowWarningMessageBox(Exception ex) {
|
---|
172 | MessageBox.Show(ex.Message,
|
---|
173 | "Warning - " + ex.GetType().Name,
|
---|
174 | MessageBoxButtons.OK,
|
---|
175 | MessageBoxIcon.Warning);
|
---|
176 | }
|
---|
177 | private void ShowErrorMessageBox(Exception ex) {
|
---|
178 | MessageBox.Show(BuildErrorMessage(ex),
|
---|
179 | "Error - " + ex.GetType().Name,
|
---|
180 | MessageBoxButtons.OK,
|
---|
181 | MessageBoxIcon.Error);
|
---|
182 | }
|
---|
183 | private string BuildErrorMessage(Exception ex) {
|
---|
184 | StringBuilder sb = new StringBuilder();
|
---|
185 | sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
186 |
|
---|
187 | while (ex.InnerException != null) {
|
---|
188 | ex = ex.InnerException;
|
---|
189 | sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
190 | }
|
---|
191 | return sb.ToString();
|
---|
192 | }
|
---|
193 |
|
---|
194 | #region gui events
|
---|
195 | private void radioButton_CheckedChanged(object sender, EventArgs e) {
|
---|
196 | minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
|
---|
197 | minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
|
---|
198 | maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
|
---|
199 | maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
|
---|
200 | autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked;
|
---|
201 | autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked;
|
---|
202 | if (timeSeriesRadioButton.Checked) problem.LearningTask = LearningTask.TimeSeries;
|
---|
203 | else if (classificationRadioButton.Checked) problem.LearningTask = LearningTask.Classification;
|
---|
204 | else if (regressionRadioButton.Checked) problem.LearningTask = LearningTask.Regression;
|
---|
205 | }
|
---|
206 |
|
---|
207 | private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
208 | int min, max;
|
---|
209 | e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min);
|
---|
210 | e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max);
|
---|
211 | e.Cancel = min > max;
|
---|
212 | }
|
---|
213 | private void timeOffsetTextBox_Validated(object sender, EventArgs e) {
|
---|
214 | problem.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text);
|
---|
215 | problem.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text);
|
---|
216 | }
|
---|
217 | #endregion
|
---|
218 | }
|
---|
219 | }
|
---|