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