Index: /branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj
===================================================================
--- /branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj (revision 15847)
@@ -347,7 +347,4 @@
ScatterPlotSingleView.cs
-
-
- TransformationView.cs
Index: /branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs (revision 15847)
@@ -83,4 +83,5 @@
private IDataAnalysisProblemData CreateRegressionData(RegressionProblemData oldProblemData) {
+ // TODO: transformations (additional inputs, target changed)
var targetVariable = oldProblemData.TargetVariable;
if (!context.Data.VariableNames.Contains(targetVariable))
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj (revision 15847)
@@ -184,5 +184,5 @@
False
- ..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll
+ ..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll
False
@@ -586,7 +586,4 @@
AbstractFeatureCorrelationView.cs
-
- RegressionSolutionView.cs
-
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs (revision 15847)
@@ -60,7 +60,7 @@
private void transformButton_Click(object sender, System.EventArgs e) {
- var targetVariable = TransformedRegressionModel.GetOriginalTragetVariable(Content.Model.TargetVariable, Content.ProblemData.Transformations);
var transformedModel = new TransformedRegressionModel(Content.Model, Content.ProblemData.Transformations);
- var transformedSolution = new TransformedRegressionSolution(transformedModel, new RegressionProblemData(Content.ProblemData) { TargetVariable = targetVariable });
+ var originalProblemData = (IRegressionProblemData)Content.ProblemData.InverseTransform();
+ var transformedSolution = new TransformedRegressionSolution(transformedModel, originalProblemData);
MainFormManager.MainForm.ShowContent(transformedSolution);
}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs (revision 15847)
@@ -241,4 +241,50 @@
}
}
+
+ public virtual IDataAnalysisProblemData InverseTransform() {
+ var newDataset = InverseTransform(Dataset, Transformations);
+
+ // TODO: Cannot create concrete instance here (maybe derived Create-method?)
+ var cloner = new Cloner();
+ cloner.RegisterClonedObject(Dataset, newDataset);
+ cloner.RegisterClonedObject(TransformationsParameter.Value, new ItemList().AsReadOnly());
+
+ return cloner.Clone(this);
+ }
+
+ public static IDataset Transform(IDataset dataset, IEnumerable transformations) {
+ var modifiableDataset = ((Dataset)dataset).ToModifiable();
+
+ foreach (var transformation in transformations) {
+ var trans = (ITransformation)transformation.Transformation;
+
+ var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable);
+ if (!trans.Check(originalData, out string errorMessage))
+ throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}");
+
+ var transformedData = trans.Apply(originalData).ToList();
+ if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable))
+ modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData);
+ else
+ modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData);
+ }
+
+ return modifiableDataset;
+ }
+
+ public static IDataset InverseTransform(IDataset dataset, IEnumerable transformations) {
+ var modifiableDataset = ((Dataset)dataset).ToModifiable();
+
+ foreach (var transformation in transformations.Reverse()) {
+ var trans = (ITransformation)transformation.Transformation;
+
+ var transformedData = modifiableDataset.GetDoubleValues(transformation.TransformedVariable);
+
+ var originalData = trans.InverseApply(transformedData).ToList();
+ modifiableDataset.ReplaceVariable(transformation.OriginalVariable, originalData);
+ }
+
+ return modifiableDataset;
+ }
}
}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs (revision 15847)
@@ -180,4 +180,20 @@
base.AdjustProblemDataProperties(problemData);
}
+
+ public override IDataAnalysisProblemData InverseTransform() {
+ var transformedProblemData = (IRegressionProblemData)base.InverseTransform();
+ var targetVariable = GetOriginalTragetVariable(TargetVariable, Transformations);
+ transformedProblemData.TargetVariable = targetVariable;
+ return transformedProblemData;
+ }
+
+ public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable transformations) {
+ var originalTarget = transformedTarget;
+ foreach (var transformation in transformations.Reverse()) {
+ if (transformation.TransformedVariable == originalTarget)
+ originalTarget = transformation.OriginalVariable;
+ }
+ return originalTarget;
+ }
}
}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/TransformedRegressionModel.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/TransformedRegressionModel.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/TransformedRegressionModel.cs (revision 15847)
@@ -20,5 +20,4 @@
#endregion
-using System;
using System.Collections.Generic;
using System.Linq;
@@ -44,5 +43,6 @@
#region Constructor, Cloning & Persistence
public TransformedRegressionModel(IRegressionModel originalModel, IEnumerable transformations)
- : base(GetOriginalTragetVariable(originalModel.TargetVariable, transformations)) {
+ : base(RegressionProblemData.GetOriginalTragetVariable(originalModel.TargetVariable, transformations)) {
+ Name = "Transformed " + originalModel.Name;
OriginalModel = originalModel;
Transformations = new ItemList(transformations);
@@ -64,4 +64,5 @@
#endregion
+ // dataset in original data range
public override IEnumerable GetEstimatedValues(IDataset dataset, IEnumerable rows) {
var transformedDataset = TransformInputs(dataset, Transformations);
@@ -69,59 +70,31 @@
var estimates = OriginalModel.GetEstimatedValues(transformedDataset, rows);
- return TransformEstimates(estimates, Transformations, OriginalModel.TargetVariable);
+ return InverseTransformEstimates(estimates, Transformations, OriginalModel.TargetVariable);
}
+ // problemData in original data range
public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
- return new TransformedRegressionSolution(this, new RegressionProblemData(problemData) { TargetVariable = GetOriginalTragetVariable(TargetVariable, Transformations) });
+ return new TransformedRegressionSolution(this, new RegressionProblemData(problemData));
}
private static IDataset TransformInputs(IDataset dataset, IEnumerable transformations) {
- return dataset;
+ return DataAnalysisProblemData.Transform(dataset, transformations);
+ }
- var modifiableDataset = ((Dataset)dataset).ToModifiable();
+ private static IEnumerable InverseTransformEstimates(IEnumerable data, IEnumerable transformations, string targetVariable) {
+ var estimates = data.ToList();
foreach (var transformation in transformations.Reverse()) {
- var trans = (ITransformation)transformation.Transformation;
+ if (transformation.TransformedVariable == targetVariable) {
+ var trans = (ITransformation)transformation.Transformation;
- // no transformations on target (but what if target is an input?)
+ estimates = trans.InverseApply(estimates).ToList();
- var originalData = modifiableDataset.GetDoubleValues(transformation.OriginalVariable);
- if (!trans.Check(originalData, out string errorMessage))
- throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}");
- var transformedData = trans.Apply(originalData).ToList();
-
- if (modifiableDataset.VariableNames.Contains(transformation.TransformedVariable))
- modifiableDataset.ReplaceVariable(transformation.TransformedVariable, transformedData);
- else
- modifiableDataset.AddVariable(transformation.TransformedVariable, transformedData);
+ // setup next iteration
+ targetVariable = transformation.OriginalVariable;
+ }
}
- return modifiableDataset;
- }
-
- private static IEnumerable TransformEstimates(IEnumerable data, IEnumerable transformations, string targetVariable) {
- var targetTransformations = transformations.Where(x => x.TransformedVariable == targetVariable);
-
- var transformedData = data.ToList();
-
- foreach (var transformation in targetTransformations.Reverse()) {
- var trans = (ITransformation)transformation.Transformation;
-
- if (!trans.Check(transformedData, out string errorMessage))
- throw new InvalidOperationException($"Cannot estimate Values, Transformation is invalid: {errorMessage}");
-
- transformedData = trans.InverseApply(transformedData).ToList();
- }
-
- return transformedData;
- }
-
- public static string GetOriginalTragetVariable(string transformedTarget, IEnumerable transformations) {
- var target = transformedTarget;
- foreach (var transformation in transformations.Reverse()) {
- if (transformation.TransformedVariable == target)
- target = transformation.OriginalVariable;
- }
- return target;
+ return estimates;
}
}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs (revision 15847)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs (revision 15847)
@@ -0,0 +1,91 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ [Item("Exponential", "Exponential transformation x' = Base ^ x")]
+ [StorableClass]
+ public class ExponentialTransformation : Transformation {
+ #region Parameters
+ private FixedValueParameter BaseParameter {
+ get { return (FixedValueParameter)Parameters["Base"]; }
+ }
+ #endregion
+
+ #region Properties
+ public double Base {
+ get { return BaseParameter.Value.Value; }
+ set { BaseParameter.Value.Value = value; }
+ }
+ #endregion
+
+ #region Constructor, Cloning & Persistence
+ public ExponentialTransformation()
+ : base() {
+ Parameters.Add(new FixedValueParameter("Base", "Base the logarithm", new DoubleValue(Math.E)));
+ }
+
+ protected ExponentialTransformation(ExponentialTransformation original, Cloner cloner)
+ : base(original, cloner) {
+ }
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new ExponentialTransformation(this, cloner);
+ }
+
+ [StorableConstructor]
+ protected ExponentialTransformation(bool deserializing)
+ : base(deserializing) {
+ }
+ #endregion
+
+ public override bool Check(IEnumerable data, out string errorMessage) {
+ if (data.Any(x => x <= 0)) {
+ errorMessage = "Log is not available for zero or negative values";
+ return false;
+ }
+ return base.Check(data, out errorMessage);
+ }
+
+ public override IEnumerable Apply(IEnumerable data) {
+ return Apply(data, Base);
+ }
+
+ public override IEnumerable InverseApply(IEnumerable data) {
+ return InverseApply(data, Base);
+ }
+
+ public static IEnumerable Apply(IEnumerable data, double @base = Math.E) {
+ return data.Select(x => Math.Pow(@base, x));
+ }
+
+ public static IEnumerable InverseApply(IEnumerable data, double @base = Math.E) {
+ return LogarithmTransformation.Apply(data, @base);
+ }
+ }
+}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs (revision 15847)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs (revision 15847)
@@ -0,0 +1,94 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ [Item("Linear", "Linear transformation x' = slope * x + intercept")]
+ [StorableClass]
+ public class LinearTransformation : Transformation {
+
+ #region Parameters
+ private FixedValueParameter SlopeParameter {
+ get { return (FixedValueParameter)Parameters["Slope"]; }
+ }
+
+ private FixedValueParameter InterceptParameter {
+ get { return (FixedValueParameter)Parameters["Intercept"]; }
+ }
+ #endregion
+
+ #region Properties
+ public double Slope {
+ get { return SlopeParameter.Value.Value; }
+ set { SlopeParameter.Value.Value = value; }
+ }
+
+ public double Intercept {
+ get { return InterceptParameter.Value.Value; }
+ set { InterceptParameter.Value.Value = value; }
+ }
+ #endregion
+
+ #region Constructor, Cloning & Persistence
+ public LinearTransformation()
+ : base() {
+ Parameters.Add(new FixedValueParameter("Slope", "Slope (multiplicative factor)", new DoubleValue(1.0)));
+ Parameters.Add(new FixedValueParameter("Intercept", "Intercept (additive factor)", new DoubleValue(0.0)));
+ }
+
+ protected LinearTransformation(LinearTransformation original, Cloner cloner)
+ : base(original, cloner) {
+ }
+ public override IDeepCloneable Clone(Cloner cloner) {
+ return new LinearTransformation(this, cloner);
+ }
+
+ [StorableConstructor]
+ protected LinearTransformation(bool deserializing)
+ : base(deserializing) {
+ }
+ #endregion
+
+ public override IEnumerable Apply(IEnumerable data) {
+ return Apply(data, Slope, Intercept);
+ }
+
+ public override IEnumerable InverseApply(IEnumerable data) {
+ return InverseApply(data, Slope, Intercept);
+ }
+
+
+ public static IEnumerable Apply(IEnumerable data, double slope = 1.0, double intercept = 0.0) {
+ return data.Select(x => slope * x + intercept);
+ }
+
+ public static IEnumerable InverseApply(IEnumerable data, double slope = 1.0, double intercept = 0.0) {
+ return data.Select(x => (x - intercept) / slope);
+ }
+ }
+}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs (revision 15847)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs (revision 15847)
@@ -0,0 +1,58 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.Collections.Generic;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ [Item("Transformation", "Represents the base class for transformations.")]
+ [StorableClass]
+ public abstract class Transformation : ParameterizedNamedItem, ITransformation {
+ #region Constructor, Cloning & Persistence
+ protected Transformation()
+ : base() {
+ }
+
+ protected Transformation(Transformation original, Cloner cloner)
+ : base(original, cloner) {
+ }
+
+ [StorableConstructor]
+ protected Transformation(bool deserializing)
+ : base(deserializing) {
+ }
+ #endregion
+
+ public virtual bool Check(IEnumerable data, out string errorMessage) {
+ errorMessage = string.Empty;
+ return true;
+ }
+
+ public virtual void Configure(IEnumerable data) {
+ }
+
+ public abstract IEnumerable Apply(IEnumerable data);
+
+ public abstract IEnumerable InverseApply(IEnumerable data);
+ }
+}
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs (revision 15847)
@@ -44,4 +44,5 @@
IEnumerable Transformations { get; }
+ IDataAnalysisProblemData InverseTransform();
bool IsTrainingSample(int index);
Index: /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs
===================================================================
--- /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs (revision 15846)
+++ /branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisTransformation.cs (revision 15847)
@@ -29,5 +29,4 @@
ITransformation Transformation { get; set; }
-
}
}