- Timestamp:
- 12/20/19 13:21:43 (5 years ago)
- File:
-
- 1 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;
Note: See TracChangeset
for help on using the changeset viewer.