[5540] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[5559] | 23 | using System.IO;
|
---|
[5540] | 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[5586] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
[5540] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
| 32 | [StorableClass]
|
---|
[5559] | 33 | public sealed class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData {
|
---|
[5586] | 34 | private const string TargetVariableParameterName = "TargetVariable";
|
---|
[5540] | 35 |
|
---|
[5554] | 36 | #region default data
|
---|
| 37 | private static double[,] kozaF1 = new double[,] {
|
---|
| 38 | {2.017885919, -1.449165046},
|
---|
| 39 | {1.30060506, -1.344523885},
|
---|
| 40 | {1.147134798, -1.317989331},
|
---|
| 41 | {0.877182504, -1.266142284},
|
---|
| 42 | {0.852562452, -1.261020794},
|
---|
| 43 | {0.431095788, -1.158793317},
|
---|
| 44 | {0.112586002, -1.050908405},
|
---|
| 45 | {0.04594507, -1.021989402},
|
---|
| 46 | {0.042572879, -1.020438113},
|
---|
| 47 | {-0.074027291, -0.959859562},
|
---|
| 48 | {-0.109178553, -0.938094706},
|
---|
| 49 | {-0.259721109, -0.803635355},
|
---|
| 50 | {-0.272991057, -0.387519561},
|
---|
| 51 | {-0.161978191, -0.193611001},
|
---|
| 52 | {-0.102489983, -0.114215349},
|
---|
| 53 | {-0.01469968, -0.014918985},
|
---|
| 54 | {-0.008863365, -0.008942626},
|
---|
| 55 | {0.026751057, 0.026054094},
|
---|
| 56 | {0.166922436, 0.14309643},
|
---|
| 57 | {0.176953808, 0.1504144},
|
---|
| 58 | {0.190233418, 0.159916534},
|
---|
| 59 | {0.199800708, 0.166635331},
|
---|
| 60 | {0.261502822, 0.207600348},
|
---|
| 61 | {0.30182879, 0.232370249},
|
---|
| 62 | {0.83763905, 0.468046718}
|
---|
| 63 | };
|
---|
| 64 | private static Dataset defaultDataset;
|
---|
| 65 | private static IEnumerable<string> defaultAllowedInputVariables;
|
---|
| 66 | private static string defaultTargetVariable;
|
---|
| 67 |
|
---|
| 68 | static RegressionProblemData() {
|
---|
| 69 | defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1);
|
---|
[5559] | 70 | defaultDataset.Name = "Fourth-order Polynomial Function Benchmark Dataset";
|
---|
| 71 | defaultDataset.Description = "f(x) = x^4 + x^3 + x^2 + x^1";
|
---|
[5554] | 72 | defaultAllowedInputVariables = new List<string>() { "x" };
|
---|
| 73 | defaultTargetVariable = "y";
|
---|
| 74 | }
|
---|
| 75 | #endregion
|
---|
| 76 |
|
---|
[5586] | 77 | public IValueParameter<StringValue> TargetVariableParameter {
|
---|
| 78 | get { return (IValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
|
---|
[5540] | 79 | }
|
---|
[5586] | 80 | public StringValue TargetVariable {
|
---|
| 81 | get { return TargetVariableParameter.Value; }
|
---|
| 82 | }
|
---|
[5540] | 83 |
|
---|
[5586] | 84 |
|
---|
[5554] | 85 | [StorableConstructor]
|
---|
| 86 | private RegressionProblemData(bool deserializing) : base(deserializing) { }
|
---|
[5559] | 87 | private RegressionProblemData(RegressionProblemData original, Cloner cloner) : base(original, cloner) { }
|
---|
[5554] | 88 | public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblemData(this, cloner); }
|
---|
| 89 |
|
---|
[5540] | 90 | public RegressionProblemData()
|
---|
[5554] | 91 | : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) {
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public RegressionProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
|
---|
| 95 | : base(dataset, allowedInputVariables) {
|
---|
[5586] | 96 | Parameters.Add(new ConstrainedValueParameter<StringValue>("TargetVariable", new ItemSet<StringValue>(InputVariables), InputVariables.Where(x => x.Value == targetVariable).First()));
|
---|
[5540] | 97 | }
|
---|
| 98 |
|
---|
[5559] | 99 | public static RegressionProblemData ImportFromFile(string fileName) {
|
---|
| 100 | TableFileParser csvFileParser = new TableFileParser();
|
---|
| 101 | csvFileParser.Parse(fileName);
|
---|
[5542] | 102 |
|
---|
[5559] | 103 | Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
|
---|
| 104 | dataset.Name = Path.GetFileName(fileName);
|
---|
[5554] | 105 |
|
---|
[5559] | 106 | RegressionProblemData problemData = new RegressionProblemData(dataset, dataset.VariableNames.Skip(1), dataset.VariableNames.First());
|
---|
| 107 | problemData.Name = "Data imported from " + Path.GetFileName(fileName);
|
---|
| 108 | return problemData;
|
---|
[5542] | 109 | }
|
---|
[5540] | 110 | }
|
---|
| 111 | }
|
---|