Changeset 7129 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
- Timestamp:
- 12/05/11 20:17:59 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r6808 r7129 50 50 51 51 protected override void UpdateModel(ISymbolicExpressionTree tree) { 52 var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter );52 var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter, Content.ProblemData.TargetVariables.ToArray()); 53 53 SymbolicTimeSeriesPrognosisModel.Scale(model, Content.ProblemData); 54 54 Content.Model = model; … … 67 67 var dataset = Content.ProblemData.Dataset; 68 68 var rows = Content.ProblemData.TrainingIndizes; 69 string targetVariable = Content.ProblemData.TargetVariable; 70 Dictionary<ISymbolicExpressionTreeNode, double> impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 71 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList(); 72 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows) 69 Dictionary<ISymbolicExpressionTreeNode, double> impactValues = 70 new Dictionary<ISymbolicExpressionTreeNode, double>(); 71 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1) 73 72 .ToArray(); 74 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 75 OnlineCalculatorError errorState; 76 double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState); 77 if (errorState != OnlineCalculatorError.None) originalR2 = 0.0; 73 int i = 0; 74 foreach (var targetVariable in Content.ProblemData.TargetVariables) { 75 List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(i).IterateNodesPostfix().ToList(); 76 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 77 OnlineCalculatorError errorState; 78 double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i).First()), out errorState); 79 if (errorState != OnlineCalculatorError.None) originalR2 = 0.0; 78 80 79 foreach (ISymbolicExpressionTreeNode node in nodes) {80 var parent = node.Parent;81 constantNode.Value = CalculateReplacementValue(node, tree);82 ISymbolicExpressionTreeNode replacementNode = constantNode;83 SwitchNode(parent, node, replacementNode);84 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);85 double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);86 if (errorState != OnlineCalculatorError.None) newR2 = 0.0;81 foreach (ISymbolicExpressionTreeNode node in nodes) { 82 var parent = node.Parent; 83 constantNode.Value = CalculateReplacementValue(node, tree); 84 ISymbolicExpressionTreeNode replacementNode = constantNode; 85 SwitchNode(parent, node, replacementNode); 86 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1); 87 double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput.Select(v => v.ElementAt(i).First()), out errorState); 88 if (errorState != OnlineCalculatorError.None) newR2 = 0.0; 87 89 88 // impact = 0 if no change 89 // impact < 0 if new solution is better 90 // impact > 0 if new solution is worse 91 impactValues[node] = originalR2 - newR2; 92 SwitchNode(parent, replacementNode, node); 90 // impact = 0 if no change 91 // impact < 0 if new solution is better 92 // impact > 0 if new solution is worse 93 impactValues[node] = originalR2 - newR2; 94 SwitchNode(parent, replacementNode, node); 95 } 96 i++; 93 97 } 94 98 return impactValues; … … 107 111 var interpreter = Content.Model.Interpreter; 108 112 var rows = Content.ProblemData.TrainingIndizes; 109 return interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, rows).Median(); 113 var allPrognosedValues = interpreter.GetSymbolicExpressionTreeValues(tempTree, Content.ProblemData.Dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1); 114 115 return allPrognosedValues.Select(x=>x.First().First()).Median(); 110 116 } 111 117
Note: See TracChangeset
for help on using the changeset viewer.