- Timestamp:
- 03/30/12 10:21:21 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 1 added
- 1 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r7294 r7672 114 114 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 115 115 <Compile Include="Plugin.cs" /> 116 <Compile Include="SingleObjective\ SymbolicRegressionConstantOptimizationEvaluator.cs" />116 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionConstantOptimizationEvaluator.cs" /> 117 117 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs" /> 118 118 <Compile Include="SymbolicRegressionModel.cs" /> … … 130 130 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs" /> 131 131 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs" /> 132 <Compile Include="SingleObjective\ SymbolicRegressionSingleObjectiveEvaluator.cs" />133 <Compile Include="SingleObjective\ SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" />134 <Compile Include="SingleObjective\ SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" />132 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveEvaluator.cs" /> 133 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" /> 134 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" /> 135 135 <Compile Include="SymbolicRegressionSolution.cs" /> 136 136 <None Include="HeuristicLab.snk" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r7670 r7672 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; 25 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 29 [StorableClass] 26 30 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 31 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 32 public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter { 33 get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 34 } 35 public bool ApplyLinearScaling { 36 get { return ApplyLinearScalingParameter.Value.Value; } 37 set { ApplyLinearScalingParameter.Value.Value = value; } 38 } 39 27 40 [StorableConstructor] 28 41 protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { } 29 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) 30 : base(original, cloner) { 42 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 43 protected SymbolicRegressionSingleObjectiveEvaluator() 44 : base() { 45 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(true))); 46 ApplyLinearScalingParameter.Hidden = true; 31 47 } 32 48 33 protected SymbolicRegressionSingleObjectiveEvaluator() : base() { } 49 [StorableHook(HookType.AfterDeserialization)] 50 private void AfterDeserialization() { 51 if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) { 52 Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(false))); 53 ApplyLinearScalingParameter.Hidden = true; 54 } 55 } 34 56 } 35 57 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r7670 r7672 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 31 33 [StorableClass] 32 34 public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 35 public override bool Maximization { get { return false; } } 36 [ThreadStatic] 37 private static double[] estimatedValuesCache; 38 33 39 [StorableConstructor] 34 40 protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } … … 39 45 return new SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(this, cloner); 40 46 } 41 42 47 public SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator() : base() { } 43 44 public override bool Maximization { get { return false; } }45 48 46 49 public override IOperation Apply() { … … 48 51 IEnumerable<int> rows = GenerateRowsToEvaluate(); 49 52 50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );53 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScaling); 51 54 QualityParameter.ActualValue = new DoubleValue(quality); 52 55 … … 54 57 } 55 58 56 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows ) {59 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 57 60 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 58 61 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 59 IEnumerable<double> boundedEstimat ionValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);62 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 60 63 OnlineCalculatorError errorState; 61 double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState); 62 if (errorState != OnlineCalculatorError.None) return double.NaN; 64 65 double mse; 66 if (applyLinearScaling) { 67 //int i = 0; 68 //int rowCount = rows.Count(); 69 //if (estimatedValuesCache == null) estimatedValuesCache = new double[problemData.Dataset.Rows]; 70 //foreach (var value in boundedEstimatedValues) { 71 // estimatedValuesCache[i] = value; 72 // i++; 73 //} 74 75 double alpha, beta; 76 OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, originalValues, out alpha, out beta, out errorState); 77 mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues.Select(value => value * beta + alpha), out errorState); 78 } else 79 mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues, out errorState); 80 81 if (errorState != OnlineCalculatorError.None) return Double.NaN; 63 82 else return mse; 64 83 } … … 68 87 EstimationLimitsParameter.ExecutionContext = context; 69 88 70 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows); 71 89 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScaling); 72 90 73 91 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset
for help on using the changeset viewer.