Changeset 17687 for branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
- Timestamp:
- 07/19/20 19:07:40 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r9456 r17687 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System.Linq; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 28 using HeuristicLab.Optimization; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 32 /// Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity 32 33 /// </summary> 33 [Storable Class]34 [StorableType("88E56AF9-AD72-47E4-A613-8875703BD927")] 34 35 [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")] 35 36 public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution { … … 46 47 private const string TestNaNEvaluationsResultName = "Test NaN Evaluations"; 47 48 49 private const string ModelBoundsResultName = "Model Bounds"; 50 48 51 public new ISymbolicRegressionModel Model { 49 52 get { return (ISymbolicRegressionModel)base.Model; } … … 95 98 } 96 99 100 public IntervalCollection ModelBoundsCollection { 101 get { 102 if (!ContainsKey(ModelBoundsResultName)) return null; 103 return (IntervalCollection)this[ModelBoundsResultName].Value; 104 } 105 private set { 106 if (ContainsKey(ModelBoundsResultName)) { 107 this[ModelBoundsResultName].Value = value; 108 } else { 109 Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", value)); 110 } 111 112 } 113 } 114 115 116 97 117 [StorableConstructor] 98 private SymbolicRegressionSolution( bool deserializing) : base(deserializing) { }118 private SymbolicRegressionSolution(StorableConstructorFlag _) : base(_) { } 99 119 private SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner) 100 120 : base(original, cloner) { … … 102 122 public SymbolicRegressionSolution(ISymbolicRegressionModel model, IRegressionProblemData problemData) 103 123 : base(model, problemData) { 124 foreach (var node in model.SymbolicExpressionTree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>()) 125 node.SetGrammar(null); 126 104 127 Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue())); 105 128 Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue())); … … 114 137 estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue())); 115 138 Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults)); 139 140 if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree)) 141 Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection())); 116 142 117 143 RecalculateResults(); … … 136 162 CalculateResults(); 137 163 } 164 165 if (!ContainsKey(ModelBoundsResultName)) { 166 if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree)) { 167 Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection())); 168 CalculateResults(); 169 } 170 } 138 171 } 139 172 … … 156 189 TrainingNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TrainingIndices).Count(double.IsNaN); 157 190 TestNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TestIndices).Count(double.IsNaN); 191 192 //Check if the tree contains unknown symbols for the interval calculation 193 if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree)) 194 ModelBoundsCollection = CalculateModelIntervals(this); 195 } 196 197 private static IntervalCollection CalculateModelIntervals(ISymbolicRegressionSolution solution) { 198 var intervalEvaluation = new IntervalCollection(); 199 var interpreter = new IntervalInterpreter(); 200 var problemData = solution.ProblemData; 201 var model = solution.Model; 202 var variableRanges = problemData.VariableRanges.GetReadonlyDictionary(); 203 204 intervalEvaluation.AddInterval($"Target {problemData.TargetVariable}", new Interval(variableRanges[problemData.TargetVariable].LowerBound, variableRanges[problemData.TargetVariable].UpperBound)); 205 intervalEvaluation.AddInterval("Model", interpreter.GetSymbolicExpressionTreeInterval(model.SymbolicExpressionTree, variableRanges)); 206 207 if (DerivativeCalculator.IsCompatible(model.SymbolicExpressionTree)) { 208 foreach (var inputVariable in model.VariablesUsedForPrediction.OrderBy(v => v, new NaturalStringComparer())) { 209 var derivedModel = DerivativeCalculator.Derive(model.SymbolicExpressionTree, inputVariable); 210 var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derivedModel, variableRanges); 211 212 intervalEvaluation.AddInterval(" ∂f/∂" + inputVariable, new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound)); 213 } 214 } 215 216 return intervalEvaluation; 158 217 } 159 218 }
Note: See TracChangeset
for help on using the changeset viewer.