Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/RegressionProblem.cs @ 3283

Last change on this file since 3283 was 3264, checked in by gkronber, 14 years ago

Implemented import of CSV files for regression problems. #938 (Data types and operators for regression problems)

File size: 6.7 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("RegressionProblem", "Represents a regression problem.")]
36  [Creatable("Problems")]
37  [StorableClass]
38  public class RegressionProblem : ParameterizedNamedItem {
39    public override Image ItemImage {
40      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
41    }
42
43    #region Parameter Properties
44    public ValueParameter<Dataset> DatasetParameter {
45      get { return (ValueParameter<Dataset>)Parameters["Dataset"]; }
46    }
47    public ValueParameter<StringValue> TargetVariableParameter {
48      get { return (ValueParameter<StringValue>)Parameters["TargetVariable"]; }
49    }
50    public ValueParameter<ItemList<StringValue>> InputVariablesParameter {
51      get { return (ValueParameter<ItemList<StringValue>>)Parameters["InputVariables"]; }
52    }
53    public ValueParameter<IntValue> TrainingSamplesStartParameter {
54      get { return (ValueParameter<IntValue>)Parameters["TrainingSamplesStart"]; }
55    }
56    public ValueParameter<IntValue> TrainingSamplesEndParameter {
57      get { return (ValueParameter<IntValue>)Parameters["TrainingSamplesEnd"]; }
58    }
59    public OptionalValueParameter<IntValue> ValidationSamplesStartParameter {
60      get { return (OptionalValueParameter<IntValue>)Parameters["ValidationSamplesStart"]; }
61    }
62    public OptionalValueParameter<IntValue> ValidationSamplesEndParameter {
63      get { return (OptionalValueParameter<IntValue>)Parameters["ValidationSamplesEnd"]; }
64    }
65    public ValueParameter<IntValue> TestSamplesStartParameter {
66      get { return (ValueParameter<IntValue>)Parameters["TestSamplesStart"]; }
67    }
68    public ValueParameter<IntValue> TestSamplesEndParameter {
69      get { return (ValueParameter<IntValue>)Parameters["TestSamplesEnd"]; }
70    }
71    #endregion
72    #region properties
73    public Dataset Dataset {
74      get { return DatasetParameter.Value; }
75      set { DatasetParameter.Value = value; }
76    }
77    public StringValue TargetVariable {
78      get { return TargetVariableParameter.Value; }
79      set { TargetVariableParameter.Value = value; }
80    }
81    public ItemList<StringValue> InputVariables {
82      get { return InputVariablesParameter.Value; }
83      set { InputVariablesParameter.Value = value; }
84    }
85    public IntValue TrainingSamplesStart {
86      get { return TrainingSamplesStartParameter.Value; }
87      set { TrainingSamplesStartParameter.Value = value; }
88    }
89    public IntValue TrainingSamplesEnd {
90      get { return TrainingSamplesEndParameter.Value; }
91      set { TrainingSamplesEndParameter.Value = value; }
92    }
93    public IntValue ValidationSamplesStart {
94      get { return ValidationSamplesStartParameter.Value; }
95      set { ValidationSamplesStartParameter.Value = value; }
96    }
97    public IntValue ValidationSamplesEnd {
98      get { return ValidationSamplesEndParameter.Value; }
99      set { ValidationSamplesEndParameter.Value = value; }
100    }
101    public IntValue TestSamplesStart {
102      get { return TestSamplesStartParameter.Value; }
103      set { TestSamplesStartParameter.Value = value; }
104    }
105    public IntValue TestSamplesEnd {
106      get { return TestSamplesEndParameter.Value; }
107      set { TestSamplesEndParameter.Value = value; }
108    }
109    #endregion
110
111    public RegressionProblem()
112      : base() {
113      var dataset = new Dataset();
114      // TODO: wiring for sanity checks of parameter values based on dataset (target & input variables available?, training and test partition correct?...)
115      Parameters.Add(new ValueParameter<Dataset>("Dataset", "The data set containing data to be analyzer.", dataset));
116      Parameters.Add(new ValueParameter<StringValue>("TargetVariable", "The target variable for which a regression model should be created.", new StringValue()));
117      Parameters.Add(new ValueParameter<ItemList<StringValue>>("InputVariables", "The input variables (regressors) that are available for the regression model.", new ItemList<StringValue>()));
118      Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesStart", "The start index of the training partition.", new IntValue()));
119      Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesEnd", "The end index of the training partition.", new IntValue()));
120      Parameters.Add(new OptionalValueParameter<IntValue>("ValidationSamplesStart", "The start index of the validation partition."));
121      Parameters.Add(new OptionalValueParameter<IntValue>("ValidationSamplesEnd", "The end index of the validation partition."));
122      Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", "The start index of the test partition.", new IntValue()));
123      Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", "The end index of the test partition.", new IntValue()));
124    }
125
126    [StorableConstructor]
127    private RegressionProblem(bool deserializing) : base() { }
128
129    public virtual void ImportFromFile(string fileName) {
130      var csvFileParser = new CsvFileParser();
131      csvFileParser.Parse(fileName);
132      Name = "Regression Problem (imported from " + Path.GetFileName(fileName);
133      Dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
134      Dataset.Name = Path.GetFileName(fileName);
135      TargetVariable = new StringValue(Dataset.VariableNames.First());
136      InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s)));
137      TrainingSamplesStart = new IntValue(0);
138      TrainingSamplesEnd = new IntValue(csvFileParser.Rows);
139      TestSamplesStart = new IntValue(0);
140      TestSamplesEnd = new IntValue(csvFileParser.Rows);
141    }
142  }
143}
Note: See TracBrowser for help on using the repository browser.