Changeset 15371
- Timestamp:
- 09/19/17 10:49:02 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/SimplifierViewsProgress/HeuristicLab.MainForm.WindowsForms merged eligible /branches/crossvalidation-2434/HeuristicLab.MainForm.WindowsForms merged eligible /stable/HeuristicLab.MainForm.WindowsForms merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.MainForm.WindowsForms 10321-10322 /branches/Algorithms.GradientDescent/HeuristicLab.MainForm.WindowsForms 5516-5520 /branches/Async/HeuristicLab.MainForm.WindowsForms 13329-15286 /branches/Benchmarking/sources/HeuristicLab.MainForm.WindowsForms 6917-7005 /branches/CloningRefactoring/HeuristicLab.MainForm.WindowsForms 4656-4721 /branches/CodeEditor/HeuristicLab.MainForm.WindowsForms 11700-11806 /branches/DataAnalysis Refactoring/HeuristicLab.MainForm.WindowsForms 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.MainForm.WindowsForms 5815-6180 /branches/DataAnalysis/HeuristicLab.MainForm.WindowsForms 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.MainForm.WindowsForms 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.MainForm.WindowsForms 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.MainForm.WindowsForms 5060 /branches/HLScript/HeuristicLab.MainForm.WindowsForms 10331-10358 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.MainForm.WindowsForms 11570-12508 /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.MainForm.WindowsForms 6123-9799 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.MainForm.WindowsForms 11130-12721 /branches/HiveStatistics/sources/HeuristicLab.MainForm.WindowsForms 12440-12877 /branches/LogResidualEvaluator/HeuristicLab.MainForm.WindowsForms 10202-10483 /branches/NET40/sources/HeuristicLab.MainForm.WindowsForms 5138-5162 /branches/NSGA-II Changes/HeuristicLab.MainForm.WindowsForms 12033-12122 /branches/ParallelEngine/HeuristicLab.MainForm.WindowsForms 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.MainForm.WindowsForms 7568-7810 /branches/QAPAlgorithms/HeuristicLab.MainForm.WindowsForms 6350-6627 /branches/Restructure trunk solution/HeuristicLab.MainForm.WindowsForms 6828 /branches/RuntimeOptimizer/HeuristicLab.MainForm.WindowsForms 8943-9078 /branches/ScatterSearch (trunk integration)/HeuristicLab.MainForm.WindowsForms 7787-8333 /branches/SlaveShutdown/HeuristicLab.MainForm.WindowsForms 8944-8956 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.MainForm.WindowsForms 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.MainForm.WindowsForms 5370-5682 /branches/Trunk/HeuristicLab.MainForm.WindowsForms 6829-6865 /branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms 9168-9215 /branches/VNS/HeuristicLab.MainForm.WindowsForms 5594-5752 /branches/histogram/HeuristicLab.MainForm.WindowsForms 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.MainForm.WindowsForms 14232-14825
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r14297 r15371 154 154 if (content != null) { 155 155 double progressValue = content.ProgressValue; 156 if (progressValue < =0.0 || progressValue > 1.0) {156 if (progressValue < 0.0 || progressValue > 1.0) { 157 157 progressBar.Style = ProgressBarStyle.Marquee; 158 158 } else { -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r14185 r15371 230 230 } 231 231 232 public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class, IContent {232 public IContentView ShowContent<T>(T content, bool reuseExistingView, IEqualityComparer<T> comparer = null) where T : class, IContent { 233 233 if (content == null) throw new ArgumentNullException("Content cannot be null."); 234 234 if (!reuseExistingView) return ShowContent(content); … … 353 353 /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content. 354 354 /// </summary> 355 public IProgress AddOperationProgressToContent(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {355 public IProgress AddOperationProgressToContent(IContent content, string progressMessage, double progressValue = -1, bool addToObjectGraphObjects = true) { 356 356 if (InvokeRequired) { 357 IProgress result = (IProgress)Invoke((Func<IContent, string, bool, IProgress>)AddOperationProgressToContent, content, progressMessage, addToObjectGraphObjects);357 IProgress result = (IProgress)Invoke((Func<IContent, string, double, bool, IProgress>)AddOperationProgressToContent, content, progressMessage, progressValue, addToObjectGraphObjects); 358 358 return result; 359 359 } … … 371 371 contentViews = contentViews.Where(v => v.Content == content); 372 372 373 var progress = new Progress(progressMessage, ProgressState.Started); 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; -
trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r14185 r15371 64 64 /// </summary> 65 65 void Start(); 66 67 66 void Start(string status); 67 void Start(string status, double progressValue); 68 68 69 69 /// <summary> -
trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
r14185 r15371 72 72 canBeCanceled = false; 73 73 } 74 public Progress(string status)75 : this() {76 this.status = status;77 }78 public Progress(string status, ProgressState state)79 : this() {80 this.status = status;81 this.progressState = state;82 }83 74 84 75 public void Cancel() { … … 93 84 94 85 public void Start() { 95 ProgressValue = 0.0; 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) { 96 92 ProgressState = ProgressState.Started; 97 } 98 99 public void Start(string status) { 100 Start(); 101 Status = status; 93 Status = status ?? string.Empty; 94 ProgressValue = progressValue; 102 95 } 103 96 -
trunk/sources/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis (added) merged: 15318
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic (added) merged: 15318,15321
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification (added) merged: 15318,15321
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views (added) merged: 15318,15321,15353
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicClassificationSolutionSimplifierViewBase.cs
r14826 r15371 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 29 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views { 30 27 public abstract partial class InteractiveSymbolicClassificationSolutionSimplifierViewBase : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 31 private readonly SymbolicClassificationSolutionImpactValuesCalculator calculator;32 33 28 public new ISymbolicClassificationSolution Content { 34 29 get { return (ISymbolicClassificationSolution)base.Content; } … … 36 31 } 37 32 38 p ublicInteractiveSymbolicClassificationSolutionSimplifierViewBase()39 : base( ) {33 protected InteractiveSymbolicClassificationSolutionSimplifierViewBase() 34 : base(new SymbolicClassificationSolutionImpactValuesCalculator()) { 40 35 InitializeComponent(); 41 36 this.Caption = "Interactive Classification Solution Simplifier"; 42 43 calculator = new SymbolicClassificationSolutionImpactValuesCalculator();44 37 } 45 38 … … 59 52 return model; 60 53 } 61 62 protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {63 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();64 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {65 double impactValue, replacementValue, newQualityForImpactsCalculation;66 calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);67 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue));68 }69 return impactAndReplacementValues;70 }71 72 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {73 74 }75 54 } 76 55 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r14826 r15371 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;27 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 26 … … 40 38 protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 41 39 42 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, 43 ISymbolicExpressionTreeNode node, 44 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 45 out double newQualityForImpactsCalculation, 46 double qualityForImpactsCalculation = Double.NaN) { 40 protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 47 41 var classificationModel = (ISymbolicClassificationModel)model; 48 42 var classificationProblemData = (IClassificationProblemData)problemData; 49 50 if (double.IsNaN(qualityForImpactsCalculation))51 qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);52 53 54 var cloner = new Cloner();55 var tempModel = cloner.Clone(classificationModel);56 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);57 58 var tempModelParentNode = tempModelNode.Parent;59 int i = tempModelParentNode.IndexOfSubtree(tempModelNode);60 double bestReplacementValue = 0.0;61 double bestImpactValue = double.PositiveInfinity;62 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize63 // try the potentially reasonable replacement values and use the best one64 foreach (var repValue in CalculateReplacementValues(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, classificationProblemData.TrainingIndices)) {65 tempModelParentNode.RemoveSubtree(i);66 67 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };68 tempModelParentNode.InsertSubtree(i, constantNode);69 70 var dataset = classificationProblemData.Dataset;71 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);72 var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);73 OnlineCalculatorError errorState;74 newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues,75 out errorState);76 if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;77 78 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;79 80 if (impactValue < bestImpactValue) {81 bestImpactValue = impactValue;82 bestReplacementValue = repValue;83 }84 }85 replacementValue = bestReplacementValue;86 impactValue = bestImpactValue;87 }88 89 public static double CalculateQualityForImpacts(ISymbolicClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) {90 43 OnlineCalculatorError errorState; 91 44 var dataset = problemData.Dataset; 92 var targetClassValues = dataset.GetDoubleValues( problemData.TargetVariable, rows);93 var originalClassValues = model.GetEstimatedClassValues(dataset, rows);45 var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows); 46 var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows); 94 47 var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState); 95 48 if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0; 96 97 49 return qualityForImpactsCalculation; 98 50 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression (added) merged: 15318-15319,15321,15353-15354
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views (added) merged: 15318-15319,15321,15353,15356
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r14826 r15371 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 using HeuristicLab.MainForm; 26 25 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; 27 26 28 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views { 29 28 public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 30 private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;31 32 29 public new SymbolicRegressionSolution Content { 33 30 get { return (SymbolicRegressionSolution)base.Content; } … … 36 33 37 34 public InteractiveSymbolicRegressionSolutionSimplifierView() 38 : base( ) {35 : base(new SymbolicRegressionSolutionImpactValuesCalculator()) { 39 36 InitializeComponent(); 40 37 this.Caption = "Interactive Regression Solution Simplifier"; 41 calculator = new SymbolicRegressionSolutionImpactValuesCalculator();42 38 } 43 39 … … 48 44 } 49 45 50 51 protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) { 52 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>(); 53 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 54 double impactValue, replacementValue, newQualityForImpactsCalculation; 55 calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation); 56 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue)); 57 } 58 return impactAndReplacementValues; 59 } 60 61 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) { 62 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); 46 protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) { 47 const int constOptIterations = 50; 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 double newProgressValue = progress.ProgressValue + 1.0 / (constOptIterations + 2); // (maxIterations + 2) iterations are reported 54 progress.ProgressValue = Math.Min(newProgressValue, 1.0); 55 }); 56 return model.SymbolicExpressionTree; 66 57 } 67 58 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs
r14185 r15371 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 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 (added) merged: 15318-15319,15321,15353-15354
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14951 r15371 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, 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 alglib.ndimensional_rep xrep = (p, f, obj) => iterationCallback(p, f, obj); 212 213 213 214 try { 214 215 alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state); 215 216 alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations); 217 alglib.lsfitsetxrep(state, iterationCallback != null); 216 218 //alglib.lsfitsetgradientcheck(state, 0.001); 217 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null);219 alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, xrep, null); 218 220 alglib.lsfitresults(state, out retVal, out c, out rep); 219 221 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r14826 r15371 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;27 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 26 … … 32 30 public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 33 31 public SymbolicRegressionSolutionImpactValuesCalculator() { } 34 35 32 protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner) 36 33 : base(original, cloner) { } … … 38 35 return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner); 39 36 } 40 41 37 [StorableConstructor] 42 38 protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 43 39 44 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 45 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 46 double qualityForImpactsCalculation = double.NaN) { 40 protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 47 41 var regressionModel = (ISymbolicRegressionModel)model; 48 42 var regressionProblemData = (IRegressionProblemData)problemData; 49 50 var dataset = regressionProblemData.Dataset; 51 var targetValues = dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows); 52 53 if (double.IsNaN(qualityForImpactsCalculation)) 54 qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows); 55 56 var cloner = new Cloner(); 57 var tempModel = cloner.Clone(regressionModel); 58 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node); 59 60 var tempModelParentNode = tempModelNode.Parent; 61 int i = tempModelParentNode.IndexOfSubtree(tempModelNode); 62 63 double bestReplacementValue = 0.0; 64 double bestImpactValue = double.PositiveInfinity; 65 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize 66 // try the potentially reasonable replacement values and use the best one 67 foreach (var repValue in CalculateReplacementValues(node, regressionModel.SymbolicExpressionTree, regressionModel.Interpreter, regressionProblemData.Dataset, regressionProblemData.TrainingIndices)) { 68 69 tempModelParentNode.RemoveSubtree(i); 70 71 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue }; 72 73 tempModelParentNode.InsertSubtree(i, constantNode); 74 75 var estimatedValues = tempModel.GetEstimatedValues(dataset, rows); 76 OnlineCalculatorError errorState; 77 double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 78 if (errorState != OnlineCalculatorError.None) r = 0.0; 79 newQualityForImpactsCalculation = r * r; 80 81 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 82 if (impactValue < bestImpactValue) { 83 bestImpactValue = impactValue; 84 bestReplacementValue = repValue; 85 } 86 } 87 replacementValue = bestReplacementValue; 88 impactValue = bestImpactValue; 89 } 90 91 public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) { 92 var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 93 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 43 var estimatedValues = regressionModel.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 44 var targetValues = problemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows); 94 45 OnlineCalculatorError errorState; 95 46 var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis (added) merged: 15318
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views merged eligible /branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views merged eligible /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 10321-10322 /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5516-5520 /branches/Async/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6917-7005 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 4656-4721 /branches/CodeEditor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 11700-11806 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5815-6180 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5060 /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 10331-10358 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 11570-12508 /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6123-9799 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 11130-12721 /branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 12440-12877 /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 10202-10483 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5138-5162 /branches/NSGA-II Changes/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 12033-12122 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6828 /branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 8943-9078 /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 7787-8333 /branches/SlaveShutdown/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 8944-8956 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5370-5682 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 6829-6865 /branches/UnloadJobs/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 9168-9215 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 14232-14825
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r14826 r15371 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using HeuristicLab.Common;26 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 23 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 27 24 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; 28 25 29 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views { 30 27 public partial class InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView { 31 private readonly ConstantTreeNode constantNode;32 private readonly SymbolicExpressionTree tempTree;33 34 28 public new SymbolicTimeSeriesPrognosisSolution Content { 35 29 get { return (SymbolicTimeSeriesPrognosisSolution)base.Content; } … … 38 32 39 33 public InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView() 40 : base( ) {34 : base(new SymbolicRegressionSolutionImpactValuesCalculator()) { 41 35 InitializeComponent(); 42 36 this.Caption = "Interactive Time-Series Prognosis Solution Simplifier"; 43 44 constantNode = ((ConstantTreeNode)new Constant().CreateTreeNode());45 ISymbolicExpressionTreeNode root = new ProgramRootSymbol().CreateTreeNode();46 ISymbolicExpressionTreeNode start = new StartSymbol().CreateTreeNode();47 root.AddSubtree(start);48 tempTree = new SymbolicExpressionTree(root);49 }50 51 protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {52 var interpreter = Content.Model.Interpreter;53 var rows = Content.ProblemData.TrainingIndices;54 var dataset = Content.ProblemData.Dataset;55 var targetVariable = Content.ProblemData.TargetVariable;56 var targetValues = dataset.GetDoubleValues(targetVariable, rows);57 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();58 59 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();60 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();61 OnlineCalculatorError errorState;62 double originalR = OnlinePearsonsRCalculator.Calculate(targetValues, originalOutput, out errorState);63 if (errorState != OnlineCalculatorError.None) originalR = 0.0;64 65 foreach (ISymbolicExpressionTreeNode node in nodes) {66 var parent = node.Parent;67 constantNode.Value = CalculateReplacementValue(node, tree);68 ISymbolicExpressionTreeNode replacementNode = constantNode;69 SwitchNode(parent, node, replacementNode);70 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);71 double newR = OnlinePearsonsRCalculator.Calculate(targetValues, newOutput, out errorState);72 if (errorState != OnlineCalculatorError.None) newR = 0.0;73 74 // impact = 0 if no change75 // impact < 0 if new solution is better76 // impact > 0 if new solution is worse77 double impact = (originalR * originalR) - (newR * newR);78 impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value);79 SwitchNode(parent, replacementNode, node);80 }81 return impactAndReplacementValues;82 37 } 83 38 … … 87 42 Content.Model = model; 88 43 } 89 90 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {91 // remove old ADFs92 while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);93 // clone ADFs of source tree94 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {95 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());96 }97 var start = tempTree.Root.GetSubtree(0);98 while (start.SubtreeCount > 0) start.RemoveSubtree(0);99 start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());100 var interpreter = Content.Model.Interpreter;101 var rows = Content.ProblemData.TrainingIndices;102 var allPrognosedValues = interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows);103 104 return allPrognosedValues.Median();105 }106 107 108 private void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {109 for (int i = 0; i < root.SubtreeCount; i++) {110 if (root.GetSubtree(i) == oldBranch) {111 root.RemoveSubtree(i);112 root.InsertSubtree(i, newBranch);113 return;114 }115 }116 }117 118 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {119 throw new NotImplementedException();120 }121 44 } 122 45 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views (added) merged: 15318-15319,15321,15353,15356
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r14949 r15371 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 … … 36 38 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 37 39 40 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 42 private readonly IProgress progress = new Progress(); 43 38 44 private enum TreeState { Valid, Invalid } 39 45 private TreeState treeState; 40 46 41 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView( ) {47 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) { 42 48 InitializeComponent(); 43 49 foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); … … 45 51 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 46 52 this.Caption = "Interactive Solution Simplifier"; 53 this.impactCalculator = impactCalculator; 47 54 48 55 // initialize the tree modifier that will be used to perform edit operations over the tree … … 145 152 Content.ProblemDataChanged += Content_Changed; 146 153 treeChart.Repainted += treeChart_Repainted; 154 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); 147 155 } 148 156 protected override void DeregisterContentEvents() { … … 151 159 Content.ProblemDataChanged -= Content_Changed; 152 160 treeChart.Repainted -= treeChart_Repainted; 161 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); 153 162 } 154 163 … … 169 178 } 170 179 171 private void UpdateView() {180 private async void UpdateView() { 172 181 if (Content == null || Content.Model == null || Content.ProblemData == null) return; 173 182 var tree = Content.Model.SymbolicExpressionTree; 174 183 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 175 184 176 var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree); 185 progress.Start("Calculate Impact and Replacement Values ...", 0); 186 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 187 await Task.Delay(500); // wait for progressbar to finish animation 177 188 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 178 189 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { … … 180 191 } 181 192 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 193 progress.Finish(); 182 194 PaintNodeImpacts(); 183 195 } 184 196 185 protected abstract Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree); 197 protected virtual Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) { 198 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>(); 199 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 200 double impactValue, replacementValue, newQualityForImpactsCalculation; 201 impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation); 202 double newProgressValue = progress.ProgressValue + 1.0 / (tree.Length - 2); 203 progress.ProgressValue = Math.Min(newProgressValue, 1); 204 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue)); 205 } 206 return impactAndReplacementValues; 207 } 208 186 209 protected abstract void UpdateModel(ISymbolicExpressionTree tree); 210 211 protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) { 212 return model.SymbolicExpressionTree; 213 } 187 214 188 215 private static ConstantTreeNode MakeConstantTreeNode(double value) { … … 270 297 } 271 298 272 protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e); 299 private async void btnOptimizeConstants_Click(object sender, EventArgs e) { 300 progress.Start("Optimizing Constants ...", 0); 301 var newTree = await Task.Run(() => OptimizeConstants(Content.Model, Content.ProblemData, progress)); 302 await Task.Delay(500); // wait for progressbar to finish animation 303 UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed) 304 } 273 305 } 274 306 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r14826 r15371 32 32 public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : Item, ISymbolicDataAnalysisSolutionImpactValuesCalculator { 33 33 protected SymbolicDataAnalysisSolutionImpactValuesCalculator() { } 34 35 34 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(SymbolicDataAnalysisSolutionImpactValuesCalculator original, Cloner cloner) 36 35 : base(original, cloner) { } 37 36 [StorableConstructor] 38 37 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 39 public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN); 38 39 public virtual void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, 40 out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 41 double qualityForImpactsCalculation = double.NaN) { 42 if (double.IsNaN(qualityForImpactsCalculation)) 43 qualityForImpactsCalculation = CalculateQualityForImpacts(model, problemData, rows); 44 45 var cloner = new Cloner(); 46 var tempModel = cloner.Clone(model); 47 var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node); 48 49 var tempModelParentNode = tempModelNode.Parent; 50 int i = tempModelParentNode.IndexOfSubtree(tempModelNode); 51 52 double bestReplacementValue = 0.0; 53 double bestImpactValue = double.PositiveInfinity; 54 newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize 55 // try the potentially reasonable replacement values and use the best one 56 foreach (var repValue in CalculateReplacementValues(node, model.SymbolicExpressionTree, model.Interpreter, problemData.Dataset, problemData.TrainingIndices)) { 57 tempModelParentNode.RemoveSubtree(i); 58 59 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue }; 60 tempModelParentNode.InsertSubtree(i, constantNode); 61 62 newQualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows); 63 64 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 65 if (impactValue < bestImpactValue) { 66 bestImpactValue = impactValue; 67 bestReplacementValue = repValue; 68 } 69 } 70 71 replacementValue = bestReplacementValue; 72 impactValue = bestImpactValue; 73 } 74 75 protected abstract double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 40 76 41 77 protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 15318
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r14890 r15371 558 558 <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project> 559 559 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name> 560 <Private>False</Private> 560 561 </ProjectReference> 561 562 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 562 563 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> 563 564 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 565 <Private>False</Private> 564 566 </ProjectReference> 565 567 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
Note: See TracChangeset
for help on using the changeset viewer.