Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/3.3/Problem.cs @ 1913

Last change on this file since 1913 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 8.8 KB
RevLine 
[957]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 {
[1287]32
33  public enum LearningTask {
34    Classification,
35    Regression,
36    TimeSeries,
37    Clustering
38  }
39
[957]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>
[1287]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 int minTimeOffset;
109    public int MinTimeOffset {
110      get { return minTimeOffset; }
111      set { minTimeOffset = value; }
112    }
113
114    private int maxTimeOffset;
115    public int MaxTimeOffset {
116      get { return maxTimeOffset; }
117      set { maxTimeOffset = value; }
118    }
119
120    private LearningTask learningTask;
121    public LearningTask LearningTask {
122      get { return learningTask; }
123      set { learningTask = value; }
124    }
125
[957]126    public Problem()
127      : base() {
[1287]128      dataset = new DataAnalysis.Dataset();
129      allowedInputVariables = new List<int>();
130      allowedTargetVariables = new List<int>();
[957]131    }
[1287]132
133
134    public string GetVariableName(int index) {
135      return dataset.GetVariableName(index);
136    }
137
138    public override IView CreateView() {
139      return new ProblemView(this);
140    }
141
142    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
143      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
144      node.AppendChild(PersistenceManager.Persist("DataSet", dataset, document, persistedObjects));
145      XmlAttribute trainingSamplesStartAttr = document.CreateAttribute("TrainingSamplesStart");
146      trainingSamplesStartAttr.Value = TrainingSamplesStart.ToString();
147      XmlAttribute trainingSamplesEndAttr = document.CreateAttribute("TrainingSamplesEnd");
148      trainingSamplesEndAttr.Value = TrainingSamplesEnd.ToString();
149      XmlAttribute validationSamplesStartAttr = document.CreateAttribute("ValidationSamplesStart");
150      validationSamplesStartAttr.Value = ValidationSamplesStart.ToString();
151      XmlAttribute validationSamplesEndAttr = document.CreateAttribute("ValidationSamplesEnd");
152      validationSamplesEndAttr.Value = ValidationSamplesEnd.ToString();
153      XmlAttribute testSamplesStartAttr = document.CreateAttribute("TestSamplesStart");
154      testSamplesStartAttr.Value = TestSamplesStart.ToString();
155      XmlAttribute testSamplesEndAttr = document.CreateAttribute("TestSamplesEnd");
156      testSamplesEndAttr.Value = TestSamplesEnd.ToString();
157      XmlAttribute learningTaskAttr = document.CreateAttribute("LearningTask");
158      learningTaskAttr.Value = LearningTask.ToString();
159      XmlAttribute autoRegressiveAttr = document.CreateAttribute("AutoRegressive");
160      autoRegressiveAttr.Value = AutoRegressive.ToString();
161      XmlAttribute minTimeOffsetAttr = document.CreateAttribute("MinTimeOffset");
162      minTimeOffsetAttr.Value = MinTimeOffset.ToString();
163      XmlAttribute maxTimeOffsetAttr = document.CreateAttribute("MaxTimeOffset");
164      maxTimeOffsetAttr.Value = MaxTimeOffset.ToString();
165
166      node.Attributes.Append(trainingSamplesStartAttr);
167      node.Attributes.Append(trainingSamplesEndAttr);
168      node.Attributes.Append(validationSamplesStartAttr);
169      node.Attributes.Append(validationSamplesEndAttr);
170      node.Attributes.Append(testSamplesStartAttr);
171      node.Attributes.Append(testSamplesEndAttr);
172      node.Attributes.Append(learningTaskAttr);
173      node.Attributes.Append(autoRegressiveAttr);
174      node.Attributes.Append(minTimeOffsetAttr);
175      node.Attributes.Append(maxTimeOffsetAttr);
176
177      XmlElement targetVariablesElement = document.CreateElement("AllowedTargetVariables");
178      targetVariablesElement.InnerText = SemiColonSeparatedList(AllowedTargetVariables);
179      XmlElement inputVariablesElement = document.CreateElement("AllowedInputVariables");
180      inputVariablesElement.InnerText = SemiColonSeparatedList(AllowedInputVariables);
181      node.AppendChild(targetVariablesElement);
182      node.AppendChild(inputVariablesElement);
183      return node;
184    }
185
186    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
187      base.Populate(node, restoredObjects);
188      dataset = (HeuristicLab.DataAnalysis.Dataset)PersistenceManager.Restore(node.SelectSingleNode("DataSet"), restoredObjects);
189      TrainingSamplesStart = int.Parse(node.Attributes["TrainingSamplesStart"].Value);
190      TrainingSamplesEnd = int.Parse(node.Attributes["TrainingSamplesEnd"].Value);
191      ValidationSamplesStart = int.Parse(node.Attributes["ValidationSamplesStart"].Value);
192      ValidationSamplesEnd = int.Parse(node.Attributes["ValidationSamplesEnd"].Value);
193      TestSamplesStart = int.Parse(node.Attributes["TestSamplesStart"].Value);
194      TestSamplesEnd = int.Parse(node.Attributes["TestSamplesEnd"].Value);
195      LearningTask = (LearningTask)Enum.Parse(typeof(LearningTask), node.Attributes["LearningTask"].Value);
196      AutoRegressive = bool.Parse(node.Attributes["AutoRegressive"].Value);
197      if (node.Attributes["MinTimeOffset"] != null)
198        MinTimeOffset = XmlConvert.ToInt32(node.Attributes["MinTimeOffset"].Value);
199      else MinTimeOffset = 0;
200      if (node.Attributes["MaxTimeOffset"] != null)
201        MaxTimeOffset = XmlConvert.ToInt32(node.Attributes["MaxTimeOffset"].Value);
202      else MaxTimeOffset = 0;
203
204      allowedTargetVariables.Clear();
205      foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
206        allowedTargetVariables.Add(int.Parse(tok));
207      allowedInputVariables.Clear();
208      foreach (string tok in node.SelectSingleNode("AllowedInputVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
209        allowedInputVariables.Add(int.Parse(tok));
210    }
211
212    private string SemiColonSeparatedList(List<int> xs) {
213      StringBuilder b = new StringBuilder();
214      foreach (int x in xs) {
215        b = b.Append(x).Append(";");
216      }
217      if (xs.Count > 0) b.Remove(b.Length - 1, 1); // remove last ';'
218      return b.ToString();
219    }
[957]220  }
221}
Note: See TracBrowser for help on using the repository browser.