Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
- Timestamp:
- 06/28/18 11:13:37 (7 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.TimeSeriesPrognosis.Views
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/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/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 15318-15370 /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/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 12948-12950 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 14232-14825 /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views 13402-15674
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r12641 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. … … 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 84 39 protected override void UpdateModel(ISymbolicExpressionTree tree) { 85 var model = new SymbolicTimeSeriesPrognosisModel( tree, Content.Model.Interpreter);40 var model = new SymbolicTimeSeriesPrognosisModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter); 86 41 model.Scale(Content.ProblemData); 87 42 Content.Model = model; 88 43 } 89 90 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {91 var replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();92 foreach (var componentBranch in tree.Root.GetSubtree(0).Subtrees)93 foreach (ISymbolicExpressionTreeNode node in componentBranch.IterateNodesPrefix()) {94 replacementValues[node] = CalculateReplacementValue(node, tree);95 }96 return replacementValues;97 }98 99 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {100 var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree);101 return impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); // item1 of the tuple is the impact value102 }103 104 private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {105 // remove old ADFs106 while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);107 // clone ADFs of source tree108 for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {109 tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());110 }111 var start = tempTree.Root.GetSubtree(0);112 while (start.SubtreeCount > 0) start.RemoveSubtree(0);113 start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());114 var interpreter = Content.Model.Interpreter;115 var rows = Content.ProblemData.TrainingIndices;116 var allPrognosedValues = interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows);117 118 return allPrognosedValues.Median();119 }120 121 122 private void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {123 for (int i = 0; i < root.SubtreeCount; i++) {124 if (root.GetSubtree(i) == oldBranch) {125 root.RemoveSubtree(i);126 root.InsertSubtree(i, newBranch);127 return;128 }129 }130 }131 132 protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {133 throw new NotImplementedException();134 }135 44 } 136 45 }
Note: See TracChangeset
for help on using the changeset viewer.