Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/20 09:19:42 (4 years ago)
Author:
pfleck
Message:

#3040 Worked in DiffSharp for constant-opt.

File:
1 edited

Legend:

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

    r17633 r17786  
    4646      btnVectorOptimizeConstants.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
    4747      nudLearningRate.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     48      btnUnrollingVectorOptimizeConstants.Enabled = tree != null && VectorUnrollingNonlinearLeastSquaresConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     49      btnDiffSharpOptimizeConstants.Enabled = tree != null && NonlinearLeastSquaresVectorConstantOptimizationEvaluator.CanOptimizeConstants(tree);
    4850    }
    4951
     
    102104    }
    103105
     106    protected override ISymbolicExpressionTree UnrollingVectorOptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
     107      const int constOptIterations = 50;
     108      const int maxRepetitions = 100;
     109      const double minimumImprovement = 1e-10;
     110      var regressionProblemData = Content.ProblemData;
     111      var model = Content.Model;
     112      progress.CanBeStopped = true;
     113      double prevResult = 0.0, improvement = 0.0;
     114      var result = 0.0;
     115      int reps = 0;
     116      var interpreter = new SymbolicDataAnalysisExpressionTreeVectorInterpreter();
     117
     118      do {
     119        prevResult = result;
     120        tree = VectorUnrollingNonlinearLeastSquaresConstantOptimizationEvaluator.OptimizeTree(
     121          tree, interpreter,
     122          regressionProblemData, regressionProblemData.TrainingIndices,
     123          applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true,
     124          cancellationToken: cancellationToken, iterationCallback: (args, func, obj) => {
     125            double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
     126            progress.ProgressValue = Math.Min(newProgressValue, 1.0);
     127          });
     128        result = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(model.Interpreter, tree,
     129          model.LowerEstimationLimit, model.UpperEstimationLimit, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true);
     130        reps++;
     131        improvement = result - prevResult;
     132      } while (improvement > minimumImprovement && reps < maxRepetitions &&
     133               progress.ProgressState != ProgressState.StopRequested &&
     134               progress.ProgressState != ProgressState.CancelRequested);
     135      return tree;
     136    }
     137
     138
     139    protected override ISymbolicExpressionTree DiffSharpVectorOptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
     140      const int constOptIterations = 50;
     141      const int maxRepetitions = 100;
     142      const double minimumImprovement = 1e-10;
     143      var regressionProblemData = Content.ProblemData;
     144      var model = Content.Model;
     145      progress.CanBeStopped = true;
     146      double prevResult = 0.0, improvement = 0.0;
     147      var result = 0.0;
     148      int reps = 0;
     149
     150      do {
     151        prevResult = result;
     152        tree = NonlinearLeastSquaresVectorConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, regressionProblemData.TrainingIndices,
     153          applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true,
     154          cancellationToken: cancellationToken, iterationCallback: (args, func, obj) => {
     155            double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
     156            progress.ProgressValue = Math.Min(newProgressValue, 1.0);
     157          });
     158        result = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(model.Interpreter, tree,
     159          model.LowerEstimationLimit, model.UpperEstimationLimit, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true);
     160        reps++;
     161        improvement = result - prevResult;
     162      } while (improvement > minimumImprovement && reps < maxRepetitions &&
     163               progress.ProgressState != ProgressState.StopRequested &&
     164               progress.ProgressState != ProgressState.CancelRequested);
     165      return tree;
     166    }
     167
     168
    104169    internal class SynchronousProgress<T> : IProgress<T> {
    105170      private readonly Action<T> callback;
Note: See TracChangeset for help on using the changeset viewer.