Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15502 for trunk/sources


Ignore:
Timestamp:
12/07/17 17:58:58 (7 years ago)
Author:
mkommend
Message:

#2862: Added switch to enable/disable linear scaling in NLR.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r15499 r15502  
    5151    private const string SeedParameterName = "Seed";
    5252    private const string InitParamsRandomlyParameterName = "InitializeParametersRandomly";
     53    private const string ApplyLinearScalingParameterName = "Apply linear scaling";
    5354
    5455    public IFixedValueParameter<StringValue> ModelStructureParameter {
     
    7374    public IFixedValueParameter<BoolValue> InitParametersRandomlyParameter {
    7475      get { return (IFixedValueParameter<BoolValue>)Parameters[InitParamsRandomlyParameterName]; }
     76    }
     77
     78    public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
     79      get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    7580    }
    7681
     
    103108      get { return InitParametersRandomlyParameter.Value.Value; }
    104109      set { InitParametersRandomlyParameter.Value.Value = value; }
     110    }
     111
     112    public bool ApplyLinearScaling {
     113      get { return ApplyLinearScalingParameter.Value.Value; }
     114      set { ApplyLinearScalingParameter.Value.Value = value; }
    105115    }
    106116
     
    119129      Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true)));
    120130      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)));
    121132
    122133      SetParameterHiddenState();
     
    146157      if (!Parameters.ContainsKey(InitParamsRandomlyParameterName))
    147158        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
    148162
    149163      SetParameterHiddenState();
     
    174188        if (SetSeedRandomly) Seed = (new System.Random()).Next();
    175189        var rand = new MersenneTwister((uint)Seed);
    176         bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);
     190        bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling, rand);
    177191        trainRMSERow.Values.Add(bestSolution.TrainingRootMeanSquaredError);
    178192        testRMSERow.Values.Add(bestSolution.TestRootMeanSquaredError);
    179193        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);
    181195          trainRMSERow.Values.Add(solution.TrainingRootMeanSquaredError);
    182196          testRMSERow.Values.Add(solution.TestRootMeanSquaredError);
     
    186200        }
    187201      } else {
    188         bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations);
     202        bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, ApplyLinearScaling);
    189203      }
    190204
     
    206220    /// <param name="random">Optional random number generator for random initialization of numeric constants.</param>
    207221    /// <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) {
    209223      var parser = new InfixExpressionParser();
    210224      var tree = parser.Parse(modelStructure);
     
    262276
    263277      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices,
    264         applyLinearScaling: true, maxIterations: maxIterations,
     278        applyLinearScaling: applyLinearScaling, maxIterations: maxIterations,
    265279        updateVariableWeights: false, updateConstantsInTree: true);
    266280
    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());
    270286      solution.Model.Name = "Regression Model";
    271287      solution.Name = "Regression Solution";
Note: See TracChangeset for help on using the changeset viewer.