- Timestamp:
- 04/02/14 13:02:17 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/Transformations
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/Transformations/LinearTransformation.cs
r10694 r10702 21 21 22 22 23 using System; 23 24 using System.Collections.Generic; 24 25 using System.Linq; 26 using System.Text; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; … … 28 30 using HeuristicLab.DataPreprocessing.Transformations; 29 31 using HeuristicLab.Parameters; 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 33 namespace HeuristicLab.DataPreprocessing.Implementations.Transformations { 31 34 [Item("LinearTransformation", "Represents a linear transformation with multiplication and addition.")] 32 35 public class LinearTransformation : Transformation<double> { 36 protected const string MultiplicandParameterName = "Multiplicand"; 37 protected const string SummandParameterName = "Summand"; 33 38 34 39 #region Parameters 35 40 public IValueParameter<DoubleValue> MultiplicandParameter { 36 get { return (IValueParameter<DoubleValue>)Parameters[ "Multiplicand"]; }41 get { return (IValueParameter<DoubleValue>)Parameters[MultiplicandParameterName]; } 37 42 } 38 43 public IValueParameter<DoubleValue> SummandParameter { 39 get { return (IValueParameter<DoubleValue>)Parameters[ "Summand"]; }44 get { return (IValueParameter<DoubleValue>)Parameters[SummandParameterName]; } 40 45 } 41 46 #endregion 42 47 43 public LinearTransformation() 44 : base() { 45 Parameters.Add(new ValueParameter<DoubleValue>("Multiplicand", "Multiplicand for linear transformation", new DoubleValue(1.0))); 46 Parameters.Add(new ValueParameter<DoubleValue>("Summand", "Summand for linear transformation", new DoubleValue(0.0))); 48 #region properties 49 public double Multiplicand { 50 get { return MultiplicandParameter.Value.Value; } 51 } 52 53 public double Summand { 54 get { return SummandParameter.Value.Value; } 55 } 56 #endregion 57 58 [StorableConstructor] 59 protected LinearTransformation(bool deserializing) : base(deserializing) { } 60 protected LinearTransformation(Transformation<double> original, Cloner cloner) 61 : base(original, cloner) { 62 } 63 protected LinearTransformation() { 64 } 65 public LinearTransformation(IEnumerable<string> allowedColumns) 66 : base(allowedColumns) { 67 Parameters.Add(new ValueParameter<DoubleValue>(MultiplicandParameterName, "Multiplicand for linear transformation", new DoubleValue(1.0))); 68 Parameters.Add(new ValueParameter<DoubleValue>(SummandParameterName, "Summand for linear transformation", new DoubleValue(0.0))); 69 } 70 71 public override IDeepCloneable Clone(Cloner cloner) { 72 return new LinearTransformation(this, cloner); 47 73 } 48 74 49 75 public override IEnumerable<double> Apply(IEnumerable<double> data) { 50 return data.Select(e => e * Multiplicand Parameter.Value.Value + SummandParameter.Value.Value).ToList();76 return data.Select(e => e * Multiplicand + Summand); 51 77 } 52 78 53 79 public override IEnumerable<double> InverseApply(IEnumerable<double> data) { 54 throw new System.NotImplementedException();80 return data.Select(e => (e - Summand) / Multiplicand); 55 81 } 56 82 57 public override IDeepCloneable Clone(Cloner cloner) { 58 throw new System.NotImplementedException(); 59 } 83 public override bool Check(IEnumerable<double> data, out string errorMsg) { 84 StringBuilder sb = new StringBuilder(); 85 bool success = true; 86 errorMsg = null; 60 87 61 public override void Check(IEnumerable<double> data) { 62 throw new System.NotImplementedException(); 88 if (Multiplicand == 0.0) { 89 sb.Append(String.Format("Multiplicand is 0, all {0} entries will be set to {1}. Reversal will not be possble", data.Count(), Summand)); 90 errorMsg = sb.ToString(); 91 success = false; 92 } 93 return success; 63 94 } 64 95 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/Transformations/Transformation.cs
r10694 r10702 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Parameters; 25 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 29 using HeuristicLab.Problems.DataAnalysis; … … 30 33 [StorableClass] 31 34 public abstract class Transformation<T> : ParameterizedNamedItem, ITransformation<T> { 32 public string Column { get; private set; } 35 protected const string ColumnParameterName = "Column"; 36 #region parameter properties 37 public IConstrainedValueParameter<StringValue> ColumnParameter { 38 get { return (IConstrainedValueParameter<StringValue>)Parameters[ColumnParameterName]; } 39 } 40 #endregion 41 42 #region properties 43 public string Column { 44 get { return ColumnParameter.Value.Value; } 45 } 46 #endregion 33 47 34 48 [StorableConstructor] 35 49 protected Transformation(bool deserializing) : base(deserializing) { } 36 protected Transformation(Transformation<T> original, Cloner cloner) 37 : base(original, cloner) { 38 Column = original.Column; 39 } 50 protected Transformation(Transformation<T> original, Cloner cloner): base(original, cloner) {} 40 51 protected Transformation() { } 41 protected Transformation(string column) { 42 this.Column = column; 52 protected Transformation(IEnumerable<string> allowedColumns) { 53 var allowed = new ItemSet<StringValue>(allowedColumns.Select(e => new StringValue(e))); 54 Parameters.Add(new ConstrainedValueParameter<StringValue>(ColumnParameterName, "Column used for the Transformation", allowed)); 43 55 } 44 56 … … 47 59 public abstract IEnumerable<T> InverseApply(IEnumerable<T> data); 48 60 49 public abstract void Check(IEnumerable<T> data);61 public abstract bool Check(IEnumerable<T> data, out string errorMsg); 50 62 } 51 63 }
Note: See TracChangeset
for help on using the changeset viewer.