Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15371


Ignore:
Timestamp:
09/19/17 10:49:02 (7 years ago)
Author:
pfleck
Message:

#1666: Merged into trunk

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.WindowsFormsmergedeligible
      /branches/crossvalidation-2434/HeuristicLab.MainForm.WindowsFormsmergedeligible
      /stable/HeuristicLab.MainForm.WindowsFormsmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.MainForm.WindowsForms10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.MainForm.WindowsForms5516-5520
      /branches/Async/HeuristicLab.MainForm.WindowsForms13329-15286
      /branches/Benchmarking/sources/HeuristicLab.MainForm.WindowsForms6917-7005
      /branches/CloningRefactoring/HeuristicLab.MainForm.WindowsForms4656-4721
      /branches/CodeEditor/HeuristicLab.MainForm.WindowsForms11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.MainForm.WindowsForms5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.MainForm.WindowsForms5815-6180
      /branches/DataAnalysis/HeuristicLab.MainForm.WindowsForms4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.MainForm.WindowsForms10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.MainForm.WindowsForms6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.MainForm.WindowsForms5060
      /branches/HLScript/HeuristicLab.MainForm.WindowsForms10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.MainForm.WindowsForms11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.MainForm.WindowsForms6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.MainForm.WindowsForms11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.MainForm.WindowsForms12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.MainForm.WindowsForms10202-10483
      /branches/NET40/sources/HeuristicLab.MainForm.WindowsForms5138-5162
      /branches/NSGA-II Changes/HeuristicLab.MainForm.WindowsForms12033-12122
      /branches/ParallelEngine/HeuristicLab.MainForm.WindowsForms5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.MainForm.WindowsForms7568-7810
      /branches/QAPAlgorithms/HeuristicLab.MainForm.WindowsForms6350-6627
      /branches/Restructure trunk solution/HeuristicLab.MainForm.WindowsForms6828
      /branches/RuntimeOptimizer/HeuristicLab.MainForm.WindowsForms8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.MainForm.WindowsForms7787-8333
      /branches/SlaveShutdown/HeuristicLab.MainForm.WindowsForms8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.MainForm.WindowsForms10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.MainForm.WindowsForms5370-5682
      /branches/Trunk/HeuristicLab.MainForm.WindowsForms6829-6865
      /branches/UnloadJobs/HeuristicLab.MainForm.WindowsForms9168-9215
      /branches/VNS/HeuristicLab.MainForm.WindowsForms5594-5752
      /branches/histogram/HeuristicLab.MainForm.WindowsForms5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.MainForm.WindowsForms14232-14825
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r14297 r15371  
    154154        if (content != null) {
    155155          double progressValue = content.ProgressValue;
    156           if (progressValue <= 0.0 || progressValue > 1.0) {
     156          if (progressValue < 0.0 || progressValue > 1.0) {
    157157            progressBar.Style = ProgressBarStyle.Marquee;
    158158          } else {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r14185 r15371  
    230230    }
    231231
    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 {
    233233      if (content == null) throw new ArgumentNullException("Content cannot be null.");
    234234      if (!reuseExistingView) return ShowContent(content);
     
    353353    /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content.
    354354    /// </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) {
    356356      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);
    358358        return result;
    359359      }
     
    371371        contentViews = contentViews.Where(v => v.Content == content);
    372372
    373       var progress = new Progress(progressMessage, ProgressState.Started);
     373      var progress = new Progress();
     374      progress.Start(progressMessage, progressValue);
    374375      foreach (var contentView in contentViews) {
    375376        progressViews.Add(new ProgressView(contentView, progress));
     
    384385    /// </summary>
    385386    public IProgress AddOperationProgressToView(Control control, string progressMessage) {
    386       var progress = new Progress(progressMessage, ProgressState.Started);
     387      var progress = new Progress();
     388      progress.Start(progressMessage);
    387389      AddOperationProgressToView(control, progress);
    388390      return progress;
  • trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs

    r14185 r15371  
    6464    /// </summary>
    6565    void Start();
    66 
    6766    void Start(string status);
     67    void Start(string status, double progressValue);
    6868
    6969    /// <summary>
  • trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs

    r14185 r15371  
    7272      canBeCanceled = false;
    7373    }
    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     }
    8374
    8475    public void Cancel() {
     
    9384
    9485    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) {
    9692      ProgressState = ProgressState.Started;
    97     }
    98 
    99     public void Start(string status) {
    100       Start();
    101       Status = status;
     93      Status = status ?? string.Empty;
     94      ProgressValue = progressValue;
    10295    }
    10396
  • trunk/sources/HeuristicLab.Problems.DataAnalysis

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicClassificationSolutionSimplifierViewBase.cs

    r14826 r15371  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2522using HeuristicLab.Common;
    2623using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2926namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views {
    3027  public abstract partial class InteractiveSymbolicClassificationSolutionSimplifierViewBase : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
    31     private readonly SymbolicClassificationSolutionImpactValuesCalculator calculator;
    32 
    3328    public new ISymbolicClassificationSolution Content {
    3429      get { return (ISymbolicClassificationSolution)base.Content; }
     
    3631    }
    3732
    38     public InteractiveSymbolicClassificationSolutionSimplifierViewBase()
    39       : base() {
     33    protected InteractiveSymbolicClassificationSolutionSimplifierViewBase()
     34      : base(new SymbolicClassificationSolutionImpactValuesCalculator()) {
    4035      InitializeComponent();
    4136      this.Caption = "Interactive Classification Solution Simplifier";
    42 
    43       calculator = new SymbolicClassificationSolutionImpactValuesCalculator();
    4437    }
    4538
     
    5952      return model;
    6053    }
    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     }
    7554  }
    7655}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs

    r14826 r15371  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
     
    4038    protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    4139
    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) {
    4741      var classificationModel = (ISymbolicClassificationModel)model;
    4842      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; // initialize
    63       // try the potentially reasonable replacement values and use the best one
    64       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) {
    9043      OnlineCalculatorError errorState;
    9144      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);
    9447      var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState);
    9548      if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0;
    96 
    9749      return qualityForImpactsCalculation;
    9850    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r14826 r15371  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2523using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     24using HeuristicLab.MainForm;
    2625using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2726
    2827namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
    2928  public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
    30     private readonly SymbolicRegressionSolutionImpactValuesCalculator calculator;
    31 
    3229    public new SymbolicRegressionSolution Content {
    3330      get { return (SymbolicRegressionSolution)base.Content; }
     
    3633
    3734    public InteractiveSymbolicRegressionSolutionSimplifierView()
    38       : base() {
     35      : base(new SymbolicRegressionSolutionImpactValuesCalculator()) {
    3936      InitializeComponent();
    4037      this.Caption = "Interactive Regression Solution Simplifier";
    41       calculator = new SymbolicRegressionSolutionImpactValuesCalculator();
    4238    }
    4339
     
    4844    }
    4945
    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;
    6657    }
    6758  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs

    r14185 r15371  
    5151    private void btn_SimplifyModel_Click(object sender, EventArgs e) {
    5252      var view = new InteractiveSymbolicRegressionSolutionSimplifierView();
     53      view.Show(); // open view first that a progress can be displayed when setting the content
    5354      view.Content = (SymbolicRegressionSolution)this.Content.Clone();
    54       view.Show();
    5555    }
    5656
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r14951 r15371  
    156156      int maxIterations, bool updateVariableWeights = true,
    157157      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue,
    158       bool updateConstantsInTree = true) {
     158      bool updateConstantsInTree = true, Action<double[], double, object> iterationCallback = null) {
    159159
    160160      // numeric constants in the tree become variables for constant opt
     
    210210      alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(func);
    211211      alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(func_grad);
     212      alglib.ndimensional_rep xrep = (p, f, obj) => iterationCallback(p, f, obj);
    212213
    213214      try {
    214215        alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state);
    215216        alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations);
     217        alglib.lsfitsetxrep(state, iterationCallback != null);
    216218        //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);
    218220        alglib.lsfitresults(state, out retVal, out c, out rep);
    219221      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r14826 r15371  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
     
    3230  public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
    3331    public SymbolicRegressionSolutionImpactValuesCalculator() { }
    34 
    3532    protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner)
    3633      : base(original, cloner) { }
     
    3835      return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner);
    3936    }
    40 
    4137    [StorableConstructor]
    4238    protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    4339
    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) {
    4741      var regressionModel = (ISymbolicRegressionModel)model;
    4842      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);
    9445      OnlineCalculatorError errorState;
    9546      var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Viewsmergedeligible
      /branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Viewsmergedeligible
      /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Viewsmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5516-5520
      /branches/Async/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views13329-15286
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views4656-4721
      /branches/CodeEditor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5060
      /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views12033-12122
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6828
      /branches/RuntimeOptimizer/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views7787-8333
      /branches/SlaveShutdown/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views6829-6865
      /branches/UnloadJobs/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views9168-9215
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views14232-14825
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r14826 r15371  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using HeuristicLab.Common;
    2622using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     23using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2724using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
    2825
    2926namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views {
    3027  public partial class InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
    31     private readonly ConstantTreeNode constantNode;
    32     private readonly SymbolicExpressionTree tempTree;
    33 
    3428    public new SymbolicTimeSeriesPrognosisSolution Content {
    3529      get { return (SymbolicTimeSeriesPrognosisSolution)base.Content; }
     
    3832
    3933    public InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView()
    40       : base() {
     34      : base(new SymbolicRegressionSolutionImpactValuesCalculator()) {
    4135      InitializeComponent();
    4236      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 change
    75         // impact < 0 if new solution is better
    76         // impact > 0 if new solution is worse
    77         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;
    8237    }
    8338
     
    8742      Content.Model = model;
    8843    }
    89 
    90     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
    91       // remove old ADFs
    92       while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);
    93       // clone ADFs of source tree
    94       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     }
    12144  }
    12245}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r14949 r15371  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading.Tasks;
    2627using System.Windows.Forms;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2930using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
     31using HeuristicLab.MainForm;
    3032using HeuristicLab.MainForm.WindowsForms;
    3133
     
    3638    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
    3739
     40    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
     41
     42    private readonly IProgress progress = new Progress();
     43
    3844    private enum TreeState { Valid, Invalid }
    3945    private TreeState treeState;
    4046
    41     protected InteractiveSymbolicDataAnalysisSolutionSimplifierView() {
     47    protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) {
    4248      InitializeComponent();
    4349      foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     
    4551      nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4652      this.Caption = "Interactive Solution Simplifier";
     53      this.impactCalculator = impactCalculator;
    4754
    4855      // initialize the tree modifier that will be used to perform edit operations over the tree
     
    145152      Content.ProblemDataChanged += Content_Changed;
    146153      treeChart.Repainted += treeChart_Repainted;
     154      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress);
    147155    }
    148156    protected override void DeregisterContentEvents() {
     
    151159      Content.ProblemDataChanged -= Content_Changed;
    152160      treeChart.Repainted -= treeChart_Repainted;
     161      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false);
    153162    }
    154163
     
    169178    }
    170179
    171     private void UpdateView() {
     180    private async void UpdateView() {
    172181      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
    173182      var tree = Content.Model.SymbolicExpressionTree;
    174183      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    175184
    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
    177188      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    178189      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     
    180191      }
    181192      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
     193      progress.Finish();
    182194      PaintNodeImpacts();
    183195    }
    184196
    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
    186209    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
     210
     211    protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) {
     212      return model.SymbolicExpressionTree;
     213    }
    187214
    188215    private static ConstantTreeNode MakeConstantTreeNode(double value) {
     
    270297    }
    271298
    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    }
    273305  }
    274306}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r14826 r15371  
    3232  public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : Item, ISymbolicDataAnalysisSolutionImpactValuesCalculator {
    3333    protected SymbolicDataAnalysisSolutionImpactValuesCalculator() { }
    34 
    3534    protected SymbolicDataAnalysisSolutionImpactValuesCalculator(SymbolicDataAnalysisSolutionImpactValuesCalculator original, Cloner cloner)
    3635      : base(original, cloner) { }
    3736    [StorableConstructor]
    3837    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);
    4076
    4177    protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r14890 r15371  
    558558      <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project>
    559559      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name>
     560      <Private>False</Private>
    560561    </ProjectReference>
    561562    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    562563      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
    563564      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
     565      <Private>False</Private>
    564566    </ProjectReference>
    565567    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
Note: See TracChangeset for help on using the changeset viewer.