- Timestamp:
- 03/27/18 15:46:12 (7 years ago)
- Location:
- branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformation.cs
r15858 r15865 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Runtime.CompilerServices;26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 34 31 [StorableClass] 35 32 public class DataAnalysisTransformation : ParameterizedNamedItem, IDataAnalysisTransformation { 36 #region Parameter s37 p ublic IConstrainedValueParameter<StringValue> OriginalVariableParameter {38 get { return (I ConstrainedValueParameter<StringValue>)Parameters["Original Variable"]; }33 #region Parameter Properties 34 private IFixedValueParameter<StringValue> OriginalVariableParameter { 35 get { return (IFixedValueParameter<StringValue>)Parameters["Original Variable"]; } 39 36 } 40 37 41 p ublic IConstrainedValueParameter<StringValue> TransformedVariableParameter {42 get { return (I ConstrainedValueParameter<StringValue>)Parameters["Transformed Variable"]; }38 private IFixedValueParameter<StringValue> TransformedVariableParameter { 39 get { return (IFixedValueParameter<StringValue>)Parameters["Transformed Variable"]; } 43 40 } 44 41 45 p ublicIValueParameter<ITransformation> TransformationParameter {42 private IValueParameter<ITransformation> TransformationParameter { 46 43 get { return (IValueParameter<ITransformation>)Parameters["Transformation"]; } 47 44 } … … 51 48 public string OriginalVariable { 52 49 get { return OriginalVariableParameter.Value.Value; } 53 set { SetConstrainedValue(OriginalVariableParameter, value); }50 set { OriginalVariableParameter.Value.Value = value; } 54 51 } 55 52 56 53 public string TransformedVariable { 57 54 get { return TransformedVariableParameter.Value.Value; } 58 set { SetConstrainedValue(TransformedVariableParameter, value); }55 set { TransformedVariableParameter.Value.Value = value; } 59 56 } 60 57 … … 63 60 set { TransformationParameter.Value = value; } 64 61 } 65 66 private static void SetConstrainedValue(IConstrainedValueParameter<StringValue> parameter, string value, [CallerMemberName] string caller = null) {67 if (value == null) throw new ArgumentNullException(caller);68 if (value == parameter.Value.Value) return;69 70 var matchingValue = parameter.ValidValues.SingleOrDefault(v => v.Value == value);71 if (matchingValue == null) throw new ArgumentException("The provided value is not valid.", caller);72 parameter.Value = matchingValue;73 }74 62 #endregion 75 63 76 64 #region Constructor, Cloning & Persistence 77 public DataAnalysisTransformation(IEnumerable<StringValue> variableNames) 65 public DataAnalysisTransformation() 66 : this("", "", new IdentityTransformation()) { 67 } 68 public DataAnalysisTransformation(string originalVariable, string transformedVariable, ITransformation transformation) 78 69 : base() { 79 var originalVariables = new ItemSet<StringValue>(variableNames.Select(x => x.AsReadOnly())); 80 var transformedVariables = new ItemSet<StringValue>(variableNames.Select(x => x.AsReadOnly())); 81 Parameters.Add(new ConstrainedValueParameter<StringValue>("Original Variable", new ItemSet<StringValue>(originalVariables), originalVariables.FirstOrDefault())); 82 Parameters.Add(new ConstrainedValueParameter<StringValue>("Transformed Variable", new ItemSet<StringValue>(transformedVariables), transformedVariables.FirstOrDefault())); 83 84 //var transformations = new ItemSet<ITransformation>(ApplicationManager.Manager.GetInstances<ITransformation>()); 85 Parameters.Add(new ValueParameter<ITransformation>("Transformation", new IdentityTransformation())); 70 Parameters.Add(new FixedValueParameter<StringValue>("Original Variable", new StringValue(originalVariable))); 71 Parameters.Add(new FixedValueParameter<StringValue>("Transformed Variable", new StringValue(transformedVariable))); 72 Parameters.Add(new ValueParameter<ITransformation>("Transformation", transformation)); 86 73 87 74 RegisterEventHandlers(); … … 109 96 #region Event-Handling 110 97 private void RegisterEventHandlers() { 111 OriginalVariableParameter.Value Changed += OriginalVariableParameter_ValueChanged;112 TransformedVariableParameter.Value Changed += TransformedVariableParameter_ValueChanged;98 OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged; 99 TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged; 113 100 TransformationParameter.ValueChanged += TransformationParameter_ValueChanged; 114 101 } 115 102 116 private void OriginalVariableParameter_ValueChanged(object sender, EventArgs e) {117 OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged;118 OnToStringChanged();119 }120 103 private void OriginalVariableParameterValue_ValueChanged(object sender, EventArgs e) { 121 OnToStringChanged();122 }123 124 private void TransformedVariableParameter_ValueChanged(object sender, EventArgs e) {125 TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged;126 104 OnToStringChanged(); 127 105 } … … 129 107 OnToStringChanged(); 130 108 } 131 132 109 private void TransformationParameter_ValueChanged(object sender, EventArgs e) { 133 110 OnToStringChanged(); 134 111 } 135 112 #endregion 136 137 113 138 114 public override string ToString() { -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs
r15847 r15865 49 49 public ExponentialTransformation() 50 50 : base() { 51 Parameters.Add(new FixedValueParameter<DoubleValue>("Base", " Base the logarithm", new DoubleValue(Math.E)));51 Parameters.Add(new FixedValueParameter<DoubleValue>("Base", "", new DoubleValue(Math.E))); 52 52 } 53 53 … … 65 65 #endregion 66 66 67 public override bool Check(IEnumerable<double> data, out string errorMessage) {68 if (data.Any(x => x <= 0)) {69 errorMessage = "Log is not available for zero or negative values";70 return false;71 }72 return base.Check(data, out errorMessage);73 }74 75 67 public override IEnumerable<double> Apply(IEnumerable<double> data) { 76 68 return Apply(data, Base); … … 80 72 return InverseApply(data, Base); 81 73 } 74 82 75 83 76 public static IEnumerable<double> Apply(IEnumerable<double> data, double @base = Math.E) { -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
r15847 r15865 46 46 public double Slope { 47 47 get { return SlopeParameter.Value.Value; } 48 set { SlopeParameter.Value.Value = value; } 48 set { SlopeParameter.Value.Value = value; } //TODO: check for != 0? 49 49 } 50 50 -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmTransformation.cs
r15846 r15865 81 81 } 82 82 83 83 84 public static IEnumerable<double> Apply(IEnumerable<double> data, double @base = Math.E) { 84 85 return data.Select(x => Math.Log(x, @base)); -
branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ZNormalizationTransformation.cs
r15846 r15865 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis { 31 [Item("Z-Score Normalization", "Z-Score normalization transformation to standardize (target_mu = 0, target_sigma = 1) the values")]31 [Item("Z-Score Normalization", "Z-Score normalization transformation to standardize the values to a Target Mean and Target Standard Deviation.")] 32 32 [StorableClass] 33 33 public class ZNormalizationTransformation : Transformation<double> { … … 58 58 public double OriginalMean { 59 59 get { return OriginalMeanParameter.Value.Value; } 60 set { OriginalMeanParameter.Value.Value = value; }60 private set { OriginalMeanParameter.Value.Value = value; } 61 61 } 62 62 public double OriginalStandardDeviation { 63 63 get { return OriginalStandardDeviationParameter.Value.Value; } 64 set { OriginalStandardDeviationParameter.Value.Value = value; }64 private set { OriginalStandardDeviationParameter.Value.Value = value; } 65 65 } 66 66 #endregion … … 103 103 104 104 public override IEnumerable<double> Apply(IEnumerable<double> data) { 105 if (double.IsNaN(OriginalMean) || double.IsNaN(OriginalStandardDeviation)) 105 if (double.IsNaN(OriginalMean) || double.IsNaN(OriginalStandardDeviation)) //TODO isConfigured field? 106 106 Configure(data); 107 107 … … 112 112 return InverseApply(data, TargetMean, TargetStandardDeviation, OriginalMean, OriginalStandardDeviation); 113 113 } 114 114 115 115 116 public static IEnumerable<double> Apply(IEnumerable<double> data, double targetMean, double targetStandardDeviation, double originalMean = double.NaN, double originalStandardDeviation = double.NaN) {
Note: See TracChangeset
for help on using the changeset viewer.