Changeset 17633 for branches/3040_VectorBasedGP
- Timestamp:
- 06/25/20 16:26:46 (4 years ago)
- 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 43 43 44 44 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); 47 48 } 48 49 … … 64 65 int reps = 0; 65 66 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) { 82 86 const int maxIterations = 1000; 87 var regressionProblemData = Content.ProblemData; 88 progress.CanBeStopped = true; 89 90 var learningRate = Math.Pow(10, (double)nudLearningRate.Value); 91 83 92 return TensorFlowConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, 84 93 regressionProblemData.TrainingIndices, 85 applyLinearScaling: false, updateVariableWeights: true, maxIterations: maxIterations, learningRate: 0.0001,94 applyLinearScaling: false, updateVariableWeights: true, maxIterations: maxIterations, learningRate: learningRate, 86 95 cancellationToken: cancellationToken, 87 96 progress: new SynchronousProgress<double>(cost => { -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r17456 r17633 55 55 this.btnSimplify = new System.Windows.Forms.Button(); 56 56 this.btnOptimizeConstants = new System.Windows.Forms.Button(); 57 this.btnVectorOptimizeConstants = new System.Windows.Forms.Button(); 58 this.nudLearningRate = new System.Windows.Forms.NumericUpDown(); 57 59 this.grpViewHost = new System.Windows.Forms.GroupBox(); 60 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 58 61 this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart(); 59 this.toolTip = new System.Windows.Forms.ToolTip(this.components);60 62 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 61 63 this.splitContainer.Panel1.SuspendLayout(); … … 129 131 // flowLayoutPanel 130 132 // 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) 132 134 | System.Windows.Forms.AnchorStyles.Right))); 133 135 this.flowLayoutPanel.Controls.Add(this.btnSimplify); 134 136 this.flowLayoutPanel.Controls.Add(this.btnOptimizeConstants); 137 this.flowLayoutPanel.Controls.Add(this.btnVectorOptimizeConstants); 138 this.flowLayoutPanel.Controls.Add(this.nudLearningRate); 135 139 this.flowLayoutPanel.Location = new System.Drawing.Point(6, 370); 136 140 this.flowLayoutPanel.Name = "flowLayoutPanel"; … … 168 172 this.btnOptimizeConstants.UseVisualStyleBackColor = true; 169 173 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}); 170 213 // 171 214 // grpViewHost … … 231 274 private System.Windows.Forms.Label treeStatusValue; 232 275 private System.Windows.Forms.ToolTip toolTip; 276 protected System.Windows.Forms.Button btnVectorOptimizeConstants; 277 protected System.Windows.Forms.NumericUpDown nudLearningRate; 233 278 } 234 279 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r17604 r17633 133 133 if (valid) { 134 134 btnOptimizeConstants.Enabled = true; 135 btnVectorOptimizeConstants.Enabled = true; 136 nudLearningRate.Enabled = true; 135 137 btnSimplify.Enabled = true; 136 138 treeStatusValue.Visible = false; 137 139 } else { 138 140 btnOptimizeConstants.Enabled = false; 141 btnVectorOptimizeConstants.Enabled = false; 142 nudLearningRate.Enabled = false; 139 143 btnSimplify.Enabled = false; 140 144 treeStatusValue.Visible = true; … … 231 235 232 236 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) { 233 240 return tree; 234 241 } … … 340 347 } 341 348 } 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 } 342 366 } 343 367 }
Note: See TracChangeset
for help on using the changeset viewer.