Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Problem.cs @ 1208

Last change on this file since 1208 was 1043, checked in by gkronber, 16 years ago

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

File size: 7.7 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.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Xml;
28using HeuristicLab.CEDMA.DB.Interfaces;
29using HeuristicLab.Operators;
30
31namespace HeuristicLab.CEDMA.Core {
32
33  public enum LearningTask {
34    Classification,
35    Regression,
36    TimeSeries,
37    Clustering
38  }
39
40  /// <summary>
41  /// Problem describes the data mining task.
42  /// Contains the actual data and meta-data:
43  ///  * which variables should be modelled
44  ///  * regression, time-series or classification problem
45  /// </summary>
46  public class Problem : ItemBase {
47    private string name;
48    public string Name {
49      get { return name; }
50    }
51    private HeuristicLab.DataAnalysis.Dataset dataset;
52    public HeuristicLab.DataAnalysis.Dataset DataSet {
53      get { return dataset; }
54    }
55
56    private int trainingSamplesStart;
57    public int TrainingSamplesStart {
58      get { return trainingSamplesStart; }
59      set { trainingSamplesStart = value; }
60    }
61
62    private int trainingSamplesEnd;
63    public int TrainingSamplesEnd {
64      get { return trainingSamplesEnd; }
65      set { trainingSamplesEnd = value; }
66    }
67
68    private int validationSamplesStart;
69    public int ValidationSamplesStart {
70      get { return validationSamplesStart; }
71      set { validationSamplesStart = value; }
72    }
73
74    private int validationSamplesEnd;
75    public int ValidationSamplesEnd {
76      get { return validationSamplesEnd; }
77      set { validationSamplesEnd = value; }
78    }
79
80    private int testSamplesStart;
81    public int TestSamplesStart {
82      get { return testSamplesStart; }
83      set { testSamplesStart = value; }
84    }
85
86    private int testSamplesEnd;
87    public int TestSamplesEnd {
88      get { return testSamplesEnd; }
89      set { testSamplesEnd = value; }
90    }
91
92    private List<int> allowedInputVariables;
93    public List<int> AllowedInputVariables {
94      get { return allowedInputVariables; }
95    }
96
97    private List<int> allowedTargetVariables;
98    public List<int> AllowedTargetVariables {
99      get { return allowedTargetVariables; }
100    }
101
102    private bool autoRegressive;
103    public bool AutoRegressive {
104      get { return autoRegressive; }
105      set { autoRegressive = value; }
106    }
107
108    private LearningTask learningTask;
109    public LearningTask LearningTask {
110      get { return learningTask; }
111      set { learningTask = value; }
112    }
113
114    public Problem()
115      : base() {
116      dataset = new DataAnalysis.Dataset();
117      allowedInputVariables = new List<int>();
118      allowedTargetVariables = new List<int>();
119    }
120
121    public override IView CreateView() {
122      return new ProblemView(this);
123    }
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    }
190  }
191}
Note: See TracBrowser for help on using the repository browser.