- Timestamp:
- 09/29/15 16:49:13 (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
r12012 r12973 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 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 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); 60 75 QualityParameter.ActualValue = new DoubleValue(quality); 61 76 … … 66 81 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 67 82 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) { 68 87 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 69 88 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs
r12012 r12973 50 50 IEnumerable<int> rows = GenerateRowsToEvaluate(); 51 51 52 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows); 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); 53 68 QualityParameter.ActualValue = new DoubleValue(quality); 54 69 … … 59 74 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 60 75 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) { 61 80 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 62 81 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r12012 r12973 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; … … 30 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 31 28 [StorableClass] 32 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 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 33 38 [StorableConstructor] 34 39 protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 35 40 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 36 protected SymbolicRegressionSingleObjectiveEvaluator(): base() {} 41 42 protected SymbolicRegressionSingleObjectiveEvaluator() : base() { 43 Parameters.Add(new FixedValueParameter<BoolValue>(SaveEstimatedValuesToScopeParameterName, new BoolValue(false))); 44 SaveEstimatedValuesToScopeParameter.Hidden = true; 45 } 37 46 } 38 47 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r12012 r12973 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 46 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 48 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 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); 49 65 QualityParameter.ActualValue = new DoubleValue(quality); 50 66 … … 55 71 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 72 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) { 57 77 OnlineCalculatorError errorState; 58 78 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r12012 r12973 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 46 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 48 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 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); 49 65 QualityParameter.ActualValue = new DoubleValue(quality); 50 66 … … 55 71 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 72 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) { 57 77 OnlineCalculatorError errorState; 58 78 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r12012 r12973 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 46 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 47 48 48 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 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); 49 65 QualityParameter.ActualValue = new DoubleValue(quality); 50 66 … … 55 71 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 72 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) { 57 77 OnlineCalculatorError errorState; 58 78 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r12641 r12973 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 48 49 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 50 50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 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); 51 67 QualityParameter.ActualValue = new DoubleValue(quality); 52 68 … … 57 73 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 58 74 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) { 59 79 OnlineCalculatorError errorState; 60 80 … … 70 90 } 71 91 if (errorState != OnlineCalculatorError.None) return double.NaN; 72 return r *r;92 return r * r; 73 93 } 74 94 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPhenotypicDiversityAnalyzer.cs
r12422 r12973 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Analysis; 25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;29 26 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters;31 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 28 … … 34 30 [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 35 31 [StorableClass] 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 32 public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer { 64 33 public SymbolicRegressionPhenotypicDiversityAnalyzer(IEnumerable<ISolutionSimilarityCalculator> validSimilarityCalculators) 65 34 : base(validSimilarityCalculators) { 66 #region add parameters67 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 #endregion73 35 74 36 UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter"; … … 88 50 : base(original, cloner) { 89 51 } 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 }111 52 } 112 53 }
Note: See TracChangeset
for help on using the changeset viewer.