Changeset 15516
- Timestamp:
- 12/12/17 16:17:19 (7 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15499,15502,15505
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 15499,15502,15505
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r15131 r15516 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(); … … 174 188 if (SetSeedRandomly) Seed = (new System.Random()).Next(); 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.