[15846] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2018 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 |
|
---|
[15870] | 22 | using System;
|
---|
[15846] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.DataAnalysis {
|
---|
[15870] | 30 | [Item("Data Analysis Transformation Model", "A model that was transformed back to match the original variables after the training was performed on transformed variables.")]
|
---|
[15846] | 31 | [StorableClass]
|
---|
[15870] | 32 | public abstract class DataAnalysisTransformationModel : DataAnalysisModel, IDataAnalysisTransformationModel {
|
---|
[15846] | 33 |
|
---|
| 34 | [Storable]
|
---|
[15870] | 35 | public IDataAnalysisModel OriginalModel { get; protected set; }
|
---|
[15846] | 36 |
|
---|
[15884] | 37 | IEnumerable<IDataAnalysisTransformation> IDataAnalysisTransformationModel.InputTransformations {
|
---|
| 38 | get { return InputTransformations; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[15846] | 41 | [Storable]
|
---|
[15870] | 42 | public ReadOnlyItemList<IDataAnalysisTransformation> InputTransformations { get; protected set; }
|
---|
[15846] | 43 |
|
---|
[15870] | 44 | [Storable]
|
---|
| 45 | public ReadOnlyItemList<IDataAnalysisTransformation> TargetTransformations { get; protected set; }
|
---|
| 46 |
|
---|
| 47 | // Usually, the TargetVariable is usually only implemented for Regression and Classification.
|
---|
| 48 | // However, we implement it in the base class for reducing code duplication and to avoid quasi-identical views.
|
---|
| 49 | [Storable]
|
---|
| 50 | private string targetVariable;
|
---|
| 51 | public string TargetVariable {
|
---|
| 52 | get { return targetVariable; }
|
---|
| 53 | set {
|
---|
| 54 | if (string.IsNullOrEmpty(value) || targetVariable == value) return;
|
---|
| 55 | targetVariable = value;
|
---|
| 56 | OnTargetVariableChanged(this, EventArgs.Empty);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[15846] | 60 | public override IEnumerable<string> VariablesUsedForPrediction {
|
---|
[15884] | 61 | get { return DataAnalysisTransformation.ReduceVariables(OriginalModel.VariablesUsedForPrediction, InputTransformations); }
|
---|
[15846] | 62 | }
|
---|
| 63 |
|
---|
| 64 | #region Constructor, Cloning & Persistence
|
---|
[15870] | 65 | protected DataAnalysisTransformationModel(IDataAnalysisModel originalModel, IEnumerable<IDataAnalysisTransformation> transformations)
|
---|
[15884] | 66 | : base("Transformation Model " + originalModel.Name) {
|
---|
[15846] | 67 | OriginalModel = originalModel;
|
---|
[15884] | 68 | var transitiveInputs = DataAnalysisTransformation.GetTransitiveVariables(originalModel.VariablesUsedForPrediction, transformations, inverse: true);
|
---|
[15870] | 69 | InputTransformations = new ItemList<IDataAnalysisTransformation>(transformations.Where(t => transitiveInputs.Contains(t.OriginalVariable))).AsReadOnly();
|
---|
| 70 | TargetTransformations = new ReadOnlyItemList<IDataAnalysisTransformation>();
|
---|
[15846] | 71 | }
|
---|
| 72 |
|
---|
[15870] | 73 | protected DataAnalysisTransformationModel(DataAnalysisTransformationModel original, Cloner cloner)
|
---|
[15846] | 74 | : base(original, cloner) {
|
---|
| 75 | OriginalModel = cloner.Clone(original.OriginalModel);
|
---|
[15870] | 76 | InputTransformations = cloner.Clone(original.InputTransformations);
|
---|
| 77 | TargetTransformations = cloner.Clone(original.TargetTransformations);
|
---|
| 78 | targetVariable = original.targetVariable;
|
---|
[15846] | 79 | }
|
---|
| 80 |
|
---|
| 81 | [StorableConstructor]
|
---|
[15870] | 82 | protected DataAnalysisTransformationModel(bool deserializing)
|
---|
[15846] | 83 | : base(deserializing) { }
|
---|
| 84 | #endregion
|
---|
| 85 |
|
---|
[15870] | 86 | #region Events
|
---|
| 87 | public event EventHandler TargetVariableChanged;
|
---|
| 88 | private void OnTargetVariableChanged(object sender, EventArgs args) {
|
---|
| 89 | var changed = TargetVariableChanged;
|
---|
| 90 | if (changed != null)
|
---|
| 91 | changed(sender, args);
|
---|
[15847] | 92 | }
|
---|
[15870] | 93 | #endregion
|
---|
[15846] | 94 | }
|
---|
| 95 | } |
---|