Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/09 20:23:47 (15 years ago)
Author:
gkronber
Message:

Refactored CEDMA dispatcher and CEDMA server view to allow different modeling scenarios for each variable. #754

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs

    r2290 r2375  
    88using System.Windows.Forms;
    99using HeuristicLab.Core;
     10using System.Diagnostics;
    1011
    1112namespace HeuristicLab.CEDMA.Server {
    1213  public partial class DispatcherView : ViewBase {
    1314    private SimpleDispatcher dispatcher;
     15    private ProblemSpecification selectedSpec;
    1416    public DispatcherView(SimpleDispatcher dispatcher)
    1517      : base() {
    1618      this.dispatcher = dispatcher;
    1719      InitializeComponent();
     20      dispatcher.Changed += (sender, args) => UpdateControls();
    1821      UpdateControls();
    19       dispatcher.Changed += (sender, args) => UpdateControls();
    2022      this.inputVariableList.CheckOnClick = true;
    2123    }
     
    3436        }
    3537
    36         foreach (string inputVar in dispatcher.InputVariables) {
     38        foreach (string inputVar in dispatcher.Variables) {
    3739          inputVariableList.Items.Add(inputVar, false);
    3840        }
    3941
    40         foreach (HeuristicLab.Modeling.IAlgorithm algo in dispatcher.Algorithms) {
    41           algorithmsListBox.Items.Add(algo, false);
    42         }
    4342        targetVariableList.ClearSelected();
    4443        inputVariableList.Enabled = false;
     
    5554
    5655    private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
    57       string selectedTarget = (string)targetVariableList.SelectedItem;
    5856      if (e.NewValue == CheckState.Checked) {
    59         dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
     57        selectedSpec.AddInputVariable((string)inputVariableList.Items[e.Index]);
    6058      } else if (e.NewValue == CheckState.Unchecked) {
    61         dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
     59        selectedSpec.RemoveInputVariable((string)inputVariableList.Items[e.Index]);
    6260      }
    6361    }
     
    6563    private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
    6664      string selectedTarget = (string)targetVariableList.SelectedItem;
    67       UpdateInputVariableList(selectedTarget);
    68     }
    69 
    70     private void UpdateInputVariableList(string target) {
     65      selectedSpec = dispatcher.GetProblemSpecification(selectedTarget);
     66      UpdateInputVariableList();
     67      UpdateAlgorithms();
     68    }
     69
     70    private void UpdateAlgorithms() {
     71      learningTaskGroupBox.Enabled = true;
     72      algorithmsListBox.Enabled = true;
     73      switch (selectedSpec.LearningTask) {
     74        case LearningTask.Classification: {
     75            classificationRadioButton.Checked = true;
     76            break;
     77          }
     78        case LearningTask.Regression: {
     79            regressionRadioButton.Checked = true;
     80            break;
     81          }
     82        case LearningTask.TimeSeries: {
     83            regressionRadioButton.Checked = true;
     84            break;
     85          }
     86        default: { break; }
     87      }
     88      algorithmsListBox.Items.Clear();
     89      foreach (HeuristicLab.Modeling.IAlgorithm algo in dispatcher.GetAlgorithms(selectedSpec.LearningTask)) {
     90        algorithmsListBox.Items.Add(algo, dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable).Contains(algo));
     91      }
     92      UpdateAlgorithmConfiguration();
     93    }
     94
     95    private void UpdateAlgorithmConfiguration() {
     96      partitioningGroupBox.Enabled = true;
     97      trainingSamplesStartTextBox.Text = selectedSpec.TrainingSamplesStart.ToString();
     98      trainingSamplesEndTextBox.Text = selectedSpec.TrainingSamplesEnd.ToString();
     99      validationSamplesStartTextBox.Text = selectedSpec.ValidationSamplesStart.ToString();
     100      validationSamplesEndTextBox.Text = selectedSpec.ValidationSamplesEnd.ToString();
     101      testSamplesStartTextBox.Text = selectedSpec.TestSamplesStart.ToString();
     102      testSamplesEndTextBox.Text = selectedSpec.TestSamplesEnd.ToString();
     103    }
     104
     105    private void UpdateInputVariableList() {
    71106      inputVariableList.Items.Clear();
    72       var activatedInputVariables = dispatcher.GetInputVariables(target);
    73       foreach (string inputVar in dispatcher.InputVariables) {
     107      var activatedInputVariables = selectedSpec.InputVariables;
     108      foreach (string inputVar in dispatcher.Variables) {
    74109        inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
    75110      }
     
    77112    }
    78113
    79     private void setAllButton_Click(object sender, EventArgs e) {     
     114    private void setAllButton_Click(object sender, EventArgs e) {
    80115      foreach (string targetVar in dispatcher.TargetVariables) {
     116        ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
    81117        for (int i = 0; i < inputVariableList.Items.Count; i++) {
    82118          if (inputVariableList.GetItemChecked(i)) {
    83             dispatcher.EnableInputVariable(targetVar, (string)inputVariableList.Items[i]);
     119            spec.AddInputVariable((string)inputVariableList.Items[i]);
    84120          } else {
    85             dispatcher.DisableInputVariable(targetVar, (string)inputVariableList.Items[i]);
     121            spec.RemoveInputVariable((string)inputVariableList.Items[i]);
    86122          }
    87123        }
     
    90126
    91127    private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
    92       if(e.NewValue == CheckState.Checked) {
    93         dispatcher.EnableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
    94       } else if(e.NewValue == CheckState.Unchecked) {
    95         dispatcher.DisableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
    96       }
     128      if (e.NewValue == CheckState.Checked) {
     129        dispatcher.EnableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
     130      } else if (e.NewValue == CheckState.Unchecked) {
     131        dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
     132      }
     133    }
     134
     135    private void radioButton_CheckedChanged(object sender, EventArgs e) {
     136      string selectedTarget = (string)targetVariableList.SelectedItem;
     137      minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
     138      minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
     139      maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
     140      maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
     141      autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked;
     142      autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked;
     143      if (timeSeriesRadioButton.Checked) selectedSpec.LearningTask = LearningTask.TimeSeries;
     144      else if (classificationRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Classification;
     145      else if (regressionRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Regression;
     146      UpdateAlgorithms();
     147    }
     148
     149    private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) {
     150      int min, max;
     151      e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min);
     152      e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max);
     153      e.Cancel = min > max;
     154    }
     155
     156    private void timeOffsetTextBox_Validated(object sender, EventArgs e) {
     157      selectedSpec.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text);
     158      selectedSpec.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text);
     159    }
     160
     161    private void samplesTextBox_Validated(object sender, EventArgs e) {
     162      selectedSpec.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
     163      selectedSpec.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
     164      selectedSpec.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
     165      selectedSpec.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
     166      selectedSpec.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
     167      selectedSpec.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
     168    }
     169
     170    private void ColorSamplesTextBoxes(Color color) {
     171      trainingSamplesStartTextBox.BackColor = color;
     172      trainingSamplesEndTextBox.BackColor = color;
     173      validationSamplesStartTextBox.BackColor = color;
     174      validationSamplesEndTextBox.BackColor = color;
     175      testSamplesStartTextBox.BackColor = color;
     176      testSamplesEndTextBox.BackColor = color;
     177    }
     178
     179    private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
     180      try {
     181        int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
     182        int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
     183        int validationStart = int.Parse(validationSamplesStartTextBox.Text);
     184        int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
     185        int testStart = int.Parse(testSamplesStartTextBox.Text);
     186        int testEnd = int.Parse(testSamplesEndTextBox.Text);
     187        if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
     188          trainingEnd >= selectedSpec.Dataset.Rows || validationEnd >= selectedSpec.Dataset.Rows || testEnd >= selectedSpec.Dataset.Rows ||
     189          trainingStart >= trainingEnd ||
     190          validationStart >= validationEnd ||
     191          testStart >= testEnd ||
     192          IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
     193          IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
     194          IsOverlapping(validationStart, validationEnd, testStart, testEnd))
     195          ColorSamplesTextBoxes(Color.Red);
     196        else
     197          ColorSamplesTextBoxes(Color.White);
     198      }
     199      catch (FormatException) {
     200        ColorSamplesTextBoxes(Color.Red);
     201      }
     202    }
     203
     204    private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
     205      selectedSpec.AutoRegressive = autoregressiveCheckBox.Checked;
     206    }
     207
     208    private bool IsOverlapping(int x0, int y0, int x1, int y1) {
     209      Trace.Assert(x0 <= y0 && x1 <= y1);
     210      int tmp;
     211      // make sure that x0,y0 is the left interval
     212      if (x1 < x0) {
     213        tmp = x1;
     214        x1 = x0;
     215        x0 = tmp;
     216        tmp = y1;
     217        y1 = y0;
     218        y0 = tmp;
     219      }
     220      return y0 > x1;
    97221    }
    98222  }
Note: See TracChangeset for help on using the changeset viewer.