- Timestamp:
- 08/10/17 13:49:26 (7 years ago)
- Location:
- branches/SimplifierViewsProgress
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r14826 r15319 22 22 using System; 23 23 using System.Collections.Generic; 24 using System. Linq;24 using System.Threading.Tasks; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; … … 54 54 double impactValue, replacementValue, newQualityForImpactsCalculation; 55 55 calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation); 56 Progress.ProgressValue += 1.0 / (tree.Length - 2); 56 57 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue)); 57 58 } … … 59 60 } 60 61 61 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) { 62 protected override async void btnOptimizeConstants_Click(object sender, EventArgs e) { 63 const int constOptIterations = 50; 62 64 var model = Content.Model; 63 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices, 64 applyLinearScaling: true, maxIterations: 50, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit); 65 UpdateModel(Content.Model.SymbolicExpressionTree); 65 Progress.Start("Optimizing Constants ...", 0); 66 await Task.Run(() => { 67 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices, 68 applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit, 69 iterationReport: (args, func, iter) => { 70 Progress.ProgressValue = (double)iter / (constOptIterations + 1); // (maxIterations + 1) iterations are reported 71 }); 72 }); 73 UpdateModel(Content.Model.SymbolicExpressionTree); // UpdateModel calls Progress.Finish 66 74 } 67 75 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs
r14185 r15319 51 51 private void btn_SimplifyModel_Click(object sender, EventArgs e) { 52 52 var view = new InteractiveSymbolicRegressionSolutionSimplifierView(); 53 view.Show(); // open view first that a progress can be displayed when setting the content 53 54 view.Content = (SymbolicRegressionSolution)this.Content.Clone(); 54 view.Show();55 55 } 56 56 -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14951 r15319 156 156 int maxIterations, bool updateVariableWeights = true, 157 157 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, 158 bool updateConstantsInTree = true ) {158 bool updateConstantsInTree = true, Action<double[], double, int> iterationReport = null) { 159 159 160 160 // numeric constants in the tree become variables for constant opt … … 211 211 alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(func_grad); 212 212 213 int i = 0; 214 var xrep = new alglib.ndimensional_rep((a, f, o) => { 215 if (iterationReport != null) iterationReport(a, f, i++); 216 }); 217 213 218 try { 214 219 alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state); 215 220 alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations); 221 alglib.lsfitsetxrep(state, iterationReport != null); 216 222 //alglib.lsfitsetgradientcheck(state, 0.001); 217 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null);223 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, xrep, null); 218 224 alglib.lsfitresults(state, out retVal, out c, out rep); 219 } 220 catch (ArithmeticException) { 225 } catch (ArithmeticException) { 221 226 return originalQuality; 222 } 223 catch (alglib.alglibexception) { 227 } catch (alglib.alglibexception) { 224 228 return originalQuality; 225 229 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r14949 r15319 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading.Tasks; 26 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 31 using HeuristicLab.MainForm; 30 32 using HeuristicLab.MainForm.WindowsForms; 31 33 … … 35 37 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes; 36 38 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 39 40 protected IProgress Progress = new Progress(); 37 41 38 42 private enum TreeState { Valid, Invalid } … … 145 149 Content.ProblemDataChanged += Content_Changed; 146 150 treeChart.Repainted += treeChart_Repainted; 151 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, Progress); 147 152 } 148 153 protected override void DeregisterContentEvents() { … … 151 156 Content.ProblemDataChanged -= Content_Changed; 152 157 treeChart.Repainted -= treeChart_Repainted; 158 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); 153 159 } 154 160 … … 169 175 } 170 176 171 private void UpdateView() {177 private async void UpdateView() { 172 178 if (Content == null || Content.Model == null || Content.ProblemData == null) return; 173 179 var tree = Content.Model.SymbolicExpressionTree; 174 180 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 175 181 176 var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree); 182 Progress.Start("Calculate Impact and Replacement Values ...", 0); 183 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 177 184 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 178 185 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { … … 180 187 } 181 188 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 189 Progress.Finish(); 182 190 PaintNodeImpacts(); 183 191 }
Note: See TracChangeset
for help on using the changeset viewer.