Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/08 11:11:03 (16 years ago)
Author:
gkronber
Message:

worked on control for CEDMA problem importer. #419 (Refactor CEDMA plugins)

Location:
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.Designer.cs

    r1003 r1042  
    4545    private void InitializeComponent() {
    4646      this.importButton = new System.Windows.Forms.Button();
    47       this.textBox1 = new System.Windows.Forms.TextBox();
     47      this.trainingSamplesStartTextBox = new System.Windows.Forms.TextBox();
    4848      this.trainingLabel = new System.Windows.Forms.Label();
    49       this.textBox4 = new System.Windows.Forms.TextBox();
    50       this.textBox2 = new System.Windows.Forms.TextBox();
    51       this.textBox3 = new System.Windows.Forms.TextBox();
     49      this.trainingSamplesEndTextBox = new System.Windows.Forms.TextBox();
     50      this.validationSamplesEndTextBox = new System.Windows.Forms.TextBox();
     51      this.validationSamplesStartTextBox = new System.Windows.Forms.TextBox();
    5252      this.validationLabel = new System.Windows.Forms.Label();
    53       this.textBox5 = new System.Windows.Forms.TextBox();
    54       this.textBox6 = new System.Windows.Forms.TextBox();
     53      this.testSamplesEndTextBox = new System.Windows.Forms.TextBox();
     54      this.testSamplesStartTextBox = new System.Windows.Forms.TextBox();
    5555      this.testLabel = new System.Windows.Forms.Label();
    5656      this.datasetView = new HeuristicLab.DataAnalysis.DatasetView();
     
    7777      this.importButton.Click += new System.EventHandler(this.importButton_Click);
    7878      //
    79       // textBox1
    80       //
    81       this.textBox1.Location = new System.Drawing.Point(119, 17);
    82       this.textBox1.Name = "textBox1";
    83       this.textBox1.Size = new System.Drawing.Size(96, 20);
    84       this.textBox1.TabIndex = 4;
     79      // trainingSamplesStartTextBox
     80      //
     81      this.trainingSamplesStartTextBox.Location = new System.Drawing.Point(119, 17);
     82      this.trainingSamplesStartTextBox.Name = "trainingSamplesStartTextBox";
     83      this.trainingSamplesStartTextBox.Size = new System.Drawing.Size(96, 20);
     84      this.trainingSamplesStartTextBox.TabIndex = 4;
     85      this.trainingSamplesStartTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     86      this.trainingSamplesStartTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
    8587      //
    8688      // trainingLabel
     
    9395      this.trainingLabel.Text = "Training samples:";
    9496      //
    95       // textBox4
    96       //
    97       this.textBox4.Location = new System.Drawing.Point(221, 17);
    98       this.textBox4.Name = "textBox4";
    99       this.textBox4.Size = new System.Drawing.Size(96, 20);
    100       this.textBox4.TabIndex = 10;
    101       //
    102       // textBox2
    103       //
    104       this.textBox2.Location = new System.Drawing.Point(221, 43);
    105       this.textBox2.Name = "textBox2";
    106       this.textBox2.Size = new System.Drawing.Size(96, 20);
    107       this.textBox2.TabIndex = 13;
    108       //
    109       // textBox3
    110       //
    111       this.textBox3.Location = new System.Drawing.Point(119, 43);
    112       this.textBox3.Name = "textBox3";
    113       this.textBox3.Size = new System.Drawing.Size(96, 20);
    114       this.textBox3.TabIndex = 12;
     97      // trainingSamplesEndTextBox
     98      //
     99      this.trainingSamplesEndTextBox.Location = new System.Drawing.Point(221, 17);
     100      this.trainingSamplesEndTextBox.Name = "trainingSamplesEndTextBox";
     101      this.trainingSamplesEndTextBox.Size = new System.Drawing.Size(96, 20);
     102      this.trainingSamplesEndTextBox.TabIndex = 10;
     103      this.trainingSamplesEndTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     104      this.trainingSamplesEndTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
     105      //
     106      // validationSamplesEndTextBox
     107      //
     108      this.validationSamplesEndTextBox.Location = new System.Drawing.Point(221, 43);
     109      this.validationSamplesEndTextBox.Name = "validationSamplesEndTextBox";
     110      this.validationSamplesEndTextBox.Size = new System.Drawing.Size(96, 20);
     111      this.validationSamplesEndTextBox.TabIndex = 13;
     112      this.validationSamplesEndTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     113      this.validationSamplesEndTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
     114      //
     115      // validationSamplesStartTextBox
     116      //
     117      this.validationSamplesStartTextBox.Location = new System.Drawing.Point(119, 43);
     118      this.validationSamplesStartTextBox.Name = "validationSamplesStartTextBox";
     119      this.validationSamplesStartTextBox.Size = new System.Drawing.Size(96, 20);
     120      this.validationSamplesStartTextBox.TabIndex = 12;
     121      this.validationSamplesStartTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     122      this.validationSamplesStartTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
    115123      //
    116124      // validationLabel
     
    123131      this.validationLabel.Text = "Validation samples:";
    124132      //
    125       // textBox5
    126       //
    127       this.textBox5.Location = new System.Drawing.Point(221, 68);
    128       this.textBox5.Name = "textBox5";
    129       this.textBox5.Size = new System.Drawing.Size(96, 20);
    130       this.textBox5.TabIndex = 16;
    131       //
    132       // textBox6
    133       //
    134       this.textBox6.Location = new System.Drawing.Point(119, 68);
    135       this.textBox6.Name = "textBox6";
    136       this.textBox6.Size = new System.Drawing.Size(96, 20);
    137       this.textBox6.TabIndex = 15;
     133      // testSamplesEndTextBox
     134      //
     135      this.testSamplesEndTextBox.Location = new System.Drawing.Point(221, 68);
     136      this.testSamplesEndTextBox.Name = "testSamplesEndTextBox";
     137      this.testSamplesEndTextBox.Size = new System.Drawing.Size(96, 20);
     138      this.testSamplesEndTextBox.TabIndex = 16;
     139      this.testSamplesEndTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     140      this.testSamplesEndTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
     141      //
     142      // testSamplesStartTextBox
     143      //
     144      this.testSamplesStartTextBox.Location = new System.Drawing.Point(119, 68);
     145      this.testSamplesStartTextBox.Name = "testSamplesStartTextBox";
     146      this.testSamplesStartTextBox.Size = new System.Drawing.Size(96, 20);
     147      this.testSamplesStartTextBox.TabIndex = 15;
     148      this.testSamplesStartTextBox.Validated += new System.EventHandler(this.samplesTextBox_Validated);
     149      this.testSamplesStartTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.samplesTextBox_Validating);
    138150      //
    139151      // testLabel
     
    169181      this.targetsListBox.Size = new System.Drawing.Size(153, 79);
    170182      this.targetsListBox.TabIndex = 19;
     183      this.targetsListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.targetsListBox_ItemCheck);
    171184      //
    172185      // inputsListBox
     
    180193      this.inputsListBox.Size = new System.Drawing.Size(141, 79);
    181194      this.inputsListBox.TabIndex = 21;
     195      this.inputsListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputsListBox_ItemCheck);
    182196      //
    183197      // autoregressiveCheckBox
     
    192206      this.autoregressiveCheckBox.Text = "Auto regressive:";
    193207      this.autoregressiveCheckBox.UseVisualStyleBackColor = true;
     208      this.autoregressiveCheckBox.CheckedChanged += new System.EventHandler(this.autoregressiveCheckBox_CheckedChanged);
    194209      //
    195210      // targetsGroupBox
     
    218233      //
    219234      this.partitioningGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    220       this.partitioningGroupBox.Controls.Add(this.textBox2);
     235      this.partitioningGroupBox.Controls.Add(this.validationSamplesEndTextBox);
    221236      this.partitioningGroupBox.Controls.Add(this.trainingLabel);
    222       this.partitioningGroupBox.Controls.Add(this.textBox1);
    223       this.partitioningGroupBox.Controls.Add(this.textBox4);
     237      this.partitioningGroupBox.Controls.Add(this.trainingSamplesStartTextBox);
     238      this.partitioningGroupBox.Controls.Add(this.trainingSamplesEndTextBox);
    224239      this.partitioningGroupBox.Controls.Add(this.validationLabel);
    225       this.partitioningGroupBox.Controls.Add(this.textBox5);
    226       this.partitioningGroupBox.Controls.Add(this.textBox3);
    227       this.partitioningGroupBox.Controls.Add(this.textBox6);
     240      this.partitioningGroupBox.Controls.Add(this.testSamplesEndTextBox);
     241      this.partitioningGroupBox.Controls.Add(this.validationSamplesStartTextBox);
     242      this.partitioningGroupBox.Controls.Add(this.testSamplesStartTextBox);
    228243      this.partitioningGroupBox.Controls.Add(this.testLabel);
    229244      this.partitioningGroupBox.Location = new System.Drawing.Point(3, 268);
     
    265280
    266281    private System.Windows.Forms.Button importButton;
    267     private System.Windows.Forms.TextBox textBox1;
     282    private System.Windows.Forms.TextBox trainingSamplesStartTextBox;
    268283    private System.Windows.Forms.Label trainingLabel;
    269     private System.Windows.Forms.TextBox textBox4;
    270     private System.Windows.Forms.TextBox textBox2;
    271     private System.Windows.Forms.TextBox textBox3;
     284    private System.Windows.Forms.TextBox trainingSamplesEndTextBox;
     285    private System.Windows.Forms.TextBox validationSamplesEndTextBox;
     286    private System.Windows.Forms.TextBox validationSamplesStartTextBox;
    272287    private System.Windows.Forms.Label validationLabel;
    273     private System.Windows.Forms.TextBox textBox5;
    274     private System.Windows.Forms.TextBox textBox6;
     288    private System.Windows.Forms.TextBox testSamplesEndTextBox;
     289    private System.Windows.Forms.TextBox testSamplesStartTextBox;
    275290    private System.Windows.Forms.Label testLabel;
    276291    private HeuristicLab.DataAnalysis.DatasetView datasetView;
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.cs

    r1003 r1042  
    3030using HeuristicLab.Core;
    3131using HeuristicLab.DataAnalysis;
     32using System.Diagnostics;
    3233
    3334namespace HeuristicLab.CEDMA.Core {
     
    4243    protected override void UpdateControls() {
    4344      base.UpdateControls();
    44       // TASK update text-boxes and datasetview
     45      trainingSamplesStartTextBox.Text = problem.TrainingSamplesStart.ToString();
     46      trainingSamplesEndTextBox.Text = problem.TrainingSamplesEnd.ToString();
     47      validationSamplesStartTextBox.Text = problem.ValidationSamplesStart.ToString();
     48      validationSamplesEndTextBox.Text = problem.ValidationSamplesEnd.ToString();
     49      testSamplesStartTextBox.Text = problem.TestSamplesStart.ToString();
     50      testSamplesEndTextBox.Text = problem.TestSamplesEnd.ToString();
     51      targetsListBox.Items.Clear();
     52      inputsListBox.Items.Clear();
     53      for (int i = 0; i < problem.DataSet.Columns; i++) {
     54        targetsListBox.Items.Add(problem.DataSet.VariableNames[i], problem.AllowedTargetVariables.Contains(i));
     55        inputsListBox.Items.Add(problem.DataSet.VariableNames[i], problem.AllowedInputVariables.Contains(i));
     56      }
    4557    }
    4658
    4759    private void importButton_Click(object sender, EventArgs e) {
    48       if(openFileDialog.ShowDialog(this) == DialogResult.OK) {
     60      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    4961        DatasetParser parser = new DatasetParser();
    5062        bool success = false;
     
    5365            parser.Import(openFileDialog.FileName, true);
    5466            success = true;
    55           } catch(DataFormatException ex) {
     67          }
     68          catch (DataFormatException ex) {
    5669            ShowWarningMessageBox(ex);
    5770            // not possible to parse strictly => clear and try to parse non-strict
     
    6073            success = true;
    6174          }
    62         } catch(DataFormatException ex) {
     75        }
     76        catch (DataFormatException ex) {
    6377          // if the non-strict parsing also failed then show the exception
    6478          ShowErrorMessageBox(ex);
    6579        }
    66         if(success) {
     80        if (success) {
    6781          Dataset dataset = (Dataset)problem.DataSet;
    6882          dataset.Rows = parser.Rows;
     
    7286          dataset.Samples = new double[dataset.Rows * dataset.Columns];
    7387          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
     88          datasetView.Dataset = problem.DataSet;
     89
    7490          problem.TrainingSamplesStart = parser.TrainingSamplesStart;
    7591          problem.ValidationSamplesEnd = parser.TrainingSamplesStart;
     
    8298
    8399          List<int> nonInputVariables = parser.NonInputVariables;
    84           for(int i = 0; i < dataset.Columns; i++) {
    85             if(!nonInputVariables.Contains(i)) problem.AllowedInputVariables.Add(i);
     100          for (int i = 0; i < dataset.Columns; i++) {
     101            if (!nonInputVariables.Contains(i)) problem.AllowedInputVariables.Add(i);
    86102          }
    87103          Refresh();
     
    106122      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
    107123
    108       while(ex.InnerException != null) {
     124      while (ex.InnerException != null) {
    109125        ex = ex.InnerException;
    110126        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     
    112128      return sb.ToString();
    113129    }
     130
     131    private void targetsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
     132      if (e.NewValue == CheckState.Checked && !problem.AllowedTargetVariables.Contains(e.Index))
     133        problem.AllowedTargetVariables.Add(e.Index);
     134      else if (e.NewValue == CheckState.Unchecked && problem.AllowedTargetVariables.Contains(e.Index))
     135        problem.AllowedTargetVariables.Remove(e.Index);
     136    }
     137
     138    private void inputsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
     139      if (e.NewValue == CheckState.Checked && !problem.AllowedInputVariables.Contains(e.Index))
     140        problem.AllowedInputVariables.Add(e.Index);
     141      else if (e.NewValue == CheckState.Unchecked && problem.AllowedInputVariables.Contains(e.Index))
     142        problem.AllowedInputVariables.Remove(e.Index);
     143    }
     144
     145    private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
     146      problem.AutoRegressive = autoregressiveCheckBox.Checked;
     147    }
     148
     149    private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
     150      try {
     151        int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
     152        int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
     153        int validationStart = int.Parse(validationSamplesStartTextBox.Text);
     154        int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
     155        int testStart = int.Parse(testSamplesStartTextBox.Text);
     156        int testEnd = int.Parse(testSamplesEndTextBox.Text);
     157        if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
     158          trainingEnd >= problem.DataSet.Rows || validationEnd >= problem.DataSet.Rows || testEnd >= problem.DataSet.Rows ||
     159          trainingStart >= trainingEnd ||
     160          validationStart >= validationEnd ||
     161          testStart >= testEnd ||
     162          IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
     163          IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
     164          IsOverlapping(validationStart, validationEnd, testStart, testEnd))
     165          ColorSamplesTextBoxes(Color.Red);
     166        else
     167          ColorSamplesTextBoxes(Color.White);
     168      }
     169      catch (FormatException ex) {
     170        ColorSamplesTextBoxes(Color.Red);
     171      }
     172    }
     173
     174    private void samplesTextBox_Validated(object sender, EventArgs e) {
     175      problem.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
     176      problem.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
     177      problem.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
     178      problem.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
     179      problem.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
     180      problem.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
     181    }
     182
     183    private void ColorSamplesTextBoxes(Color color) {
     184      trainingSamplesStartTextBox.BackColor = color;
     185      trainingSamplesEndTextBox.BackColor = color;
     186      validationSamplesStartTextBox.BackColor = color;
     187      validationSamplesEndTextBox.BackColor = color;
     188      testSamplesStartTextBox.BackColor = color;
     189      testSamplesEndTextBox.BackColor = color;
     190    }
     191
     192    private bool IsOverlapping(int x0, int y0, int x1, int y1) {
     193      Trace.Assert(x0 <= y0 && x1 <= y1);
     194      int tmp;
     195      // make sure that x0,y0 is the left interval
     196      if (x1 < x0) {
     197        tmp = x1;
     198        x1 = x0;
     199        x0 = tmp;
     200        tmp = y1;
     201        y1 = y0;
     202        y0 = tmp;
     203      }
     204      return y0 > x1;
     205    }
    114206  }
    115207}
Note: See TracChangeset for help on using the changeset viewer.