Changeset 15502 for trunk/sources
- Timestamp:
- 12/07/17 17:58:58 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r15499 r15502 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: true, 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.