Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs @ 3373

Last change on this file since 3373 was 3373, checked in by gkronber, 15 years ago

Refactored HeuristicLab.Problems.DataAnalysis namespace. #938 (Data types and operators for regression problems)

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Parameters;
28using HeuristicLab.Data;
29using HeuristicLab.Problems.DataAnalysis;
30using System.Drawing;
31using System.IO;
32
33namespace HeuristicLab.Problems.DataAnalysis {
34  [Item("DataAnalysisProblemData", "Represents an item containing all data defining a data analysis problem.")]
35  [StorableClass]
36  public class DataAnalysisProblemData : NamedItem {
37    #region properties
38    private Dataset dataset;
39    [Storable]
40    public Dataset Dataset {
41      get { return dataset; }
42      set {
43        if (dataset != value) {
44          if (value == null) throw new ArgumentNullException();
45          else {
46            dataset = value;
47            OnDatasetChanged(EventArgs.Empty);
48          }
49        }
50      }
51    }
52    private StringValue targetVariable;
53    [Storable]
54    public StringValue TargetVariable {
55      get { return targetVariable; }
56      set { targetVariable = value; }
57    }
58    private ItemList<StringValue> inputVariables;
59    [Storable]
60    public ItemList<StringValue> InputVariables {
61      get { return inputVariables; }
62      set {
63        if (inputVariables != value) {
64          if (value == null) throw new ArgumentNullException();
65          else {
66            inputVariables = value;
67            OnInputVariablesChanged(EventArgs.Empty);
68          }
69        }
70      }
71    }
72    private IntValue trainingSamplesStart;
73    [Storable]
74    public IntValue TrainingSamplesStart {
75      get { return trainingSamplesStart; }
76      set { trainingSamplesStart = value; }
77    }
78    private IntValue trainingSamplesEnd;
79    [Storable]
80    public IntValue TrainingSamplesEnd {
81      get { return trainingSamplesEnd; }
82      set { trainingSamplesEnd = value; }
83    }
84    private IntValue validationSamplesStart;
85    [Storable]
86    public IntValue ValidationSamplesStart {
87      get { return validationSamplesStart; }
88      set { validationSamplesStart = value; }
89    }
90    private IntValue validationSamplesEnd;
91    [Storable]
92    public IntValue ValidationSamplesEnd {
93      get { return validationSamplesEnd; }
94      set { validationSamplesEnd = value; }
95    }
96    private IntValue testSamplesStart;
97    [Storable]
98    public IntValue TestSamplesStart {
99      get { return testSamplesStart; }
100      set { testSamplesStart = value; }
101    }
102    private IntValue testSamplesEnd;
103    [Storable]
104    public IntValue TestSamplesEnd {
105      get { return testSamplesEnd; }
106      set { testSamplesEnd = value; }
107    }
108    #endregion
109
110    public DataAnalysisProblemData()
111      : base() {
112      dataset = new Dataset();
113      targetVariable = new StringValue();
114      inputVariables = new ItemList<StringValue>();
115      trainingSamplesStart = new IntValue();
116      trainingSamplesEnd = new IntValue();
117      validationSamplesStart = new IntValue();
118      validationSamplesEnd = new IntValue();
119      testSamplesStart = new IntValue();
120      testSamplesEnd = new IntValue();
121    }
122
123    [StorableConstructor]
124    private DataAnalysisProblemData(bool deserializing) : base() { }
125
126    #region events
127    public event EventHandler InputVariablesChanged;
128    protected virtual void OnInputVariablesChanged(EventArgs e) {
129      var listeners = InputVariablesChanged;
130      if (listeners != null) listeners(this, e);
131    }
132
133    public event EventHandler DatasetChanged;
134    protected virtual void OnDatasetChanged(EventArgs e) {
135      EventHandler handler = DatasetChanged;
136      if (handler != null) handler(this, e);
137    }
138    #endregion
139
140    public virtual void ImportFromFile(string fileName) {
141      var csvFileParser = new CsvFileParser();
142      csvFileParser.Parse(fileName);
143      Name = "Data imported from " + Path.GetFileName(fileName);
144      Dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
145      Dataset.Name = Path.GetFileName(fileName);
146      TargetVariable = new StringValue(Dataset.VariableNames.First());
147      InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s)));
148      TrainingSamplesStart = new IntValue(0);
149      TrainingSamplesEnd = new IntValue(csvFileParser.Rows);
150      TestSamplesStart = new IntValue(0);
151      TestSamplesEnd = new IntValue(csvFileParser.Rows);
152    }
153  }
154}
Note: See TracBrowser for help on using the repository browser.