Changeset 16308 for branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
- Timestamp:
- 11/20/18 13:52:40 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
/stable reverse-merged: 15587-15588 /trunk/sources removed
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/stable/HeuristicLab.Algorithms.DataAnalysis reverse-merged: 15587 /trunk/sources/HeuristicLab.Algorithms.DataAnalysis removed
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo deleted
-
branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r16307 r16308 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 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";54 53 55 54 public IFixedValueParameter<StringValue> ModelStructureParameter { … … 74 73 public IFixedValueParameter<BoolValue> InitParametersRandomlyParameter { 75 74 get { return (IFixedValueParameter<BoolValue>)Parameters[InitParamsRandomlyParameterName]; } 76 }77 78 public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {79 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }80 75 } 81 76 … … 108 103 get { return InitParametersRandomlyParameter.Value.Value; } 109 104 set { InitParametersRandomlyParameter.Value.Value = value; } 110 }111 112 public bool ApplyLinearScaling {113 get { return ApplyLinearScalingParameter.Value.Value; }114 set { ApplyLinearScalingParameter.Value.Value = value; }115 105 } 116 106 … … 129 119 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true))); 130 120 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)));132 121 133 122 SetParameterHiddenState(); … … 157 146 if (!Parameters.ContainsKey(InitParamsRandomlyParameterName)) 158 147 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 162 148 163 149 SetParameterHiddenState(); … … 188 174 if (SetSeedRandomly) Seed = (new System.Random()).Next(); 189 175 var rand = new MersenneTwister((uint)Seed); 190 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling,rand);176 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand); 191 177 trainRMSERow.Values.Add(bestSolution.TrainingRootMeanSquaredError); 192 178 testRMSERow.Values.Add(bestSolution.TestRootMeanSquaredError); 193 179 for (int r = 0; r < Restarts; r++) { 194 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling,rand);180 var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand); 195 181 trainRMSERow.Values.Add(solution.TrainingRootMeanSquaredError); 196 182 testRMSERow.Values.Add(solution.TestRootMeanSquaredError); … … 200 186 } 201 187 } else { 202 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations , ApplyLinearScaling);188 bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations); 203 189 } 204 190 … … 220 206 /// <param name="random">Optional random number generator for random initialization of numeric constants.</param> 221 207 /// <returns></returns> 222 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations, bool applyLinearScaling,IRandom rand = null) {208 public static ISymbolicRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, string modelStructure, int maxIterations, IRandom rand = null) { 223 209 var parser = new InfixExpressionParser(); 224 210 var tree = parser.Parse(modelStructure); … … 276 262 277 263 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, 278 applyLinearScaling: applyLinearScaling, maxIterations: maxIterations,264 applyLinearScaling: false, maxIterations: maxIterations, 279 265 updateVariableWeights: false, updateConstantsInTree: true); 280 266 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()); 267 var scaledModel = new SymbolicRegressionModel(problemData.TargetVariable, tree, (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter.Clone()); 268 scaledModel.Scale(problemData); 269 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(scaledModel, (IRegressionProblemData)problemData.Clone()); 286 270 solution.Model.Name = "Regression Model"; 287 271 solution.Name = "Regression Solution";
Note: See TracChangeset
for help on using the changeset viewer.