Changeset 17390
- Timestamp:
- 12/20/19 13:21:43 (5 years ago)
- Location:
- branches/3044_variableScaling
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3044_variableScaling/HeuristicLab.Algorithms.DataAnalysis/3.4/KernelRidgeRegression/KernelRidgeRegressionModel.cs
r17180 r17390 27 27 using HEAL.Attic; 28 28 using HeuristicLab.Problems.DataAnalysis; 29 using HeuristicLab.Data; 29 30 30 31 namespace HeuristicLab.Algorithms.DataAnalysis { … … 155 156 this.kernel = (ICovarianceFunction)kernel.Clone(); 156 157 this.lambda = lambda; 157 if (scaleInputs) scaling = CreateScaling(dataset, rows, this.allowedInputVariables); 158 if (scaleInputs) { 159 var trans = new ShiftToRangeTransformation(allowedInputVariables); 160 trans.Range.Start = 0; 161 trans.Range.End = 1; 162 scaling = Transformation.CreateTransformations(trans, dataset, rows, this.allowedInputVariables); 163 } 164 158 165 trainX = ExtractData(dataset, rows, this.allowedInputVariables, scaling); 159 166 var y = dataset.GetDoubleValues(targetVariable, rows).ToArray(); … … 201 208 } 202 209 203 private static ITransformation<double>[] CreateScaling(IDataset dataset, int[] rows, IReadOnlyCollection<string> allowedInputVariables) {204 var trans = new ITransformation<double>[allowedInputVariables.Count];205 int i = 0;206 foreach (var variable in allowedInputVariables) {207 var lin = new LinearTransformation(allowedInputVariables);208 var max = dataset.GetDoubleValues(variable, rows).Max();209 var min = dataset.GetDoubleValues(variable, rows).Min();210 lin.Multiplier = 1.0 / (max - min);211 lin.Addend = -min / (max - min);212 trans[i] = lin;213 i++;214 }215 return trans;216 }217 218 210 private static double[,] ExtractData(IDataset dataset, IEnumerable<int> rows, IReadOnlyCollection<string> allowedInputVariables, ITransformation<double>[] scaling = null) { 219 211 double[][] variables; -
branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs
r17389 r17390 61 61 protected Transformation(IEnumerable<string> allowedColumns) { 62 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 ));63 Parameters.Add(new ConstrainedValueParameter<StringValue>(ColumnParameterName, "Column used for the Transformation", allowed, allowed.First())); 64 64 } 65 66 67 //TODO: Fill XML comments 68 /// <summary> 69 /// Creates transformation for the provided input variables. 70 /// </summary> 71 /// <param name="transformation"></param> 72 /// <param name="dataset"></param> 73 /// <param name="rows"></param> 74 /// <param name="allowedInputVariables"></param> 75 /// <returns></returns> 76 public static ITransformation<double>[] CreateTransformations(ITransformation<double> transformation, IDataset dataset, int[] rows, IReadOnlyCollection<string> allowedInputVariables) { 77 var trans = new ITransformation<double>[allowedInputVariables.Count]; 78 int i = 0; 79 foreach (var variable in allowedInputVariables) { 80 var trans_clone = (ITransformation<double>)transformation.Clone(); 81 trans_clone.Column = variable; 82 trans_clone.ConfigureParameters(dataset.GetDoubleValues(variable, rows)); 83 trans[i] = trans_clone; 84 i++; 85 } 86 return trans; 87 } 88 65 89 } 66 90 … … 85 109 86 110 public abstract bool Check(IEnumerable<T> data, out string errorMsg); 111 112 87 113 } 88 114 } -
branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/ITransformation.cs
r17180 r17390 28 28 public interface ITransformation : IParameterizedItem { 29 29 string ShortName { get; } 30 string Column { get; }30 string Column { get; set; } 31 31 } 32 32
Note: See TracChangeset
for help on using the changeset viewer.