Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PausableBasicAlgorithm/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/FeatureSelection/FeatureSelectionRegressionProblemData.cs @ 15428

Last change on this file since 15428 was 12509, checked in by mkommend, 10 years ago

#2276: Reintegrated branch for dataset refactoring.

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