Changeset 16311 for branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
- Timestamp:
- 11/20/18 15:26:57 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /stable/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Algorithms.DataAnalysis/3.4 10321-10322 /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 6917-7005 /branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4 9070-13099 /branches/CloningRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.4 5815-6180 /branches/DataAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Algorithms.DataAnalysis/3.4 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Algorithms.DataAnalysis/3.4 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Algorithms.DataAnalysis/3.4 5060 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 11570-12508 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Algorithms.DataAnalysis/3.4 11130-12721 /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis/3.4 13819-14091 /branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4 8116-8789 /branches/LogResidualEvaluator/HeuristicLab.Algorithms.DataAnalysis/3.4 10202-10483 /branches/NET40/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 5138-5162 /branches/ParallelEngine/HeuristicLab.Algorithms.DataAnalysis/3.4 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Algorithms.DataAnalysis/3.4 7773-7810 /branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Algorithms.DataAnalysis/3.4 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Algorithms.DataAnalysis/3.4 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 5370-5682 /branches/Trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 6829-6865 /branches/VNS/HeuristicLab.Algorithms.DataAnalysis/3.4 5594-5752 /branches/Weighted TSNE/3.4 15451-15531 /branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4 14232-14825 /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 15406-15681
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r16308 r16311 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 51 51 private const string SeedParameterName = "Seed"; 52 52 private const string InitParamsRandomlyParameterName = "InitializeParametersRandomly"; 53 private const string ApplyLinearScalingParameterName = "Apply linear scaling"; 53 54 54 55 public IFixedValueParameter<StringValue> ModelStructureParameter { … … 73 74 public IFixedValueParameter<BoolValue> InitParametersRandomlyParameter { 74 75 get { return (IFixedValueParameter<BoolValue>)Parameters[InitParamsRandomlyParameterName]; } 76 } 77 78 public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter { 79 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 75 80 } 76 81 … … 103 108 get { return InitParametersRandomlyParameter.Value.Value; } 104 109 set { InitParametersRandomlyParameter.Value.Value = value; } 110 } 111 112 public bool ApplyLinearScaling { 113 get { return ApplyLinearScalingParameter.Value.Value; } 114 set { ApplyLinearScalingParameter.Value.Value = value; } 105 115 } 106 116 … … 119 129 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true))); 120 130 Parameters.Add(new FixedValueParameter<BoolValue>(InitParamsRandomlyParameterName, "Switch to determine if the real-valued model parameters should be initialized randomly in each restart.", new BoolValue(false))); 131 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Switch to determine if linear scaling terms should be added to the model", new BoolValue(true))); 121 132 122 133 SetParameterHiddenState(); … … 146 157 if (!Parameters.ContainsKey(InitParamsRandomlyParameterName)) 147 158 Parameters.Add(new FixedValueParameter<BoolValue>(InitParamsRandomlyParameterName, "Switch to determine if the numeric parameters of the model should be initialized randomly.", new BoolValue(false))); 159 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) 160 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Switch to determine if linear scaling terms should be added to the model", new BoolValue(true))); 161 148 162 149 163 SetParameterHiddenState(); … … 172 186 qualityTable.Rows.Add(testRMSERow); 173 187 Results.Add(new Result(qualityTable.Name, qualityTable.Name + " for all restarts", qualityTable)); 174 if (SetSeedRandomly) Seed = (new System.Random()).Next();188 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 175 189 var rand = new MersenneTwister((uint)Seed); 176 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);190 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling, rand); 177 191 trainRMSERow.Values.Add(bestSolution.TrainingRootMeanSquaredError); 178 192 testRMSERow.Values.Add(bestSolution.TestRootMeanSquaredError); 179 193 for (int r = 0; r < Restarts; r++) { 180 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);194 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling, rand); 181 195 trainRMSERow.Values.Add(solution.TrainingRootMeanSquaredError); 182 196 testRMSERow.Values.Add(solution.TestRootMeanSquaredError); … … 186 200 } 187 201 } else { 188 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations );202 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling); 189 203 } 190 204 … … 206 220 /// <param name="random">Optional random number generator for random initialization of numeric constants.</param> 207 221 /// <returns></returns> 208 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations, IRandom rand = null) {222 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations, bool applyLinearScaling, IRandom rand = null) { 209 223 var parser = new InfixExpressionParser(); 210 224 var tree = parser.Parse(modelStructure); … … 262 276 263 277 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 264 applyLinearScaling: false, maxIterations: maxIterations,278 applyLinearScaling: applyLinearScaling, maxIterations: maxIterations, 265 279 updateVariableWeights: false, updateConstantsInTree: true); 266 280 267 var scaledModel = new SymbolicRegressionModel(problemData.TargetVariable, tree, (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter.Clone()); 268 scaledModel.Scale(problemData); 269 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(scaledModel, (IRegressionProblemData)problemData.Clone()); 281 var model = new SymbolicRegressionModel(problemData.TargetVariable, tree, (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter.Clone()); 282 if (applyLinearScaling) 283 model.Scale(problemData); 284 285 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(model, (IRegressionProblemData)problemData.Clone()); 270 286 solution.Model.Name = "Regression Model"; 271 287 solution.Name = "Regression Solution";
Note: See TracChangeset
for help on using the changeset viewer.