Changeset 12448
- Timestamp:
- 06/15/15 17:00:37 (9 years ago)
- Location:
- branches/SensitivityEvaluator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator.cs
r12416 r12448 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 33 33 [Item("Weighted Residuals Mean Squared Error Evaluator", @"A modified mean squared error evaluator that enables the possibility to weight residuals differently. 34 The first residual category belongs to estimated values which obviously belong to a specific class because the estimated value is located above the maximum or below the minimum of all the class values (ObviousResidualsWeight).34 The first residual category belongs to estimated values which definitely belong to a specific class because the estimated value is located above the maximum or below the minimum of all the class values (DefiniteResidualsWeight). 35 35 The second residual category represents residuals which belong to the positive class whereby the estimated value is located between the positive and a negative class (PositiveClassResidualsWeight). 36 All other cases are represented by the third category (NegativeClass ResidualsWeight).36 All other cases are represented by the third category (NegativeClassesResidualsWeight). 37 37 The weight is multiplied to the error before squaring which means that the Evaluator acts like a normal MSE-Evaluator if all the weights are set to 1.")] 38 38 [StorableClass] 39 39 public class SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator { 40 private const string ObviousResidualsWeightParameterName = "ObviousResidualsWeight";40 private const string DefiniteResidualsWeightParameterName = "DefiniteResidualsWeight"; 41 41 private const string PositiveClassResidualsWeightParameterName = "PositiveClassResidualsWeight"; 42 private const string NegativeClass ResidualsWeightParameterName = "NegativeClassResidualsWeight";42 private const string NegativeClassesResidualsWeightParameterName = "NegativeClassesResidualsWeight"; 43 43 [StorableConstructor] 44 44 protected SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } … … 52 52 public SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator() 53 53 : base() { 54 Parameters.Add(new FixedValueParameter<DoubleValue>( ObviousResidualsWeightParameterName, "Weight of residuals which obviously belong to a specific class because the estimated values is located above the maximum or below the minimum of all the class values.", new DoubleValue(1)));54 Parameters.Add(new FixedValueParameter<DoubleValue>(DefiniteResidualsWeightParameterName, "Weight of residuals which definitely belong to a specific class because the estimated values is located above the maximum or below the minimum of all the class values.", new DoubleValue(1))); 55 55 Parameters.Add(new FixedValueParameter<DoubleValue>(PositiveClassResidualsWeightParameterName, "Weight of residuals which belong to the positive class whereby the estimated value is located between the positive and a negative class.", new DoubleValue(1))); 56 Parameters.Add(new FixedValueParameter<DoubleValue>(NegativeClass ResidualsWeightParameterName, "Weight of residuals which are not covered by the ObviousResidualsWeight or the PositiveClassResidualsWeight.", new DoubleValue(1)));56 Parameters.Add(new FixedValueParameter<DoubleValue>(NegativeClassesResidualsWeightParameterName, "Weight of residuals which are not covered by the DefiniteResidualsWeight or the PositiveClassResidualsWeight.", new DoubleValue(1))); 57 57 } 58 58 59 59 #region parameter properties 60 public IFixedValueParameter<DoubleValue> ObviousResidualsWeightParameter {61 get { return (IFixedValueParameter<DoubleValue>)Parameters[ ObviousResidualsWeightParameterName]; }60 public IFixedValueParameter<DoubleValue> DefiniteResidualsWeightParameter { 61 get { return (IFixedValueParameter<DoubleValue>)Parameters[DefiniteResidualsWeightParameterName]; } 62 62 } 63 63 public IFixedValueParameter<DoubleValue> PositiveClassResidualsWeightParameter { 64 64 get { return (IFixedValueParameter<DoubleValue>)Parameters[PositiveClassResidualsWeightParameterName]; } 65 65 } 66 public IFixedValueParameter<DoubleValue> NegativeClass ResidualsWeightParameter {67 get { return (IFixedValueParameter<DoubleValue>)Parameters[NegativeClass ResidualsWeightParameterName]; }66 public IFixedValueParameter<DoubleValue> NegativeClassesResidualsWeightParameter { 67 get { return (IFixedValueParameter<DoubleValue>)Parameters[NegativeClassesResidualsWeightParameterName]; } 68 68 } 69 69 #endregion … … 72 72 public override bool Maximization { get { return false; } } 73 73 74 public double ObviousResidualsWeight {74 public double DefiniteResidualsWeight { 75 75 get { 76 return ObviousResidualsWeightParameter.Value.Value;76 return DefiniteResidualsWeightParameter.Value.Value; 77 77 } 78 78 } … … 82 82 } 83 83 } 84 public double NegativeClass ResidualsWeight {84 public double NegativeClassesResidualsWeight { 85 85 get { 86 return NegativeClass ResidualsWeightParameter.Value.Value;86 return NegativeClassesResidualsWeightParameter.Value.Value; 87 87 } 88 88 } … … 93 93 var solution = SymbolicExpressionTreeParameter.ActualValue; 94 94 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, 95 ObviousResidualsWeight, PositiveClassResidualsWeight, NegativeClassResidualsWeight);95 DefiniteResidualsWeight, PositiveClassResidualsWeight, NegativeClassesResidualsWeight); 96 96 QualityParameter.ActualValue = new DoubleValue(quality); 97 97 return base.InstrumentedApply(); … … 99 99 100 100 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, 101 double obviousResidualsWeight, double positiveClassResidualsWeight, double negativeClassResidualsWeight) {101 double definiteResidualsWeight, double positiveClassResidualsWeight, double negativeClassesResidualsWeight) { 102 102 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 103 103 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); … … 116 116 if (applyLinearScaling) { 117 117 var calculator = new OnlineWeightedResidualsMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin, 118 obviousResidualsWeight, positiveClassResidualsWeight, negativeClassResidualsWeight);118 definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight); 119 119 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, calculator, problemData.Dataset.Rows); 120 120 errorState = calculator.ErrorState; … … 123 123 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 124 124 quality = OnlineWeightedResidualsMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, positiveClassValue, classValuesMax, 125 classValuesMin, obviousResidualsWeight, positiveClassResidualsWeight, negativeClassResidualsWeight, out errorState);125 classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight, out errorState); 126 126 } 127 127 if (errorState != OnlineCalculatorError.None) return Double.NaN; … … 134 134 ApplyLinearScalingParameter.ExecutionContext = context; 135 135 136 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, ObviousResidualsWeight, PositiveClassResidualsWeight, NegativeClassResidualsWeight);136 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DefiniteResidualsWeight, PositiveClassResidualsWeight, NegativeClassesResidualsWeight); 137 137 138 138 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedResidualsMeanSquaredErrorCalculator.cs
r12416 r12448 36 36 37 37 public double PositiveClassValue { get; private set; } 38 public double ClassValue Max { get; private set; }39 public double ClassValue Min { get; private set; }40 public double ObviousResidualsWeight { get; private set; }38 public double ClassValuesMax { get; private set; } 39 public double ClassValuesMin { get; private set; } 40 public double DefiniteResidualsWeight { get; private set; } 41 41 public double PositiveClassResidualsWeight { get; private set; } 42 public double NegativeClass ResidualsWeight { get; private set; }42 public double NegativeClassesResidualsWeight { get; private set; } 43 43 44 public OnlineWeightedResidualsMeanSquaredErrorCalculator(double positiveClassValue, double classValue Max, double classValueMin,45 double obviousResidualsWeight, double positiveClassResidualsWeight, double negativeClassResidualsWeight) {44 public OnlineWeightedResidualsMeanSquaredErrorCalculator(double positiveClassValue, double classValuesMax, double classValuesMin, 45 double definiteResidualsWeight, double positiveClassResidualsWeight, double negativeClassesResidualsWeight) { 46 46 PositiveClassValue = positiveClassValue; 47 ClassValue Max = classValueMax;48 ClassValue Min = classValueMin;49 ObviousResidualsWeight = obviousResidualsWeight;47 ClassValuesMax = classValuesMax; 48 ClassValuesMin = classValuesMin; 49 DefiniteResidualsWeight = definiteResidualsWeight; 50 50 PositiveClassResidualsWeight = positiveClassResidualsWeight; 51 NegativeClass ResidualsWeight = negativeClassResidualsWeight;51 NegativeClassesResidualsWeight = negativeClassesResidualsWeight; 52 52 Reset(); 53 53 } … … 75 75 double weight; 76 76 //apply weight 77 if (estimated > ClassValueMax || estimated < ClassValueMin) { 78 weight = ObviousResidualsWeight; 79 } else if (original.IsAlmost(PositiveClassValue)) 80 { 77 if (estimated > ClassValuesMax || estimated < ClassValuesMin) { 78 weight = DefiniteResidualsWeight; 79 } else if (original.IsAlmost(PositiveClassValue)) { 81 80 weight = PositiveClassResidualsWeight; 82 } else 83 { 84 weight = NegativeClassResidualsWeight; 81 } else { 82 weight = NegativeClassesResidualsWeight; 85 83 } 86 84 error *= weight; … … 92 90 #endregion 93 91 94 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, double positiveClassValue, double classValue Max, double classValueMin,95 double obviousValuesWeight, double positiveClassValuesWeight, double negativeClassValuesWeight, out OnlineCalculatorError errorState) {92 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, double positiveClassValue, double classValuesMax, double classValuesMin, 93 double definiteResidualsWeight, double positiveClassResidualsWeight, double negativeClassesResidualsWeight, out OnlineCalculatorError errorState) { 96 94 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 97 95 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 98 OnlineWeightedResidualsMeanSquaredErrorCalculator calculator = new OnlineWeightedResidualsMeanSquaredErrorCalculator(positiveClassValue, classValue Max, classValueMin, obviousValuesWeight, positiveClassValuesWeight, negativeClassValuesWeight);96 OnlineWeightedResidualsMeanSquaredErrorCalculator calculator = new OnlineWeightedResidualsMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight); 99 97 100 98 // always move forward both enumerators (do not use short-circuit evaluation!)
Note: See TracChangeset
for help on using the changeset viewer.