Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/07/17 15:32:26 (7 years ago)
Author:
pfleck
Message:

#1666:

  • Changed Progress interface (single parameterless ctor, overloads for Start-method).
  • Passed Impact-Calculator per ctor argument instead of virtual properties.
  • Created virtual OptimizeConstants-method instead of making the button-click event-handler virtual.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r15321 r15353  
    2121
    2222using System;
    23 using System.Threading.Tasks;
    2423using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     24using HeuristicLab.MainForm;
    2525using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    2828  public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
    29     private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;
    30 
    3129    public new SymbolicRegressionSolution Content {
    3230      get { return (SymbolicRegressionSolution)base.Content; }
     
    3432    }
    3533
    36     protected override ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator {
    37       get { return calculator; }
    38     }
    39 
    4034    public InteractiveSymbolicRegressionSolutionSimplifierView()
    41       : base() {
     35      : base(new SymbolicRegressionSolutionImpactValuesCalculator()) {
    4236      InitializeComponent();
    4337      this.Caption = "Interactive Regression Solution Simplifier";
    44       calculator = new SymbolicRegressionSolutionImpactValuesCalculator();
    4538    }
    4639
     
    5144    }
    5245
    53     protected override async void btnOptimizeConstants_Click(object sender, EventArgs e) {
     46    protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) {
    5447      const int constOptIterations = 50;
    55       var model = Content.Model;
    56       Progress.Start("Optimizing Constants ...", 0);
    57       await Task.Run(() => {
    58         SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices,
    59           applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit,
    60           iterationReport: (args, func, iter) => {
    61             Progress.ProgressValue = (double)iter / (constOptIterations + 1); // (maxIterations + 1) iterations are reported
    62           });
    63       });
    64       UpdateModel(Content.Model.SymbolicExpressionTree); // UpdateModel calls Progress.Finish
     48      var regressionModelModel = (ISymbolicDataAnalysisModel)model.Clone();
     49      var regressionProblemData = (IRegressionProblemData)problemData;
     50      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(regressionModelModel.Interpreter, regressionModelModel.SymbolicExpressionTree, regressionProblemData, regressionProblemData.TrainingIndices,
     51        applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: regressionModelModel.LowerEstimationLimit, upperEstimationLimit: regressionModelModel.UpperEstimationLimit,
     52        iterationCallback: (args, func, obj) => {
     53          // (maxIterations + 2) iterations are reported; Math.Min neccecary because of floating-point inaccuracies
     54          progress.ProgressValue = Math.Min(progress.ProgressValue + 1.0 / (constOptIterations + 2), 1);
     55        });
     56      return model.SymbolicExpressionTree;
    6557    }
    6658  }
Note: See TracChangeset for help on using the changeset viewer.