1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Problems.DataAnalysis;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.Instances.DataAnalysis {
|
---|
32 | [StorableClass]
|
---|
33 | public class FeatureSelectionRegressionProblemData : RegressionProblemData {
|
---|
34 | private const string SelectedFeaturesParameterName = "SelectedFeatures";
|
---|
35 | private const string WeightsParameterName = "Weights";
|
---|
36 | private const string OptimalRSquaredParameterName = "R² (best solution)";
|
---|
37 |
|
---|
38 | public IValueParameter<StringArray> SelectedFeaturesParameter {
|
---|
39 | get { return (IValueParameter<StringArray>)Parameters[SelectedFeaturesParameterName]; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public IValueParameter<DoubleArray> WeightsParameter {
|
---|
43 | get { return (IValueParameter<DoubleArray>)Parameters[WeightsParameterName]; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public IValueParameter<DoubleValue> OptimalRSquaredParameter {
|
---|
47 | get { return (IValueParameter<DoubleValue>)Parameters[OptimalRSquaredParameterName]; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableConstructor]
|
---|
51 | protected FeatureSelectionRegressionProblemData(bool deserializing)
|
---|
52 | : base(deserializing) {
|
---|
53 | }
|
---|
54 | protected FeatureSelectionRegressionProblemData(FeatureSelectionRegressionProblemData original, Cloner cloner)
|
---|
55 | : base(original, cloner) {
|
---|
56 | }
|
---|
57 |
|
---|
58 | public FeatureSelectionRegressionProblemData(IDataset ds, IEnumerable<string> allowedInputVariables, string targetVariable, string[] selectedFeatures, double[] weights, double optimalRSquared)
|
---|
59 | : base(ds, allowedInputVariables, targetVariable) {
|
---|
60 | if (selectedFeatures.Length != weights.Length) throw new ArgumentException("Length of selected features vector does not match the length of the weights vector");
|
---|
61 | if (optimalRSquared < 0 || optimalRSquared > 1) throw new ArgumentException("Optimal R² is not in range [0..1]");
|
---|
62 | Parameters.Add(new FixedValueParameter<StringArray>(
|
---|
63 | SelectedFeaturesParameterName,
|
---|
64 | "Array of features used to generate the target values.",
|
---|
65 | new StringArray(selectedFeatures).AsReadOnly()));
|
---|
66 | Parameters.Add(new FixedValueParameter<DoubleArray>(
|
---|
67 | WeightsParameterName,
|
---|
68 | "Array of weights used to generate the target values.",
|
---|
69 | (DoubleArray)(new DoubleArray(weights).AsReadOnly())));
|
---|
70 | Parameters.Add(new FixedValueParameter<DoubleValue>(
|
---|
71 | OptimalRSquaredParameterName,
|
---|
72 | "R² of the optimal solution.",
|
---|
73 | (DoubleValue)(new DoubleValue(optimalRSquared).AsReadOnly())));
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
77 | return new FeatureSelectionRegressionProblemData(this, cloner);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|