Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13889 for trunk


Ignore:
Timestamp:
06/10/16 10:53:37 (8 years ago)
Author:
gkronber
Message:

#1795: added parameter to turn on/off storing of individual runs

File:
1 edited

Legend:

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

    r13724 r13889  
    6464    private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
    6565    private const string CreateSolutionParameterName = "CreateSolution";
     66    private const string StoreRunsParameterName = "StoreRuns";
    6667    private const string RegressionAlgorithmSolutionResultParameterName = "RegressionAlgorithmResult";
    6768
     
    106107      get { return (IFixedValueParameter<BoolValue>)Parameters[CreateSolutionParameterName]; }
    107108    }
     109    public IFixedValueParameter<BoolValue> StoreRunsParameter {
     110      get { return (IFixedValueParameter<BoolValue>)Parameters[StoreRunsParameterName]; }
     111    }
    108112
    109113    #endregion
     
    144148      get { return CreateSolutionParameter.Value.Value; }
    145149      set { CreateSolutionParameter.Value.Value = value; }
     150    }
     151
     152    public bool StoreRuns {
     153      get { return StoreRunsParameter.Value.Value; }
     154      set { StoreRunsParameter.Value.Value = value; }
    146155    }
    147156
     
    178187      var regressionAlgs = new ItemSet<IAlgorithm>(new IAlgorithm[] {
    179188        new RandomForestRegression(),
    180         sgp, 
     189        sgp,
    181190        mctsSymbReg
    182191      });
     
    206215        "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));
    207216      Parameters[CreateSolutionParameterName].Hidden = true;
     217      Parameters.Add(new FixedValueParameter<BoolValue>(StoreRunsParameterName,
     218        "Flag that indicates if the results of the individual runs should be stored for detailed analysis", new BoolValue(false)));
     219      Parameters[StoreRunsParameterName].Hidden = true;
    208220    }
    209221
     
    218230
    219231      var table = new DataTable("Qualities");
    220       table.Rows.Add(new DataRow("Loss (train)"));
    221       table.Rows.Add(new DataRow("Loss (test)"));
     232      table.Rows.Add(new DataRow(" (train)"));
     233      table.Rows.Add(new DataRow(" (test)"));
    222234      Results.Add(new Result("Qualities", table));
    223235      var curLoss = new DoubleValue();
    224236      var curTestLoss = new DoubleValue();
    225       Results.Add(new Result("Loss (train)", curLoss));
    226       Results.Add(new Result("Loss (test)", curTestLoss));
     237      Results.Add(new Result(" (train)", curLoss));
     238      Results.Add(new Result(" (test)", curTestLoss));
    227239      var runCollection = new RunCollection();
    228       Results.Add(new Result("Runs", runCollection));
     240      if (StoreRuns)
     241        Results.Add(new Result("Runs", runCollection));
    229242
    230243      // init
    231244      var problemData = Problem.ProblemData;
    232       var targetVarName = Problem.ProblemData.TargetVariable;
     245      var targetVarName = problemData.TargetVariable;
    233246      var activeVariables = problemData.AllowedInputVariables.Concat(new string[] { problemData.TargetVariable });
    234247      var modifiableDataset = new ModifiableDataset(
     
    303316          }
    304317
    305           runCollection.Add(run);
    306           table.Rows["Loss (train)"].Values.Add(curLoss.Value);
    307           table.Rows["Loss (test)"].Values.Add(curTestLoss.Value);
     318          if (StoreRuns)
     319            runCollection.Add(run);
     320          table.Rows["R² (train)"].Values.Add(curLoss.Value);
     321          table.Rows["R² (test)"].Values.Add(curTestLoss.Value);
    308322          iterations.Value = i + 1;
    309323        }
     
    408422      model = null;
    409423      using (var wh = new AutoResetEvent(false)) {
    410         EventHandler<EventArgs<Exception>> handler = (sender, args) => wh.Set();
     424        Exception ex = null;
     425        EventHandler<EventArgs<Exception>> handler = (sender, args) => {
     426          ex = args.Value;
     427          wh.Set();
     428        };
    411429        EventHandler handler2 = (sender, args) => wh.Set();
    412430        alg.ExceptionOccurred += handler;
     
    417435          wh.WaitOne();
    418436
     437          if (ex != null) throw new AggregateException(ex);
    419438          run = alg.Runs.Last();
     439          alg.Runs.Clear();
    420440          var sols = alg.Results.Select(r => r.Value).OfType<IRegressionSolution>();
    421441          if (!sols.Any()) return false;
Note: See TracChangeset for help on using the changeset viewer.