Changeset 15353
- Timestamp:
- 09/07/17 15:32:26 (7 years ago)
- Location:
- branches/SimplifierViewsProgress
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimplifierViewsProgress/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r15320 r15353 371 371 contentViews = contentViews.Where(v => v.Content == content); 372 372 373 var progress = new Progress(progressMessage, ProgressState.Started, progressValue); 373 var progress = new Progress(); 374 progress.Start(progressMessage, progressValue); 374 375 foreach (var contentView in contentViews) { 375 376 progressViews.Add(new ProgressView(contentView, progress)); … … 384 385 /// </summary> 385 386 public IProgress AddOperationProgressToView(Control control, string progressMessage) { 386 var progress = new Progress(progressMessage, ProgressState.Started); 387 var progress = new Progress(); 388 progress.Start(progressMessage); 387 389 AddOperationProgressToView(control, progress); 388 390 return progress; -
branches/SimplifierViewsProgress/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r15320 r15353 63 63 /// Starts or restarts a Progress. 64 64 /// </summary> 65 void Start(string status = null, double progressValue = -1.0); 65 void Start(); 66 void Start(string status); 67 void Start(string status, double progressValue); 66 68 67 69 /// <summary> -
branches/SimplifierViewsProgress/HeuristicLab.MainForm/3.3/Progress.cs
r15320 r15353 68 68 } 69 69 70 public Progress(string status = null, ProgressState state = ProgressState.Finished, double progressValue = -1) 71 : base() { 72 this.status = status; 73 this.progressState = state; 74 this.progressValue = progressValue; 70 public Progress() { 71 progressState = ProgressState.Finished; 72 canBeCanceled = false; 75 73 } 76 74 … … 85 83 } 86 84 87 public void Start(string status = null, double progressValue = -1.0) { 85 public void Start() { 86 Start(string.Empty); 87 } 88 public void Start(string status) { 89 Start(status, -1.0); 90 } 91 public void Start(string status, double progressValue) { 88 92 ProgressState = ProgressState.Started; 89 Status = status ;93 Status = status ?? string.Empty; 90 94 ProgressValue = progressValue; 91 95 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicClassificationSolutionSimplifierViewBase.cs
r15321 r15353 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 27 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views { 28 27 public abstract partial class InteractiveSymbolicClassificationSolutionSimplifierViewBase : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 29 private readonly SymbolicClassificationSolutionImpactValuesCalculator calculator;30 31 28 public new ISymbolicClassificationSolution Content { 32 29 get { return (ISymbolicClassificationSolution)base.Content; } … … 34 31 } 35 32 36 protected override ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator { 37 get { return calculator; } 38 } 39 40 public InteractiveSymbolicClassificationSolutionSimplifierViewBase() 41 : base() { 33 protected InteractiveSymbolicClassificationSolutionSimplifierViewBase() 34 : base(new SymbolicClassificationSolutionImpactValuesCalculator()) { 42 35 InitializeComponent(); 43 36 this.Caption = "Interactive Classification Solution Simplifier"; 44 45 calculator = new SymbolicClassificationSolutionImpactValuesCalculator();46 37 } 47 38 … … 61 52 return model; 62 53 } 63 64 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {65 66 }67 54 } 68 55 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r15321 r15353 21 21 22 22 using System; 23 using System.Threading.Tasks;24 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 using HeuristicLab.MainForm; 25 25 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views { 28 28 public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 29 private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;30 31 29 public new SymbolicRegressionSolution Content { 32 30 get { return (SymbolicRegressionSolution)base.Content; } … … 34 32 } 35 33 36 protected override ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator {37 get { return calculator; }38 }39 40 34 public InteractiveSymbolicRegressionSolutionSimplifierView() 41 : base( ) {35 : base(new SymbolicRegressionSolutionImpactValuesCalculator()) { 42 36 InitializeComponent(); 43 37 this.Caption = "Interactive Regression Solution Simplifier"; 44 calculator = new SymbolicRegressionSolutionImpactValuesCalculator();45 38 } 46 39 … … 51 44 } 52 45 53 protected override async void btnOptimizeConstants_Click(object sender, EventArgs e) {46 protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) { 54 47 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; 65 57 } 66 58 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r15319 r15353 156 156 int maxIterations, bool updateVariableWeights = true, 157 157 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, 158 bool updateConstantsInTree = true, Action<double[], double, int> iterationReport= null) {158 bool updateConstantsInTree = true, Action<double[], double, object> iterationCallback = null) { 159 159 160 160 // numeric constants in the tree become variables for constant opt … … 210 210 alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(func); 211 211 alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(func_grad); 212 213 int i = 0; 214 var xrep = new alglib.ndimensional_rep((a, f, o) => { 215 if (iterationReport != null) iterationReport(a, f, i++); 216 }); 212 alglib.ndimensional_rep xrep = null; 213 if (iterationCallback != null) 214 xrep = new alglib.ndimensional_rep(iterationCallback); 217 215 218 216 try { 219 217 alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state); 220 218 alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations); 221 alglib.lsfitsetxrep(state, iteration Report!= null);219 alglib.lsfitsetxrep(state, iterationCallback != null); 222 220 //alglib.lsfitsetgradientcheck(state, 0.001); 223 221 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, xrep, null); -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r15321 r15353 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 23 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; … … 27 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views { 28 27 public partial class InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 29 private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;30 31 28 public new SymbolicTimeSeriesPrognosisSolution Content { 32 29 get { return (SymbolicTimeSeriesPrognosisSolution)base.Content; } … … 34 31 } 35 32 36 protected override ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator {37 get { return calculator; }38 }39 40 33 public InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView() 41 : base( ) {34 : base(new SymbolicRegressionSolutionImpactValuesCalculator()) { 42 35 InitializeComponent(); 43 36 this.Caption = "Interactive Time-Series Prognosis Solution Simplifier"; 44 calculator = new SymbolicRegressionSolutionImpactValuesCalculator();45 37 } 46 38 … … 50 42 Content.Model = model; 51 43 } 52 53 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {54 55 }56 44 } 57 45 } -
branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15321 r15353 38 38 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 39 39 40 protected IProgress Progress = new Progress(); 40 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 42 private readonly IProgress progress = new Progress(); 41 43 42 44 private enum TreeState { Valid, Invalid } 43 45 private TreeState treeState; 44 46 45 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView( ) {47 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) { 46 48 InitializeComponent(); 47 49 foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); … … 49 51 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 50 52 this.Caption = "Interactive Solution Simplifier"; 53 this.impactCalculator = impactCalculator; 51 54 52 55 // initialize the tree modifier that will be used to perform edit operations over the tree … … 149 152 Content.ProblemDataChanged += Content_Changed; 150 153 treeChart.Repainted += treeChart_Repainted; 151 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, Progress);154 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); 152 155 } 153 156 protected override void DeregisterContentEvents() { … … 180 183 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 181 184 182 Progress.Start("Calculate Impact and Replacement Values ...", 0);185 progress.Start("Calculate Impact and Replacement Values ...", 0); 183 186 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 184 187 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); … … 187 190 } 188 191 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 189 Progress.Finish();192 progress.Finish(); 190 193 PaintNodeImpacts(); 191 194 } … … 195 198 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 196 199 double impactValue, replacementValue, newQualityForImpactsCalculation; 197 ImpactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);198 Progress.ProgressValue += 1.0 / (tree.Length - 2);200 impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation); 201 progress.ProgressValue += 1.0 / (tree.Length - 2); 199 202 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue)); 200 203 } … … 204 207 protected abstract void UpdateModel(ISymbolicExpressionTree tree); 205 208 206 protected abstract ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator { get; } 209 protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) { 210 return model.SymbolicExpressionTree; 211 } 207 212 208 213 private static ConstantTreeNode MakeConstantTreeNode(double value) { … … 290 295 } 291 296 292 protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e); 297 private async void btnOptimizeConstants_Click(object sender, EventArgs e) { 298 progress.Start("Optimizing Constants ...", 0); 299 var newTree = await Task.Run(() => OptimizeConstants(Content.Model, Content.ProblemData, progress)); 300 UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed) 301 } 293 302 } 294 303 }
Note: See TracChangeset
for help on using the changeset viewer.