Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs @ 17389

Last change on this file since 17389 was 17389, checked in by mkommend, 4 years ago

#3044: Allowed modification of column within transformations.

File size: 3.6 KB
RevLine 
[10664]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10664]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
[17389]22using System;
[10694]23using System.Collections.Generic;
[10702]24using System.Linq;
[17389]25using HEAL.Attic;
[10669]26using HeuristicLab.Common;
27using HeuristicLab.Core;
[10702]28using HeuristicLab.Data;
29using HeuristicLab.Parameters;
[10664]30
[11068]31namespace HeuristicLab.Problems.DataAnalysis {
[10940]32
[10669]33  [Item("Transformation", "Represents the base class for a transformation.")]
[16565]34  [StorableType("46B380CC-6CDE-40FC-9BB4-E3FF82BA35EA")]
[10940]35  public abstract class Transformation : ParameterizedNamedItem, ITransformation {
[10702]36    protected const string ColumnParameterName = "Column";
37    #region parameter properties
38    public IConstrainedValueParameter<StringValue> ColumnParameter {
39      get { return (IConstrainedValueParameter<StringValue>)Parameters[ColumnParameterName]; }
40    }
41    #endregion
[10664]42
[10702]43    #region properties
[10932]44    public abstract string ShortName { get; }
45
[10702]46    public string Column {
47      get { return ColumnParameter.Value.Value; }
[17389]48      set {
49        if (value == null) throw new ArgumentNullException("column", "The provided value for the column is null.");
50        if (value == Column) return;
51
52        var matchingParameterValue = ColumnParameter.ValidValues.FirstOrDefault(v => v.Value == value);
53        ColumnParameter.Value = matchingParameterValue ?? throw new ArgumentException("The provided value is not valid as the column.", "column");
54      }
[10702]55    }
56    #endregion
57
[10694]58    [StorableConstructor]
[16565]59    protected Transformation(StorableConstructorFlag _) : base(_) { }
[10940]60    protected Transformation(Transformation original, Cloner cloner) : base(original, cloner) { }
[10702]61    protected Transformation(IEnumerable<string> allowedColumns) {
62      var allowed = new ItemSet<StringValue>(allowedColumns.Select(e => new StringValue(e)));
63      Parameters.Add(new ConstrainedValueParameter<StringValue>(ColumnParameterName, "Column used for the Transformation", allowed));
[10664]64    }
[10940]65  }
[10664]66
[10940]67  [Item("Transformation", "Represents the base class for a transformation.")]
[16565]68  [StorableType("F244DB89-72EA-4B41-89FA-C2E14F30AD29")]
[10940]69  public abstract class Transformation<T> : Transformation, ITransformation<T> {
70
71    [StorableConstructor]
[16565]72    protected Transformation(StorableConstructorFlag _) : base(_) { }
[10940]73    protected Transformation(Transformation<T> original, Cloner cloner) : base(original, cloner) { }
[11068]74    protected Transformation(IEnumerable<string> allowedColumns) : base(allowedColumns) { }
[10940]75
[14843]76    public virtual void ConfigureParameters(IEnumerable<T> data) {
77      // override in transformations with parameters
78    }
79
[10694]80    public abstract IEnumerable<T> Apply(IEnumerable<T> data);
[14843]81    public IEnumerable<T> ConfigureAndApply(IEnumerable<T> data) {
82      ConfigureParameters(data);
83      return Apply(data);
84    }
[10669]85
[10702]86    public abstract bool Check(IEnumerable<T> data, out string errorMsg);
[10664]87  }
88}
Note: See TracBrowser for help on using the repository browser.