Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/SupervisedDataAnalysisProblemData.cs @ 18088

Last change on this file since 18088 was 18088, checked in by mkommend, 3 years ago

#2521: Added storable type attribute to SupervisedDataAnalysisProblemData and license info to SupervisedDataAnalysisProblemData and GSEMO.

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.Problems.DataAnalysis {
31  [StorableType("1B593917-9CC6-49B2-A446-02A0CFB273FE")]
32  public abstract class SupervisedDataAnalysisProblemData : DataAnalysisProblemData {
33    protected const string TargetVariableParameterName = "TargetVariable";
34
35    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
36
37    public string TargetVariable {
38      get { return TargetVariableParameter.Value.Value; }
39      set {
40        if (value == null) throw new ArgumentNullException("targetVariable", "The provided value for the targetVariable is null.");
41        if (value == TargetVariable) return;
42
43        var matchingParameterValue = TargetVariableParameter.ValidValues.FirstOrDefault(v => v.Value == value);
44        if (matchingParameterValue == null) throw new ArgumentException("The provided value is not valid as the targetVariable.", "targetVariable");
45        TargetVariableParameter.Value = matchingParameterValue;
46      }
47    }
48    public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable);
49    public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices);
50    public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices);
51
52
53    public SupervisedDataAnalysisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null, IntervalCollection variableRanges = null) : base(dataset, allowedInputVariables, transformations, variableRanges) { }
54    protected SupervisedDataAnalysisProblemData(SupervisedDataAnalysisProblemData original, Cloner cloner) : base(original, cloner) { }
55
56    [StorableConstructor]
57    protected SupervisedDataAnalysisProblemData(StorableConstructorFlag _) : base(_) { }
58
59  }
60}
Note: See TracBrowser for help on using the repository browser.