Changeset 14719


Ignore:
Timestamp:
03/06/17 17:10:14 (3 years ago)
Author:
gkronber
Message:

#2650: forgot to update another reference (see r14717)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r14542 r14719  
    138138      // BackwardsCompatibility3.3
    139139      #region Backwards compatible code, remove with 3.4
    140       if (!Parameters.ContainsKey(RestartsParameterName))
     140      if(!Parameters.ContainsKey(RestartsParameterName))
    141141        Parameters.Add(new FixedValueParameter<IntValue>(RestartsParameterName, "The number of independent random restarts", new IntValue(1)));
    142       if (!Parameters.ContainsKey(SeedParameterName))
     142      if(!Parameters.ContainsKey(SeedParameterName))
    143143        Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The PRNG seed value.", new IntValue()));
    144       if (!Parameters.ContainsKey(SetSeedRandomlyParameterName))
     144      if(!Parameters.ContainsKey(SetSeedRandomlyParameterName))
    145145        Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "Switch to determine if the random number seed should be initialized randomly.", new BoolValue(true)));
    146       if (!Parameters.ContainsKey(InitParamsRandomlyParameterName))
     146      if(!Parameters.ContainsKey(InitParamsRandomlyParameterName))
    147147        Parameters.Add(new FixedValueParameter<BoolValue>(InitParamsRandomlyParameterName, "Switch to determine if the numeric parameters of the model should be initialized randomly.", new BoolValue(false)));
    148148
     
    161161    protected override void Run(CancellationToken cancellationToken) {
    162162      IRegressionSolution bestSolution = null;
    163       if (InitializeParametersRandomly) {
     163      if(InitializeParametersRandomly) {
    164164        var qualityTable = new DataTable("RMSE table");
    165165        qualityTable.VisualProperties.YAxisLogScale = true;
     
    172172        qualityTable.Rows.Add(testRMSERow);
    173173        Results.Add(new Result(qualityTable.Name, qualityTable.Name + " for all restarts", qualityTable));
    174         if (SetSeedRandomly) Seed = (new System.Random()).Next();
     174        if(SetSeedRandomly) Seed = (new System.Random()).Next();
    175175        var rand = new MersenneTwister((uint)Seed);
    176176        bestSolution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);
    177177        trainRMSERow.Values.Add(bestSolution.TrainingRootMeanSquaredError);
    178178        testRMSERow.Values.Add(bestSolution.TestRootMeanSquaredError);
    179         for (int r = 0; r < Restarts; r++) {
     179        for(int r = 0; r < Restarts; r++) {
    180180          var solution = CreateRegressionSolution(Problem.ProblemData, ModelStructure, Iterations, rand);
    181181          trainRMSERow.Values.Add(solution.TrainingRootMeanSquaredError);
    182182          testRMSERow.Values.Add(solution.TestRootMeanSquaredError);
    183           if (solution.TrainingRootMeanSquaredError < bestSolution.TrainingRootMeanSquaredError) {
     183          if(solution.TrainingRootMeanSquaredError < bestSolution.TrainingRootMeanSquaredError) {
    184184            bestSolution = solution;
    185185          }
     
    216216      factorSymbol.AllVariableNames = factorSymbol.VariableNames;
    217217      factorSymbol.VariableValues =
    218         factorSymbol.VariableNames.Select(name => new KeyValuePair<string, List<string>>(name, problemData.Dataset.GetReadOnlyStringValues(name).Distinct().ToList()));
    219 
    220       foreach (var parent in tree.IterateNodesPrefix().ToArray()) {
    221         for (int i = 0; i < parent.SubtreeCount; i++) {
     218        factorSymbol.VariableNames.Select(name =>
     219        new KeyValuePair<string, Dictionary<string, int>>(name,
     220        problemData.Dataset.GetReadOnlyStringValues(name).Distinct()
     221        .Select((n, i) => Tuple.Create(n, i))
     222        .ToDictionary(tup => tup.Item1, tup => tup.Item2)));
     223
     224      foreach(var parent in tree.IterateNodesPrefix().ToArray()) {
     225        for(int i = 0; i < parent.SubtreeCount; i++) {
    222226          var child = parent.GetSubtree(i) as VariableTreeNode;
    223           if (child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
     227          if(child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
    224228            parent.RemoveSubtree(i);
    225229            var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode();
     
    232236      }
    233237
    234       if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure.");
     238      if(!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure.");
    235239
    236240      // initialize constants randomly
    237       if (rand != null) {
    238         foreach (var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) {
     241      if(rand != null) {
     242        foreach(var node in tree.IterateNodesPrefix().OfType<ConstantTreeNode>()) {
    239243          double f = Math.Exp(NormalDistributedRandom.NextDouble(rand, 0, 1));
    240244          double s = rand.NextDouble() < 0.5 ? -1 : 1;
Note: See TracChangeset for help on using the changeset viewer.