Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/RegressionProblemData.cs @ 3368

Last change on this file since 3368 was 3309, checked in by mkommend, 14 years ago

added DataSetChanged event in RegressionProblemData and adapted RegressionProblemDataView to show the included dataset (ticket #983)

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