Changeset 12977
- Timestamp:
- 10/01/15 00:12:46 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionLogResidualEvaluator.cs
r12973 r12977 30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 32 [Item("Log Residual Evaluator", "Evaluator for symbolic regression models that calculates the mean of logarithmic absolute residuals avg(log( 1 + abs(y' - y)))" + 32 [Item("Log Residual Evaluator", "Evaluator for symbolic regression models that calculates the mean of logarithmic absolute residuals avg(log( 1 + abs(y' - y)))" + 33 33 "This evaluator does not perform linear scaling!" + 34 34 "This evaluator can be useful if the modeled function contains discontinuities (e.g. 1/x). " + … … 57 57 IEnumerable<int> rows = GenerateRowsToEvaluate(); 58 58 59 var problemData = ProblemDataParameter.ActualValue; 60 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 61 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 62 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 63 var estimationLimits = EstimationLimitsParameter.ActualValue; 64 65 if (SaveEstimatedValuesToScope) { 66 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 67 var scope = ExecutionContext.Scope; 68 if (scope.Variables.ContainsKey("EstimatedValues")) 69 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 70 else 71 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 72 } 73 74 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper); 59 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 75 60 QualityParameter.ActualValue = new DoubleValue(quality); 76 61 … … 81 66 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 82 67 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 83 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit);84 }85 86 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit) {87 68 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 88 69 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs
r12973 r12977 50 50 IEnumerable<int> rows = GenerateRowsToEvaluate(); 51 51 52 var problemData = ProblemDataParameter.ActualValue; 53 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 54 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 55 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 56 var estimationLimits = EstimationLimitsParameter.ActualValue; 57 58 if (SaveEstimatedValuesToScope) { 59 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 60 var scope = ExecutionContext.Scope; 61 if (scope.Variables.ContainsKey("EstimatedValues")) 62 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 63 else 64 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 65 } 66 67 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper); 52 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 68 53 QualityParameter.ActualValue = new DoubleValue(quality); 69 54 … … 74 59 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 75 60 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 76 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit);77 }78 79 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit) {80 61 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 81 62 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r12973 r12977 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; … … 27 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 31 [StorableClass] 29 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 30 private const string SaveEstimatedValuesToScopeParameterName = "SaveEstimatedValuesToScope"; 31 32 public IFixedValueParameter<BoolValue> SaveEstimatedValuesToScopeParameter { 33 get { return (IFixedValueParameter<BoolValue>)Parameters[SaveEstimatedValuesToScopeParameterName]; } 34 } 35 36 public bool SaveEstimatedValuesToScope { get { return SaveEstimatedValuesToScopeParameter.Value.Value; } } 37 32 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 38 33 [StorableConstructor] 39 34 protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 40 35 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 41 42 protected SymbolicRegressionSingleObjectiveEvaluator() : base() { 43 Parameters.Add(new FixedValueParameter<BoolValue>(SaveEstimatedValuesToScopeParameterName, new BoolValue(false))); 44 SaveEstimatedValuesToScopeParameter.Hidden = true; 45 } 36 protected SymbolicRegressionSingleObjectiveEvaluator(): base() {} 46 37 } 47 38 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r12973 r12977 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 47 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 47 49 var problemData = ProblemDataParameter.ActualValue; 50 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 51 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 52 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 53 var estimationLimits = EstimationLimitsParameter.ActualValue; 54 55 if (SaveEstimatedValuesToScope) { 56 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 57 var scope = ExecutionContext.Scope; 58 if (scope.Variables.ContainsKey("EstimatedValues")) 59 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 60 else 61 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 62 } 63 64 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 65 49 QualityParameter.ActualValue = new DoubleValue(quality); 66 50 … … 71 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 72 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 73 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);74 }75 76 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {77 57 OnlineCalculatorError errorState; 78 58 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r12973 r12977 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 47 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 47 49 var problemData = ProblemDataParameter.ActualValue; 50 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 51 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 52 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 53 var estimationLimits = EstimationLimitsParameter.ActualValue; 54 55 if (SaveEstimatedValuesToScope) { 56 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 57 var scope = ExecutionContext.Scope; 58 if (scope.Variables.ContainsKey("EstimatedValues")) 59 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 60 else 61 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 62 } 63 64 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 65 49 QualityParameter.ActualValue = new DoubleValue(quality); 66 50 … … 71 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 72 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 73 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);74 }75 76 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {77 57 OnlineCalculatorError errorState; 78 58 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r12973 r12977 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 47 46 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 47 49 var problemData = ProblemDataParameter.ActualValue; 50 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 51 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 52 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 53 var estimationLimits = EstimationLimitsParameter.ActualValue; 54 55 if (SaveEstimatedValuesToScope) { 56 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 57 var scope = ExecutionContext.Scope; 58 if (scope.Variables.ContainsKey("EstimatedValues")) 59 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 60 else 61 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 62 } 63 64 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value); 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 65 49 QualityParameter.ActualValue = new DoubleValue(quality); 66 50 … … 71 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 72 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 73 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);74 }75 76 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {77 57 OnlineCalculatorError errorState; 78 58 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r12973 r12977 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 49 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 50 49 51 var problemData = ProblemDataParameter.ActualValue; 52 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 53 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray(); 54 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 55 var estimationLimits = EstimationLimitsParameter.ActualValue; 56 57 if (SaveEstimatedValuesToScope) { 58 var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 59 var scope = ExecutionContext.Scope; 60 if (scope.Variables.ContainsKey("EstimatedValues")) 61 scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues); 62 else 63 scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues))); 64 } 65 66 double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value); 50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 67 51 QualityParameter.ActualValue = new DoubleValue(quality); 68 52 … … 73 57 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 74 58 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 75 return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);76 }77 78 private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {79 59 OnlineCalculatorError errorState; 80 60 … … 90 70 } 91 71 if (errorState != OnlineCalculatorError.None) return double.NaN; 92 return r *r;72 return r*r; 93 73 } 94 74 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPhenotypicDiversityAnalyzer.cs
r12973 r12977 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Analysis; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 27 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 32 … … 30 34 [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 31 35 [StorableClass] 32 public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer { 36 public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer, 37 ISymbolicDataAnalysisBoundedOperator, ISymbolicDataAnalysisInterpreterOperator, ISymbolicExpressionTreeAnalyzer { 38 #region parameter names 39 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 40 private const string EvaluatedValuesParameterName = "EstimatedValues"; 41 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 42 private const string ProblemDataParameterName = "ProblemData"; 43 private const string EstimationLimitsParameterName = "EstimationLimits"; 44 #endregion 45 46 #region parameter properties 47 public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 48 get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 49 } 50 private IScopeTreeLookupParameter<DoubleArray> EvaluatedValuesParameter { 51 get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters[EvaluatedValuesParameterName]; } 52 } 53 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 54 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 55 } 56 public IValueLookupParameter<IRegressionProblemData> ProblemDataParameter { 57 get { return (IValueLookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; } 58 } 59 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 60 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 61 } 62 #endregion 63 33 64 public SymbolicRegressionPhenotypicDiversityAnalyzer(IEnumerable<ISolutionSimilarityCalculator> validSimilarityCalculators) 34 65 : base(validSimilarityCalculators) { 66 #region add parameters 67 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees.")); 68 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(EvaluatedValuesParameterName, "Intermediate estimated values to be saved in the scopes.")); 69 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree.")); 70 Parameters.Add(new ValueLookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 71 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); 72 #endregion 35 73 36 74 UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter"; … … 50 88 : base(original, cloner) { 51 89 } 90 91 public override IOperation Apply() { 92 int updateInterval = UpdateIntervalParameter.Value.Value; 93 IntValue updateCounter = UpdateCounterParameter.ActualValue; 94 95 if (updateCounter == null) { 96 updateCounter = new IntValue(updateInterval); 97 UpdateCounterParameter.ActualValue = updateCounter; 98 } 99 100 if (updateCounter.Value == updateInterval) { 101 var trees = SymbolicExpressionTreeParameter.ActualValue; 102 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 103 var ds = ProblemDataParameter.ActualValue.Dataset; 104 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 105 106 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 107 EvaluatedValuesParameter.ActualValue = evaluatedValues; 108 } 109 return base.Apply(); 110 } 52 111 } 53 112 }
Note: See TracChangeset
for help on using the changeset viewer.