Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 20 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged eligible /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged eligible /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged eligible /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6917-7005 /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 6917-7005 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 4656-4721 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5471-5473 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5471-5473 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5815-6180 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5815-6180 /branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 10750-13239 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 4458-4459,4462,4464 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10085-11101 /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6284-6795 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5060 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5060 /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10331-10358 /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 10331-10358 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 11570-12508 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 11130-12721 /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 8388-8942 /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 8388-8942 /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10202-10483 /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 10202-10483 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5138-5162 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5138-5162 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5175-5192 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 7748-7810 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 7748-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6350-6627 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6828 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10204-10479 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5370-5682 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5370-5682 /branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 12029-12100 /branches/SymbolicExpressionTreeEncoding/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 12336-12421 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6829-6865 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 6829-6865 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5594-5752 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5959-6341 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r12103 r14029 123 123 </ItemGroup> 124 124 <ItemGroup> 125 <Compile Include="MultiObjective\PearsonRSquaredNestedTreeSizeEvaluator.cs" /> 126 <Compile Include="MultiObjective\PearsonRSquaredNumberOfVariablesEvaluator.cs" /> 127 <Compile Include="MultiObjective\PearsonRSquaredTreeComplexityEvaluator.cs" /> 125 128 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 126 129 <Compile Include="Plugin.cs" /> -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveEvaluator.cs
r12012 r14029 22 22 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 24 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 25 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [StorableClass] 26 31 public abstract class SymbolicRegressionMultiObjectiveEvaluator : SymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionMultiObjectiveEvaluator { 32 private const string DecimalPlacesParameterName = "Decimal Places"; 33 private const string UseConstantOptimizationParameterName = "Use constant optimization"; 34 private const string ConstantOptimizationIterationsParameterName = "Constant optimization iterations"; 35 36 private const string ConstantOptimizationUpdateVariableWeightsParameterName = 37 "Constant optimization update variable weights"; 38 39 public IFixedValueParameter<IntValue> DecimalPlacesParameter { 40 get { return (IFixedValueParameter<IntValue>)Parameters[DecimalPlacesParameterName]; } 41 } 42 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 43 get { return (IFixedValueParameter<BoolValue>)Parameters[UseConstantOptimizationParameterName]; } 44 } 45 46 public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter { 47 get { return (IFixedValueParameter<IntValue>)Parameters[ConstantOptimizationIterationsParameterName]; } 48 } 49 50 public IFixedValueParameter<BoolValue> ConstantOptimizationUpdateVariableWeightsParameter { 51 get { return (IFixedValueParameter<BoolValue>)Parameters[ConstantOptimizationUpdateVariableWeightsParameterName]; } 52 } 53 54 public int DecimalPlaces { 55 get { return DecimalPlacesParameter.Value.Value; } 56 set { DecimalPlacesParameter.Value.Value = value; } 57 } 58 public bool UseConstantOptimization { 59 get { return UseConstantOptimizationParameter.Value.Value; } 60 set { UseConstantOptimizationParameter.Value.Value = value; } 61 } 62 public int ConstantOptimizationIterations { 63 get { return ConstantOptimizationIterationsParameter.Value.Value; } 64 set { ConstantOptimizationIterationsParameter.Value.Value = value; } 65 } 66 public bool ConstantOptimizationUpdateVariableWeights { 67 get { return ConstantOptimizationUpdateVariableWeightsParameter.Value.Value; } 68 set { ConstantOptimizationUpdateVariableWeightsParameter.Value.Value = value; } 69 } 70 27 71 [StorableConstructor] 28 72 protected SymbolicRegressionMultiObjectiveEvaluator(bool deserializing) : base(deserializing) { } … … 31 75 } 32 76 33 protected SymbolicRegressionMultiObjectiveEvaluator() : base() { } 77 protected SymbolicRegressionMultiObjectiveEvaluator() 78 : base() { 79 Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(5)) { Hidden = true }); 80 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false))); 81 Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "The number of iterations constant optimization should be applied.", new IntValue(5))); 82 Parameters.Add(new FixedValueParameter<BoolValue>(ConstantOptimizationUpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized during constant optimization.", new BoolValue(true)) { Hidden = true }); 83 } 84 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserialization() { 87 if (!Parameters.ContainsKey(UseConstantOptimizationParameterName)) { 88 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false))); 89 } 90 if (!Parameters.ContainsKey(DecimalPlacesParameterName)) { 91 Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(-1)) { Hidden = true }); 92 } 93 if (!Parameters.ContainsKey(ConstantOptimizationIterationsParameterName)) { 94 Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "The number of iterations constant optimization should be applied.", new IntValue(5))); 95 } 96 if (!Parameters.ContainsKey(ConstantOptimizationUpdateVariableWeightsParameterName)) { 97 Parameters.Add(new FixedValueParameter<BoolValue>(ConstantOptimizationUpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized during constant optimization.", new BoolValue(true))); 98 } 99 } 34 100 } 35 101 } -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r12012 r14029 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 47 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 49 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 var problemData = ProblemDataParameter.ActualValue; 51 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 52 var estimationLimits = EstimationLimitsParameter.ActualValue; 53 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 54 55 if (UseConstantOptimization) { 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper); 57 } 58 59 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 50 60 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 61 return base.InstrumentedApply(); 52 62 } 53 63 54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 OnlineCalculatorError errorState; 64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 65 var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, 66 upperEstimationLimit, problemData, rows, applyLinearScaling); 58 67 59 double mse; 60 if (applyLinearScaling) { 61 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows); 63 errorState = mseCalculator.ErrorState; 64 mse = mseCalculator.MeanSquaredError; 65 } else { 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 } 69 if (errorState != OnlineCalculatorError.None) mse = double.NaN; 68 if (decimalPlaces >= 0) 69 mse = Math.Round(mse, decimalPlaces); 70 70 71 return new double[2] { mse, solution.Length }; 71 72 } … … 76 77 ApplyLinearScalingParameter.ExecutionContext = context; 77 78 78 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 79 80 80 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r12641 r14029 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 47 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 49 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 var problemData = ProblemDataParameter.ActualValue; 51 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 52 var estimationLimits = EstimationLimitsParameter.ActualValue; 53 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 54 55 if (UseConstantOptimization) { 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper); 57 } 58 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 50 59 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 60 return base.InstrumentedApply(); 52 61 } 53 62 54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 OnlineCalculatorError errorState; 58 59 double r; 60 if (applyLinearScaling) { 61 var rCalculator = new OnlinePearsonsRCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 63 errorState = rCalculator.ErrorState; 64 r = rCalculator.R; 65 } else { 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 } 69 70 if (errorState != OnlineCalculatorError.None) r = double.NaN; 71 return new double[2] { r*r, solution.Length }; 63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 65 if (decimalPlaces >= 0) 66 r2 = Math.Round(r2, decimalPlaces); 67 return new double[2] { r2, solution.Length }; 72 68 } 73 69 … … 77 73 ApplyLinearScalingParameter.ExecutionContext = context; 78 74 79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );75 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 80 76 81 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r14029 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 24 using HeuristicLab.Analysis; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 24 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 25 30 using HeuristicLab.Parameters; 26 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 38 43 private const string EstimationLimitsParameterName = "EstimationLimits"; 44 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 45 private const string ValidationPartitionParameterName = "ValidationPartition"; 46 39 47 #region parameter properties 40 48 public ILookupParameter<IRegressionProblemData> ProblemDataParameter { … … 47 55 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 48 56 } 57 public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 58 get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 59 } 60 61 public IValueLookupParameter<IntRange> ValidationPartitionParameter { 62 get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; } 63 } 49 64 #endregion 50 65 … … 54 69 public SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer() 55 70 : base() { 56 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution.")); 57 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 58 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model.")); 71 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution.") { Hidden = true }); 72 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.") { Hidden = true }); 73 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model.") { Hidden = true }); 74 Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true }); 75 Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition.")); 76 } 77 78 [StorableHook(HookType.AfterDeserialization)] 79 private void AfterDeserialization() { 80 if (!Parameters.ContainsKey(MaximumSymbolicExpressionTreeLengthParameterName)) 81 Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true }); 82 if (!Parameters.ContainsKey(ValidationPartitionParameterName)) 83 Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition.")); 59 84 } 60 85 … … 64 89 65 90 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 66 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);91 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 67 92 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 68 93 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); 69 94 } 95 96 public override IOperation Apply() { 97 var operation = base.Apply(); 98 var paretoFront = TrainingBestSolutionsParameter.ActualValue; 99 100 IResult result; 101 ScatterPlot qualityToTreeSize; 102 if (!ResultCollection.TryGetValue("Pareto Front Analysis", out result)) { 103 qualityToTreeSize = new ScatterPlot("Quality vs Tree Size", ""); 104 qualityToTreeSize.VisualProperties.XAxisMinimumAuto = false; 105 qualityToTreeSize.VisualProperties.XAxisMaximumAuto = false; 106 qualityToTreeSize.VisualProperties.YAxisMinimumAuto = false; 107 qualityToTreeSize.VisualProperties.YAxisMaximumAuto = false; 108 109 qualityToTreeSize.VisualProperties.XAxisMinimumFixedValue = 0; 110 qualityToTreeSize.VisualProperties.XAxisMaximumFixedValue = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value; 111 qualityToTreeSize.VisualProperties.YAxisMinimumFixedValue = 0; 112 qualityToTreeSize.VisualProperties.YAxisMaximumFixedValue = 2; 113 ResultCollection.Add(new Result("Pareto Front Analysis", qualityToTreeSize)); 114 } else { 115 qualityToTreeSize = (ScatterPlot)result.Value; 116 } 117 118 119 int previousTreeLength = -1; 120 var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>(); 121 foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) { 122 int treeLength = solution.Model.SymbolicExpressionTree.Length; 123 if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution); 124 if (solution.TrainingNormalizedMeanSquaredError < sizeParetoFront.Last.Value.TrainingNormalizedMeanSquaredError) { 125 if (treeLength == previousTreeLength) 126 sizeParetoFront.RemoveLast(); 127 sizeParetoFront.AddLast(solution); 128 } 129 previousTreeLength = treeLength; 130 } 131 132 qualityToTreeSize.Rows.Clear(); 133 var trainingRow = new ScatterPlotDataRow("Training NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingNormalizedMeanSquaredError))); 134 trainingRow.VisualProperties.PointSize = 8; 135 qualityToTreeSize.Rows.Add(trainingRow); 136 137 var validationPartition = ValidationPartitionParameter.ActualValue; 138 if (validationPartition.Size != 0) { 139 var problemData = ProblemDataParameter.ActualValue; 140 var validationIndizes = Enumerable.Range(validationPartition.Start, validationPartition.Size).ToList(); 141 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, validationIndizes).ToList(); 142 OnlineCalculatorError error; 143 var validationRow = new ScatterPlotDataRow("Validation NMSE", "", 144 sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, 145 OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, x.GetEstimatedValues(validationIndizes), out error)))); 146 validationRow.VisualProperties.PointSize = 7; 147 qualityToTreeSize.Rows.Add(validationRow); 148 } 149 150 return operation; 151 } 152 70 153 } 71 154 } -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs
r12012 r14029 54 54 55 55 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 56 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);56 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 57 57 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 58 58 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame
r12753 r14029 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4. 8.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.9.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")] -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties/AssemblyInfo.cs.frame
r12753 r14029 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 8.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.9.$WCREV$")] -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r12509 r14029 40 40 private const string ConstantOptimizationRowsPercentageParameterName = "ConstantOptimizationRowsPercentage"; 41 41 private const string UpdateConstantsInTreeParameterName = "UpdateConstantsInSymbolicExpressionTree"; 42 private const string UpdateVariableWeightsParameterName = "Update Variable Weights"; 42 43 43 44 public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter { … … 56 57 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateConstantsInTreeParameterName]; } 57 58 } 59 public IFixedValueParameter<BoolValue> UpdateVariableWeightsParameter { 60 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateVariableWeightsParameterName]; } 61 } 62 58 63 59 64 public IntValue ConstantOptimizationIterations { … … 72 77 get { return UpdateConstantsInTreeParameter.Value.Value; } 73 78 set { UpdateConstantsInTreeParameter.Value.Value = value; } 79 } 80 81 public bool UpdateVariableWeights { 82 get { return UpdateVariableWeightsParameter.Value.Value; } 83 set { UpdateVariableWeightsParameter.Value.Value = value; } 74 84 } 75 85 … … 86 96 : base() { 87 97 Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "Determines how many iterations should be calculated while optimizing the constant of a symbolic expression tree (0 indicates other or default stopping criterion).", new IntValue(10), true)); 88 Parameters.Add(new FixedValueParameter<DoubleValue>(ConstantOptimizationImprovementParameterName, "Determines the relative improvement which must be achieved in the constant optimization to continue with it (0 indicates other or default stopping criterion).", new DoubleValue(0), true) );98 Parameters.Add(new FixedValueParameter<DoubleValue>(ConstantOptimizationImprovementParameterName, "Determines the relative improvement which must be achieved in the constant optimization to continue with it (0 indicates other or default stopping criterion).", new DoubleValue(0), true) { Hidden = true }); 89 99 Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationProbabilityParameterName, "Determines the probability that the constants are optimized", new PercentValue(1), true)); 90 100 Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationRowsPercentageParameterName, "Determines the percentage of the rows which should be used for constant optimization", new PercentValue(1), true)); 91 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true))); 101 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true)) { Hidden = true }); 102 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized.", new BoolValue(true)) { Hidden = true }); 92 103 } 93 104 … … 100 111 if (!Parameters.ContainsKey(UpdateConstantsInTreeParameterName)) 101 112 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true))); 113 if (!Parameters.ContainsKey(UpdateVariableWeightsParameterName)) 114 Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized.", new BoolValue(true))); 102 115 } 103 116 … … 108 121 IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value); 109 122 quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue, 110 constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value, 111 EstimationLimitsParameter.ActualValue.Upper, EstimationLimitsParameter.ActualValue.Lower, UpdateConstantsInTree); 123 constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateConstantsInTree: UpdateConstantsInTree); 112 124 113 125 if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { … … 164 176 165 177 166 public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData, 167 IEnumerable<int> rows, bool applyLinearScaling, int maxIterations, double upperEstimationLimit = double.MaxValue, double lowerEstimationLimit = double.MinValue, bool updateConstantsInTree = true) { 178 public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int maxIterations, bool updateVariableWeights = true, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue, bool updateConstantsInTree = true) { 168 179 169 180 List<AutoDiff.Variable> variables = new List<AutoDiff.Variable>(); … … 172 183 173 184 AutoDiff.Term func; 174 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func))185 if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out func)) 175 186 throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree."); 176 187 if (variableNames.Count == 0) return 0.0; 177 188 178 AutoDiff.IParametricCompiledTerm compiledFunc = AutoDiff.TermUtils.Compile(func, variables.ToArray(), parameters.ToArray()); 179 180 List<SymbolicExpressionTreeTerminalNode> terminalNodes = tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>().ToList(); 189 AutoDiff.IParametricCompiledTerm compiledFunc = func.Compile(variables.ToArray(), parameters.ToArray()); 190 191 List<SymbolicExpressionTreeTerminalNode> terminalNodes = null; 192 if (updateVariableWeights) 193 terminalNodes = tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>().ToList(); 194 else 195 terminalNodes = new List<SymbolicExpressionTreeTerminalNode>(tree.Root.IterateNodesPrefix().OfType<ConstantTreeNode>()); 196 197 //extract inital constants 181 198 double[] c = new double[variables.Count]; 182 183 199 { 184 200 c[0] = 0.0; 185 201 c[1] = 1.0; 186 //extract inital constants187 202 int i = 2; 188 203 foreach (var node in terminalNodes) { … … 191 206 if (constantTreeNode != null) 192 207 c[i++] = constantTreeNode.Value; 193 else if ( variableTreeNode != null)208 else if (updateVariableWeights && variableTreeNode != null) 194 209 c[i++] = variableTreeNode.Weight; 195 210 } … … 234 249 235 250 //info == -7 => constant optimization failed due to wrong gradient 236 if (info != -7) UpdateConstants(tree, c.Skip(2).ToArray() );251 if (info != -7) UpdateConstants(tree, c.Skip(2).ToArray(), updateVariableWeights); 237 252 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 238 253 239 if (!updateConstantsInTree) UpdateConstants(tree, originalConstants.Skip(2).ToArray() );254 if (!updateConstantsInTree) UpdateConstants(tree, originalConstants.Skip(2).ToArray(), updateVariableWeights); 240 255 if (originalQuality - quality > 0.001 || double.IsNaN(quality)) { 241 UpdateConstants(tree, originalConstants.Skip(2).ToArray() );256 UpdateConstants(tree, originalConstants.Skip(2).ToArray(), updateVariableWeights); 242 257 return originalQuality; 243 258 } … … 245 260 } 246 261 247 private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants ) {262 private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants, bool updateVariableWeights) { 248 263 int i = 0; 249 264 foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) { … … 252 267 if (constantTreeNode != null) 253 268 constantTreeNode.Value = constants[i++]; 254 else if ( variableTreeNode != null)269 else if (updateVariableWeights && variableTreeNode != null) 255 270 variableTreeNode.Weight = constants[i++]; 256 271 } … … 271 286 } 272 287 273 private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, out AutoDiff.Term term) {288 private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, bool updateVariableWeights, out AutoDiff.Term term) { 274 289 if (node.Symbol is Constant) { 275 290 var var = new AutoDiff.Variable(); … … 283 298 parameters.Add(par); 284 299 variableNames.Add(varNode.VariableName); 285 var w = new AutoDiff.Variable(); 286 variables.Add(w); 287 term = AutoDiff.TermBuilder.Product(w, par); 300 301 if (updateVariableWeights) { 302 var w = new AutoDiff.Variable(); 303 variables.Add(w); 304 term = AutoDiff.TermBuilder.Product(w, par); 305 } else { 306 term = par; 307 } 288 308 return true; 289 309 } … … 292 312 foreach (var subTree in node.Subtrees) { 293 313 AutoDiff.Term t; 294 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out t)) {314 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) { 295 315 term = null; 296 316 return false; … … 305 325 for (int i = 0; i < node.SubtreeCount; i++) { 306 326 AutoDiff.Term t; 307 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, out t)) {327 if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, updateVariableWeights, out t)) { 308 328 term = null; 309 329 return false; … … 316 336 } 317 337 if (node.Symbol is Multiplication) { 318 AutoDiff.Term a, b; 319 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out a) || 320 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, out b)) { 321 term = null; 322 return false; 323 } else { 324 List<AutoDiff.Term> factors = new List<Term>(); 325 foreach (var subTree in node.Subtrees.Skip(2)) { 326 AutoDiff.Term f; 327 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out f)) { 328 term = null; 329 return false; 330 } 331 factors.Add(f); 338 List<AutoDiff.Term> terms = new List<Term>(); 339 foreach (var subTree in node.Subtrees) { 340 AutoDiff.Term t; 341 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) { 342 term = null; 343 return false; 332 344 } 333 term = AutoDiff.TermBuilder.Product(a, b, factors.ToArray()); 334 return true; 335 } 345 terms.Add(t); 346 } 347 if (terms.Count == 1) term = terms[0]; 348 else term = terms.Aggregate((a, b) => new AutoDiff.Product(a, b)); 349 return true; 350 336 351 } 337 352 if (node.Symbol is Division) { 338 // only works for at least two subtrees 339 AutoDiff.Term a, b; 340 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out a) || 341 !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, out b)) { 342 term = null; 343 return false; 344 } else { 345 List<AutoDiff.Term> factors = new List<Term>(); 346 foreach (var subTree in node.Subtrees.Skip(2)) { 347 AutoDiff.Term f; 348 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out f)) { 349 term = null; 350 return false; 351 } 352 factors.Add(1.0 / f); 353 List<AutoDiff.Term> terms = new List<Term>(); 354 foreach (var subTree in node.Subtrees) { 355 AutoDiff.Term t; 356 if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, updateVariableWeights, out t)) { 357 term = null; 358 return false; 353 359 } 354 term = AutoDiff.TermBuilder.Product(a, 1.0 / b, factors.ToArray()); 355 return true; 356 } 360 terms.Add(t); 361 } 362 if (terms.Count == 1) term = 1.0 / terms[0]; 363 else term = terms.Aggregate((a, b) => new AutoDiff.Product(a, 1.0 / b)); 364 return true; 357 365 } 358 366 if (node.Symbol is Logarithm) { 359 367 AutoDiff.Term t; 360 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {368 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 361 369 term = null; 362 370 return false; … … 368 376 if (node.Symbol is Exponential) { 369 377 AutoDiff.Term t; 370 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {378 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 371 379 term = null; 372 380 return false; … … 378 386 if (node.Symbol is Square) { 379 387 AutoDiff.Term t; 380 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {388 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 381 389 term = null; 382 390 return false; … … 385 393 return true; 386 394 } 387 } if (node.Symbol is SquareRoot) { 388 AutoDiff.Term t; 389 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 395 } 396 if (node.Symbol is SquareRoot) { 397 AutoDiff.Term t; 398 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 390 399 term = null; 391 400 return false; … … 394 403 return true; 395 404 } 396 } if (node.Symbol is Sine) { 397 AutoDiff.Term t; 398 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 405 } 406 if (node.Symbol is Sine) { 407 AutoDiff.Term t; 408 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 399 409 term = null; 400 410 return false; … … 403 413 return true; 404 414 } 405 } if (node.Symbol is Cosine) { 406 AutoDiff.Term t; 407 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 415 } 416 if (node.Symbol is Cosine) { 417 AutoDiff.Term t; 418 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 408 419 term = null; 409 420 return false; … … 412 423 return true; 413 424 } 414 } if (node.Symbol is Tangent) { 415 AutoDiff.Term t; 416 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 425 } 426 if (node.Symbol is Tangent) { 427 AutoDiff.Term t; 428 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 417 429 term = null; 418 430 return false; … … 421 433 return true; 422 434 } 423 } if (node.Symbol is Erf) { 424 AutoDiff.Term t; 425 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 435 } 436 if (node.Symbol is Erf) { 437 AutoDiff.Term t; 438 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 426 439 term = null; 427 440 return false; … … 430 443 return true; 431 444 } 432 } if (node.Symbol is Norm) { 433 AutoDiff.Term t; 434 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) { 445 } 446 if (node.Symbol is Norm) { 447 AutoDiff.Term t; 448 if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out t)) { 435 449 term = null; 436 450 return false; … … 446 460 variables.Add(alpha); 447 461 AutoDiff.Term branchTerm; 448 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out branchTerm)) {462 if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, updateVariableWeights, out branchTerm)) { 449 463 term = branchTerm * alpha + beta; 450 464 return true; -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs
r12012 r14029 63 63 64 64 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 65 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);65 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 66 66 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 67 67 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r12012 r14029 42 42 43 43 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) { 44 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);44 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs
r12012 r14029 55 55 56 56 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 57 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);57 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 58 58 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 59 59 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r12012 r14029 42 42 43 43 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) { 44 var model = new SymbolicRegressionModel( (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);44 var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSolutionsAnalyzer.cs
r12012 r14029 27 27 using HeuristicLab.Common; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Data; 29 30 using HeuristicLab.Operators; 30 31 using HeuristicLab.Optimization; … … 33 34 34 35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 36 [StorableClass] 35 37 public class SymbolicRegressionSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer { 36 38 private const string ResultCollectionParameterName = "Results"; 37 39 private const string RegressionSolutionQualitiesResultName = "Regression Solution Qualities"; 40 private const string TrainingQualityParameterName = "TrainingRSquared"; 41 private const string TestQualityParameterName = "TestRSquared"; 38 42 39 43 public ILookupParameter<ResultCollection> ResultCollectionParameter { 40 44 get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; } 45 } 46 public ILookupParameter<DoubleValue> TrainingQualityParameter { 47 get { return (ILookupParameter<DoubleValue>)Parameters[TrainingQualityParameterName]; } 48 } 49 public ILookupParameter<DoubleValue> TestQualityParameter { 50 get { return (ILookupParameter<DoubleValue>)Parameters[TestQualityParameterName]; } 41 51 } 42 52 … … 55 65 public SymbolicRegressionSolutionsAnalyzer() { 56 66 Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results.")); 67 Parameters.Add(new LookupParameter<DoubleValue>(TrainingQualityParameterName)); 68 Parameters.Add(new LookupParameter<DoubleValue>(TestQualityParameterName)); 69 } 70 71 [StorableHook(HookType.AfterDeserialization)] 72 private void AfterDeserialization() { 73 // BackwardsCompatibility3.3 74 75 #region Backwards compatible code, remove with 3.4 76 if (!Parameters.ContainsKey(TrainingQualityParameterName)) 77 Parameters.Add(new LookupParameter<DoubleValue>(TrainingQualityParameterName)); 78 if (!Parameters.ContainsKey(TestQualityParameterName)) 79 Parameters.Add(new LookupParameter<DoubleValue>(TestQualityParameterName)); 80 #endregion 57 81 } 58 82 … … 66 90 67 91 var dataTable = (DataTable)results[RegressionSolutionQualitiesResultName].Value; 92 93 // only if the parameters are available (not available in old persisted code) 94 ILookupParameter<DoubleValue> trainingQualityParam = null; 95 ILookupParameter<DoubleValue> testQualityParam = null; 96 // store actual names of parameter because it is changed below 97 trainingQualityParam = TrainingQualityParameter; 98 string prevTrainingQualityParamName = trainingQualityParam.ActualName; 99 testQualityParam = TestQualityParameter; 100 string prevTestQualityParamName = testQualityParam.ActualName; 68 101 foreach (var result in results.Where(r => r.Value is IRegressionSolution)) { 69 102 var solution = (IRegressionSolution)result.Value; 70 103 71 var trainingR2 = result.Name + Environment.NewLine + "Training R²";72 if (!dataTable.Rows.ContainsKey(trainingR2 ))73 dataTable.Rows.Add(new DataRow(trainingR2 ));104 var trainingR2Name = result.Name + " Training R²"; 105 if (!dataTable.Rows.ContainsKey(trainingR2Name)) 106 dataTable.Rows.Add(new DataRow(trainingR2Name)); 74 107 75 var testR2 = result.Name + Environment.NewLine + " Test R²";76 if (!dataTable.Rows.ContainsKey(testR2 ))77 dataTable.Rows.Add(new DataRow(testR2 ));108 var testR2Name = result.Name + " Test R²"; 109 if (!dataTable.Rows.ContainsKey(testR2Name)) 110 dataTable.Rows.Add(new DataRow(testR2Name)); 78 111 79 dataTable.Rows[trainingR2].Values.Add(solution.TrainingRSquared); 80 dataTable.Rows[testR2].Values.Add(solution.TestRSquared); 112 dataTable.Rows[trainingR2Name].Values.Add(solution.TrainingRSquared); 113 dataTable.Rows[testR2Name].Values.Add(solution.TestRSquared); 114 115 // also add training and test R² to the scope using the parameters 116 // HACK: we change the ActualName of the parameter to write two variables for each solution in the results collection 117 trainingQualityParam.ActualName = trainingR2Name; 118 trainingQualityParam.ActualValue = new DoubleValue(solution.TrainingRSquared); 119 testQualityParam.ActualName = testR2Name; 120 testQualityParam.ActualValue = new DoubleValue(solution.TestRSquared); 81 121 } 122 123 trainingQualityParam.ActualName = prevTrainingQualityParamName; 124 testQualityParam.ActualName = prevTestQualityParamName; 82 125 83 126 return base.Apply(); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r12509 r14029 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 33 34 [Item(Name = "Symbolic Regression Model", Description = "Represents a symbolic regression model.")] 34 35 public class SymbolicRegressionModel : SymbolicDataAnalysisModel, ISymbolicRegressionModel { 35 36 [Storable] 37 private readonly string targetVariable; 38 public string TargetVariable { 39 get { return targetVariable; } 40 } 36 41 37 42 [StorableConstructor] 38 43 protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { } 39 protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) { }40 44 41 public SymbolicRegressionModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 45 protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) 46 : base(original, cloner) { 47 this.targetVariable = original.targetVariable; 48 } 49 50 public SymbolicRegressionModel(string targetVariable, ISymbolicExpressionTree tree, 51 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 42 52 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 43 : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { } 53 : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 54 this.targetVariable = targetVariable; 55 } 44 56 45 57 public override IDeepCloneable Clone(Cloner cloner) { -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r12744 r14029 69 69 70 70 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) { 71 return new SymbolicRegressionModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 71 var regressionProblemData = (IRegressionProblemData)problemData; 72 return new SymbolicRegressionModel(regressionProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 72 73 } 73 74 … … 83 84 public static ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, SymbolicRegressionSolutionImpactValuesCalculator impactValuesCalculator, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData, DoubleLimit estimationLimits, IEnumerable<int> rows, double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) { 84 85 var clonedTree = (ISymbolicExpressionTree)tree.Clone(); 85 var model = new SymbolicRegressionModel( clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);86 var model = new SymbolicRegressionModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 86 87 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol 87 88 -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r12012 r14029 118 118 estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue())); 119 119 Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults)); 120 121 120 RecalculateResults(); 122 121 }
Note: See TracChangeset
for help on using the changeset viewer.