Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3294 was 3294, checked in by gkronber, 13 years ago

Added first version of architecture altering operators for ADFs. #290 (Implement ADFs)

File size: 4.9 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 { dataset = value; }
44    }
45    private StringValue targetVariable;
46    [Storable]
47    public StringValue TargetVariable {
48      get { return targetVariable; }
49      set { targetVariable = value; }
50    }
51    private ItemList<StringValue> inputVariables;
52    [Storable]
53    public ItemList<StringValue> InputVariables {
54      get { return inputVariables; }
55      set {
56        if (inputVariables != value) {
57          if (value == null) throw new ArgumentNullException();
58          else {
59            inputVariables = value;
60            OnInputVariablesChanged(EventArgs.Empty);
61          }
62        }
63      }
64    }
65    private IntValue trainingSamplesStart;
66    [Storable]
67    public IntValue TrainingSamplesStart {
68      get { return trainingSamplesStart; }
69      set { trainingSamplesStart = value; }
70    }
71    private IntValue trainingSamplesEnd;
72    [Storable]
73    public IntValue TrainingSamplesEnd {
74      get { return trainingSamplesEnd; }
75      set { trainingSamplesEnd = value; }
76    }
77    private IntValue validationSamplesStart;
78    [Storable]
79    public IntValue ValidationSamplesStart {
80      get { return validationSamplesStart; }
81      set { validationSamplesStart = value; }
82    }
83    private IntValue validationSamplesEnd;
84    [Storable]
85    public IntValue ValidationSamplesEnd {
86      get { return validationSamplesEnd; }
87      set { validationSamplesEnd = value; }
88    }
89    private IntValue testSamplesStart;
90    [Storable]
91    public IntValue TestSamplesStart {
92      get { return testSamplesStart; }
93      set { testSamplesStart = value; }
94    }
95    private IntValue testSamplesEnd;
96    [Storable]
97    public IntValue TestSamplesEnd {
98      get { return testSamplesEnd; }
99      set { testSamplesEnd = value; }
100    }
101    #endregion
102
103    public RegressionProblemData()
104      : base() {
105      dataset = new Dataset();
106      targetVariable = new StringValue();
107      inputVariables = new ItemList<StringValue>();
108      trainingSamplesStart = new IntValue();
109      trainingSamplesEnd = new IntValue();
110      validationSamplesStart = new IntValue();
111      validationSamplesEnd = new IntValue();
112      testSamplesStart = new IntValue();
113      testSamplesEnd = new IntValue();
114    }
115
116    [StorableConstructor]
117    private RegressionProblemData(bool deserializing) : base() { }
118
119    #region events
120    public event EventHandler InputVariablesChanged;
121    protected virtual void OnInputVariablesChanged(EventArgs e) {
122      var listeners = InputVariablesChanged;
123      if (listeners != null) listeners(this, e);
124    }
125    #endregion
126
127    public virtual void ImportFromFile(string fileName) {
128      var csvFileParser = new CsvFileParser();
129      csvFileParser.Parse(fileName);
130      Name = "Regression Problem (imported from " + Path.GetFileName(fileName) + ")";
131      Dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
132      Dataset.Name = Path.GetFileName(fileName);
133      TargetVariable = new StringValue(Dataset.VariableNames.First());
134      InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s)));
135      TrainingSamplesStart = new IntValue(0);
136      TrainingSamplesEnd = new IntValue(csvFileParser.Rows);
137      TestSamplesStart = new IntValue(0);
138      TestSamplesEnd = new IntValue(csvFileParser.Rows);
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.