Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r12720 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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 44 40 protected override void UpdateModel(ISymbolicExpressionTree tree) { 45 var model = new SymbolicRegressionModel( tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);41 var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit); 46 42 model.Scale(Content.ProblemData); 47 43 Content.Model = model; 48 44 } 49 45 50 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) { 51 return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary( 52 n => n, 53 n => calculator.CalculateReplacementValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices) 54 ); 55 } 56 57 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) { 58 var values = CalculateImpactAndReplacementValues(tree); 59 return values.ToDictionary(x => x.Key, x => x.Value.Item1); 60 } 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) { 46 protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) { 47 const int constOptIterations = 50; 48 var regressionProblemData = Content.ProblemData; 73 49 var model = Content.Model; 74 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices, 75 applyLinearScaling: true, maxIterations: 50, upperEstimationLimit: model.UpperEstimationLimit, lowerEstimationLimit: model.LowerEstimationLimit); 76 UpdateModel(Content.Model.SymbolicExpressionTree); 50 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, tree, regressionProblemData, regressionProblemData.TrainingIndices, 51 applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.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 tree; 77 57 } 78 58 }
Note: See TracChangeset
for help on using the changeset viewer.