Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1043


Ignore:
Timestamp:
12/20/08 13:54:29 (15 years ago)
Author:
gkronber
Message:

worked on view for CEDMA problems and persistence of CEDMA problems to RDF store. #419 (Refactor CEDMA plugins)

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

Legend:

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

    r992 r1043  
    4545    private Problem problem;
    4646    public Problem Problem {
    47       get { return problem; }
     47      get {
     48        // lazy loading of problem from DB
     49        if (problem == null) {
     50          IList<Statement> persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity));
     51          if (persistedData.Count == 1) {
     52            Literal persistedLiteral = (Literal)persistedData[0].Property;
     53            this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
     54          } else
     55            this.problem = new Problem(); // no entry in the DB => create a new problem
     56        }
     57        return problem;
     58      }
    4859    }
    4960
     
    5263      guid = Guid.NewGuid();
    5364      name = "Data set";
    54       problem = new Problem();
    5565    }
    5666
     
    6070      guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length));
    6171      IList<Statement> names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity));
    62       if(names.Count > 0) name = (string)((Literal)names[0].Property).Value;
     72      if (names.Count > 0) name = (string)((Literal)names[0].Property).Value;
    6373      else name = guid.ToString();
    6474    }
     
    6777      Entity myEntity = new Entity(Ontology.CedmaNameSpace + Guid);
    6878      Store.Add(new Statement(myEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
    69       Store.Add(new Statement(myEntity, Ontology.PredicateSerializedData, new Literal(PersistenceManager.SaveToGZip(problem))));
     79      Store.Add(new Statement(myEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(PersistenceManager.SaveToGZip(problem)))));
    7080      Store.Add(new Statement(myEntity, Ontology.PredicateName, new Literal(name)));
    7181    }
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetListView.cs

    r992 r1043  
    4747
    4848    void dataSetList_Changed(object sender, EventArgs e) {
    49       UpdateControls();
     49      if (InvokeRequired) Invoke((EventHandler)dataSetList_Changed, sender, e);
     50      else UpdateControls();
    5051    }
    5152
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Problem.cs

    r1003 r1043  
    3030
    3131namespace HeuristicLab.CEDMA.Core {
     32
     33  public enum LearningTask {
     34    Classification,
     35    Regression,
     36    TimeSeries,
     37    Clustering
     38  }
     39
    3240  /// <summary>
    3341  /// Problem describes the data mining task.
     
    5967
    6068    private int validationSamplesStart;
    61 
    6269    public int ValidationSamplesStart {
    6370      get { return validationSamplesStart; }
    6471      set { validationSamplesStart = value; }
    6572    }
     73
    6674    private int validationSamplesEnd;
    67 
    6875    public int ValidationSamplesEnd {
    6976      get { return validationSamplesEnd; }
     
    7279
    7380    private int testSamplesStart;
    74 
    7581    public int TestSamplesStart {
    7682      get { return testSamplesStart; }
    7783      set { testSamplesStart = value; }
    7884    }
     85
    7986    private int testSamplesEnd;
    80 
    8187    public int TestSamplesEnd {
    8288      get { return testSamplesEnd; }
     
    95101
    96102    private bool autoRegressive;
    97 
    98103    public bool AutoRegressive {
    99104      get { return autoRegressive; }
     
    101106    }
    102107
    103     private bool timeSeries;
    104 
    105     public bool TimeSeries {
    106       get { return timeSeries; }
    107       set { timeSeries = value; }
     108    private LearningTask learningTask;
     109    public LearningTask LearningTask {
     110      get { return learningTask; }
     111      set { learningTask = value; }
    108112    }
    109113
     
    118122      return new ProblemView(this);
    119123    }
     124
     125    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     126      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     127      node.AppendChild(PersistenceManager.Persist("DataSet", dataset, document, persistedObjects));
     128      XmlAttribute trainingSamplesStartAttr = document.CreateAttribute("TrainingSamplesStart");
     129      trainingSamplesStartAttr.Value = TrainingSamplesStart.ToString();
     130      XmlAttribute trainingSamplesEndAttr = document.CreateAttribute("TrainingSamplesEnd");
     131      trainingSamplesEndAttr.Value = TrainingSamplesEnd.ToString();
     132      XmlAttribute validationSamplesStartAttr = document.CreateAttribute("ValidationSamplesStart");
     133      validationSamplesStartAttr.Value = ValidationSamplesStart.ToString();
     134      XmlAttribute validationSamplesEndAttr = document.CreateAttribute("ValidationSamplesEnd");
     135      validationSamplesEndAttr.Value = ValidationSamplesEnd.ToString();
     136      XmlAttribute testSamplesStartAttr = document.CreateAttribute("TestSamplesStart");
     137      testSamplesStartAttr.Value = TestSamplesStart.ToString();
     138      XmlAttribute testSamplesEndAttr = document.CreateAttribute("TestSamplesEnd");
     139      testSamplesEndAttr.Value = TestSamplesEnd.ToString();
     140      XmlAttribute learningTaskAttr = document.CreateAttribute("LearningTask");
     141      learningTaskAttr.Value = LearningTask.ToString();
     142      XmlAttribute autoRegressiveAttr = document.CreateAttribute("AutoRegressive");
     143      autoRegressiveAttr.Value = AutoRegressive.ToString();
     144
     145      node.Attributes.Append(trainingSamplesStartAttr);
     146      node.Attributes.Append(trainingSamplesEndAttr);
     147      node.Attributes.Append(validationSamplesStartAttr);
     148      node.Attributes.Append(validationSamplesEndAttr);
     149      node.Attributes.Append(testSamplesStartAttr);
     150      node.Attributes.Append(testSamplesEndAttr);
     151      node.Attributes.Append(learningTaskAttr);
     152      node.Attributes.Append(autoRegressiveAttr);
     153
     154      XmlElement targetVariablesElement = document.CreateElement("AllowedTargetVariables");
     155      targetVariablesElement.InnerText = SemiColonSeparatedList(AllowedTargetVariables);
     156      XmlElement inputVariablesElement = document.CreateElement("AllowedInputVariables");
     157      inputVariablesElement.InnerText = SemiColonSeparatedList(AllowedInputVariables);
     158      node.AppendChild(targetVariablesElement);
     159      node.AppendChild(inputVariablesElement);
     160      return node;
     161    }
     162
     163    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     164      base.Populate(node, restoredObjects);
     165      dataset = (HeuristicLab.DataAnalysis.Dataset)PersistenceManager.Restore(node.SelectSingleNode("DataSet"), restoredObjects);
     166      TrainingSamplesStart = int.Parse(node.Attributes["TrainingSamplesStart"].Value);
     167      TrainingSamplesEnd = int.Parse(node.Attributes["TrainingSamplesEnd"].Value);
     168      ValidationSamplesStart = int.Parse(node.Attributes["ValidationSamplesStart"].Value);
     169      ValidationSamplesEnd = int.Parse(node.Attributes["ValidationSamplesEnd"].Value);
     170      TestSamplesStart = int.Parse(node.Attributes["TestSamplesStart"].Value);
     171      TestSamplesEnd = int.Parse(node.Attributes["TestSamplesEnd"].Value);
     172      LearningTask = (LearningTask)Enum.Parse(typeof(LearningTask), node.Attributes["LearningTask"].Value);
     173      AutoRegressive = bool.Parse(node.Attributes["AutoRegressive"].Value);
     174      allowedTargetVariables.Clear();
     175      foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[]{";"}, StringSplitOptions.RemoveEmptyEntries))
     176        allowedTargetVariables.Add(int.Parse(tok));
     177      allowedInputVariables.Clear();
     178      foreach (string tok in node.SelectSingleNode("AllowedInputVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
     179        allowedInputVariables.Add(int.Parse(tok));
     180    }
     181
     182    private string SemiColonSeparatedList(List<int> xs) {
     183      StringBuilder b = new StringBuilder();
     184      foreach (int x in xs) {
     185        b = b.Append(x).Append(";");
     186      }
     187      if (xs.Count > 0) b.Remove(b.Length - 1, 1); // remove last ';'
     188      return b.ToString();
     189    }
    120190  }
    121191}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.Designer.cs

    r1042 r1043  
    6262      this.partitioningGroupBox = new System.Windows.Forms.GroupBox();
    6363      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
     64      this.modelType = new System.Windows.Forms.ComboBox();
     65      this.taskLabel = new System.Windows.Forms.Label();
    6466      this.targetsGroupBox.SuspendLayout();
    6567      this.inputsGroupBox.SuspendLayout();
     
    168170      this.datasetView.Location = new System.Drawing.Point(3, 32);
    169171      this.datasetView.Name = "datasetView";
    170       this.datasetView.Size = new System.Drawing.Size(326, 230);
     172      this.datasetView.Size = new System.Drawing.Size(326, 176);
    171173      this.datasetView.TabIndex = 17;
    172174      //
     
    200202      this.autoregressiveCheckBox.AutoSize = true;
    201203      this.autoregressiveCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
    202       this.autoregressiveCheckBox.Location = new System.Drawing.Point(3, 480);
     204      this.autoregressiveCheckBox.Location = new System.Drawing.Point(215, 424);
    203205      this.autoregressiveCheckBox.Name = "autoregressiveCheckBox";
    204206      this.autoregressiveCheckBox.Size = new System.Drawing.Size(102, 17);
     
    212214      this.targetsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    213215      this.targetsGroupBox.Controls.Add(this.targetsListBox);
    214       this.targetsGroupBox.Location = new System.Drawing.Point(3, 374);
     216      this.targetsGroupBox.Location = new System.Drawing.Point(3, 320);
    215217      this.targetsGroupBox.Name = "targetsGroupBox";
    216218      this.targetsGroupBox.Size = new System.Drawing.Size(167, 100);
     
    223225      this.inputsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    224226      this.inputsGroupBox.Controls.Add(this.inputsListBox);
    225       this.inputsGroupBox.Location = new System.Drawing.Point(176, 374);
     227      this.inputsGroupBox.Location = new System.Drawing.Point(176, 320);
    226228      this.inputsGroupBox.Name = "inputsGroupBox";
    227229      this.inputsGroupBox.Size = new System.Drawing.Size(153, 100);
     
    242244      this.partitioningGroupBox.Controls.Add(this.testSamplesStartTextBox);
    243245      this.partitioningGroupBox.Controls.Add(this.testLabel);
    244       this.partitioningGroupBox.Location = new System.Drawing.Point(3, 268);
     246      this.partitioningGroupBox.Location = new System.Drawing.Point(3, 214);
    245247      this.partitioningGroupBox.Name = "partitioningGroupBox";
    246248      this.partitioningGroupBox.Size = new System.Drawing.Size(326, 100);
     
    256258      this.openFileDialog.Title = "Import data set from file";
    257259      //
     260      // modelType
     261      //
     262      this.modelType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     263      this.modelType.FormattingEnabled = true;
     264      this.modelType.Location = new System.Drawing.Point(88, 422);
     265      this.modelType.Name = "modelType";
     266      this.modelType.Size = new System.Drawing.Size(121, 21);
     267      this.modelType.TabIndex = 26;
     268      this.modelType.SelectedValueChanged += new System.EventHandler(this.modelType_SelectedValueChanged);
     269      //
     270      // taskLabel
     271      //
     272      this.taskLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     273      this.taskLabel.AutoSize = true;
     274      this.taskLabel.Location = new System.Drawing.Point(8, 425);
     275      this.taskLabel.Name = "taskLabel";
     276      this.taskLabel.Size = new System.Drawing.Size(74, 13);
     277      this.taskLabel.TabIndex = 27;
     278      this.taskLabel.Text = "Learning task:";
     279      //
    258280      // ProblemView
    259281      //
    260282      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    261283      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     284      this.Controls.Add(this.taskLabel);
     285      this.Controls.Add(this.modelType);
    262286      this.Controls.Add(this.partitioningGroupBox);
    263287      this.Controls.Add(this.inputsGroupBox);
     
    267291      this.Controls.Add(this.importButton);
    268292      this.Name = "ProblemView";
    269       this.Size = new System.Drawing.Size(337, 500);
     293      this.Size = new System.Drawing.Size(337, 446);
    270294      this.targetsGroupBox.ResumeLayout(false);
    271295      this.inputsGroupBox.ResumeLayout(false);
     
    297321    private System.Windows.Forms.GroupBox partitioningGroupBox;
    298322    private System.Windows.Forms.OpenFileDialog openFileDialog;
     323    private System.Windows.Forms.ComboBox modelType;
     324    private System.Windows.Forms.Label taskLabel;
    299325  }
    300326}
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.cs

    r1042 r1043  
    3939      this.problem = problem;
    4040      InitializeComponent();
     41      foreach (LearningTask l in Enum.GetValues(typeof(LearningTask))) {
     42        modelType.Items.Add(l);
     43      }
     44      UpdateControls();
    4145    }
    4246
    4347    protected override void UpdateControls() {
    4448      base.UpdateControls();
     49      datasetView.Dataset = problem.DataSet;
    4550      trainingSamplesStartTextBox.Text = problem.TrainingSamplesStart.ToString();
    4651      trainingSamplesEndTextBox.Text = problem.TrainingSamplesEnd.ToString();
     
    4954      testSamplesStartTextBox.Text = problem.TestSamplesStart.ToString();
    5055      testSamplesEndTextBox.Text = problem.TestSamplesEnd.ToString();
     56      autoregressiveCheckBox.Checked = problem.AutoRegressive;
     57      for (int i = 0; i < modelType.Items.Count; i++) {
     58        if ((LearningTask)modelType.Items[i] == problem.LearningTask) {
     59          modelType.SelectedIndex = i;
     60          break;
     61        }
     62      }
    5163      targetsListBox.Items.Clear();
    5264      inputsListBox.Items.Clear();
     
    105117      }
    106118
    107     }
    108     private void ShowWarningMessageBox(Exception ex) {
    109       MessageBox.Show(ex.Message,
    110                       "Warning - " + ex.GetType().Name,
    111                       MessageBoxButtons.OK,
    112                       MessageBoxIcon.Warning);
    113     }
    114     private void ShowErrorMessageBox(Exception ex) {
    115       MessageBox.Show(BuildErrorMessage(ex),
    116                       "Error - " + ex.GetType().Name,
    117                       MessageBoxButtons.OK,
    118                       MessageBoxIcon.Error);
    119     }
    120     private string BuildErrorMessage(Exception ex) {
    121       StringBuilder sb = new StringBuilder();
    122       sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
    123 
    124       while (ex.InnerException != null) {
    125         ex = ex.InnerException;
    126         sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
    127       }
    128       return sb.ToString();
    129119    }
    130120
     
    204194      return y0 > x1;
    205195    }
     196    private void ShowWarningMessageBox(Exception ex) {
     197      MessageBox.Show(ex.Message,
     198                      "Warning - " + ex.GetType().Name,
     199                      MessageBoxButtons.OK,
     200                      MessageBoxIcon.Warning);
     201    }
     202    private void ShowErrorMessageBox(Exception ex) {
     203      MessageBox.Show(BuildErrorMessage(ex),
     204                      "Error - " + ex.GetType().Name,
     205                      MessageBoxButtons.OK,
     206                      MessageBoxIcon.Error);
     207    }
     208    private string BuildErrorMessage(Exception ex) {
     209      StringBuilder sb = new StringBuilder();
     210      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     211
     212      while (ex.InnerException != null) {
     213        ex = ex.InnerException;
     214        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     215      }
     216      return sb.ToString();
     217    }
     218
     219    private void modelType_SelectedValueChanged(object sender, EventArgs e) {
     220      if ((LearningTask)modelType.SelectedItem == LearningTask.TimeSeries) autoregressiveCheckBox.Enabled = true;
     221      else autoregressiveCheckBox.Enabled = false;
     222      problem.LearningTask = (LearningTask)modelType.SelectedItem;
     223    }
    206224  }
    207225}
Note: See TracChangeset for help on using the changeset viewer.