Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/20 16:26:46 (4 years ago)
Author:
pfleck
Message:

#3040 Reenabled the old optimize button in the simplifier and added a new button for const opt with vectors.

Location:
branches/3040_VectorBasedGP
Files:
3 edited

Legend:

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

    r17502 r17633  
    4343
    4444      var tree = Content?.Model?.SymbolicExpressionTree;
    45       //btnOptimizeConstants.Enabled = tree != null && NonlinearLeastSquaresConstantOptimizationEvaluator.CanOptimizeConstants(tree);
    46       btnOptimizeConstants.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     45      btnOptimizeConstants.Enabled = tree != null && NonlinearLeastSquaresConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     46      btnVectorOptimizeConstants.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     47      nudLearningRate.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
    4748    }
    4849
     
    6465      int reps = 0;
    6566
    66       //do {
    67       //  prevResult = result;
    68       //  tree = NonlinearLeastSquaresConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, regressionProblemData.TrainingIndices,
    69       //    applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true,
    70       //    cancellationToken: cancellationToken, iterationCallback: (args, func, obj) => {
    71       //      double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
    72       //      progress.ProgressValue = Math.Min(newProgressValue, 1.0);
    73       //    });
    74       //  result = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(model.Interpreter, tree,
    75       //    model.LowerEstimationLimit, model.UpperEstimationLimit, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true);
    76       //  reps++;
    77       //  improvement = result - prevResult;
    78       //} while (improvement > minimumImprovement && reps < maxRepetitions &&
    79       //         progress.ProgressState != ProgressState.StopRequested &&
    80       //         progress.ProgressState != ProgressState.CancelRequested);
    81       //return tree;
     67      do {
     68        prevResult = result;
     69        tree = NonlinearLeastSquaresConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, regressionProblemData.TrainingIndices,
     70          applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true,
     71          cancellationToken: cancellationToken, iterationCallback: (args, func, obj) => {
     72            double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
     73            progress.ProgressValue = Math.Min(newProgressValue, 1.0);
     74          });
     75        result = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(model.Interpreter, tree,
     76          model.LowerEstimationLimit, model.UpperEstimationLimit, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true);
     77        reps++;
     78        improvement = result - prevResult;
     79      } while (improvement > minimumImprovement && reps < maxRepetitions &&
     80               progress.ProgressState != ProgressState.StopRequested &&
     81               progress.ProgressState != ProgressState.CancelRequested);
     82      return tree;
     83    }
     84
     85    protected override ISymbolicExpressionTree VectorOptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
    8286      const int maxIterations = 1000;
     87      var regressionProblemData = Content.ProblemData;
     88      progress.CanBeStopped = true;
     89
     90      var learningRate = Math.Pow(10, (double)nudLearningRate.Value);
     91
    8392      return TensorFlowConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData,
    8493        regressionProblemData.TrainingIndices,
    85         applyLinearScaling: false, updateVariableWeights: true, maxIterations: maxIterations, learningRate: 0.0001,
     94        applyLinearScaling: false, updateVariableWeights: true, maxIterations: maxIterations, learningRate: learningRate,
    8695        cancellationToken: cancellationToken,
    8796        progress: new SynchronousProgress<double>(cost => {
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r17456 r17633  
    5555      this.btnSimplify = new System.Windows.Forms.Button();
    5656      this.btnOptimizeConstants = new System.Windows.Forms.Button();
     57      this.btnVectorOptimizeConstants = new System.Windows.Forms.Button();
     58      this.nudLearningRate = new System.Windows.Forms.NumericUpDown();
    5759      this.grpViewHost = new System.Windows.Forms.GroupBox();
     60      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5861      this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart();
    59       this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    6062      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    6163      this.splitContainer.Panel1.SuspendLayout();
     
    129131      // flowLayoutPanel
    130132      //
    131       this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     133      this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
    132134            | System.Windows.Forms.AnchorStyles.Right)));
    133135      this.flowLayoutPanel.Controls.Add(this.btnSimplify);
    134136      this.flowLayoutPanel.Controls.Add(this.btnOptimizeConstants);
     137      this.flowLayoutPanel.Controls.Add(this.btnVectorOptimizeConstants);
     138      this.flowLayoutPanel.Controls.Add(this.nudLearningRate);
    135139      this.flowLayoutPanel.Location = new System.Drawing.Point(6, 370);
    136140      this.flowLayoutPanel.Name = "flowLayoutPanel";
     
    168172      this.btnOptimizeConstants.UseVisualStyleBackColor = true;
    169173      this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click);
     174      //
     175      // btnVectorOptimizeConstants
     176      //
     177      this.btnVectorOptimizeConstants.AutoSize = true;
     178      this.btnVectorOptimizeConstants.Enabled = false;
     179      this.btnVectorOptimizeConstants.Image = HeuristicLab.Common.Resources.VSImageLibrary.Performance;
     180      this.btnVectorOptimizeConstants.Location = new System.Drawing.Point(175, 3);
     181      this.btnVectorOptimizeConstants.Name = "btnVectorOptimizeConstants";
     182      this.btnVectorOptimizeConstants.Size = new System.Drawing.Size(107, 24);
     183      this.btnVectorOptimizeConstants.TabIndex = 3;
     184      this.btnVectorOptimizeConstants.Text = "Vector-Optimize";
     185      this.btnVectorOptimizeConstants.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     186      this.toolTip.SetToolTip(this.btnVectorOptimizeConstants, "Optimizes the numerical constants of the model. \r\nIf the algorithm converges, opt" +
     187        "imization is stopped.");
     188      this.btnVectorOptimizeConstants.UseVisualStyleBackColor = true;
     189      this.btnVectorOptimizeConstants.Click += new System.EventHandler(this.btnVectorOptimizeConstants_Click);
     190      //
     191      // nudLearningRate
     192      //
     193      this.nudLearningRate.Location = new System.Drawing.Point(288, 3);
     194      this.nudLearningRate.Maximum = new decimal(new int[] {
     195            20,
     196            0,
     197            0,
     198            0});
     199      this.nudLearningRate.Minimum = new decimal(new int[] {
     200            20,
     201            0,
     202            0,
     203            -2147483648});
     204      this.nudLearningRate.Name = "nudLearningRate";
     205      this.nudLearningRate.Size = new System.Drawing.Size(45, 20);
     206      this.nudLearningRate.TabIndex = 4;
     207      this.toolTip.SetToolTip(this.nudLearningRate, "Learning Rate (logarithmic)");
     208      this.nudLearningRate.Value = new decimal(new int[] {
     209            2,
     210            0,
     211            0,
     212            -2147483648});
    170213      //
    171214      // grpViewHost
     
    231274    private System.Windows.Forms.Label treeStatusValue;
    232275    private System.Windows.Forms.ToolTip toolTip;
     276    protected System.Windows.Forms.Button btnVectorOptimizeConstants;
     277    protected System.Windows.Forms.NumericUpDown nudLearningRate;
    233278  }
    234279}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17604 r17633  
    133133      if (valid) {
    134134        btnOptimizeConstants.Enabled = true;
     135        btnVectorOptimizeConstants.Enabled = true;
     136        nudLearningRate.Enabled = true;
    135137        btnSimplify.Enabled = true;
    136138        treeStatusValue.Visible = false;
    137139      } else {
    138140        btnOptimizeConstants.Enabled = false;
     141        btnVectorOptimizeConstants.Enabled = false;
     142        nudLearningRate.Enabled = false;
    139143        btnSimplify.Enabled = false;
    140144        treeStatusValue.Visible = true;
     
    231235
    232236    protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
     237      return tree;
     238    }
     239    protected virtual ISymbolicExpressionTree VectorOptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
    233240      return tree;
    234241    }
     
    340347      }
    341348    }
     349
     350    private async void btnVectorOptimizeConstants_Click(object sender, EventArgs e) {
     351      progress.Start("Optimizing Constants ...");
     352      cancellationTokenSource = new CancellationTokenSource();
     353      progress.CanBeStopped = true;
     354      try {
     355        var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
     356
     357        var newTree = await Task.Run(() => VectorOptimizeConstants(tree, cancellationTokenSource.Token, progress), cancellationTokenSource.Token);
     358        try {
     359          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
     360        } catch (OperationCanceledException) { }
     361        UpdateModel(newTree); // triggers progress.Finish after calculating the node impacts when model is changed
     362      } catch {
     363        progress.Finish();
     364      }
     365    }
    342366  }
    343367}
Note: See TracChangeset for help on using the changeset viewer.