Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/02/10 15:21:07 (14 years ago)
Author:
gkronber
Message:

Implemented multi-objective version of symbolic regression problem. #1118

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators
Files:
4 added
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r4127 r4128  
    3333  [Item("SymbolicRegressionMeanSquaredErrorEvaluator", "Calculates the mean squared error of a symbolic regression solution.")]
    3434  [StorableClass]
    35   public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
     35  public class SymbolicRegressionMeanSquaredErrorEvaluator : SingleObjectiveSymbolicRegressionEvaluator {
    3636    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    3737    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionPearsonsRSquaredEvaluator.cs

    r4127 r4128  
    3333  [Item("SymbolicRegressionPearsonsRSquaredEvaluator", "Calculates the pearson r² correlation coefficient of a symbolic regression solution.")]
    3434  [StorableClass]
    35   public class SymbolicRegressionPearsonsRSquaredEvaluator : SymbolicRegressionEvaluator {
     35  public class SymbolicRegressionPearsonsRSquaredEvaluator : SingleObjectiveSymbolicRegressionEvaluator {
    3636    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    3737    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs

    r4127 r4128  
    3737    private const string QualityVarianceParameterName = "QualityVariance";
    3838    private const string QualitySamplesParameterName = "QualitySamples";
     39    private const string DecompositionBiasParameterName = "QualityDecompositionBias";
     40    private const string DecompositionVarianceParameterName = "QualityDecompositionVariance";
     41    private const string DecompositionCovarianceParameterName = "QualityDecompositionCovariance";
     42    private const string ApplyScalingParameterName = "ApplyScaling";
    3943
    4044    #region parameter properties
     45    public IValueLookupParameter<BoolValue> ApplyScalingParameter {
     46      get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyScalingParameterName]; }
     47    }
    4148    public ILookupParameter<DoubleValue> AlphaParameter {
    4249      get { return (ILookupParameter<DoubleValue>)Parameters["Alpha"]; }
     
    5158      get { return (ILookupParameter<IntValue>)Parameters[QualitySamplesParameterName]; }
    5259    }
     60    public ILookupParameter<DoubleValue> DecompositionBiasParameter {
     61      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionBiasParameterName]; }
     62    }
     63    public ILookupParameter<DoubleValue> DecompositionVarianceParameter {
     64      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionVarianceParameterName]; }
     65    }
     66    public ILookupParameter<DoubleValue> DecompositionCovarianceParameter {
     67      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionCovarianceParameterName]; }
     68    }
    5369
    5470    #endregion
    5571    #region properties
     72    public BoolValue ApplyScaling {
     73      get { return ApplyScalingParameter.ActualValue; }
     74    }
    5675    public DoubleValue Alpha {
    5776      get { return AlphaParameter.ActualValue; }
     
    7392    public SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator()
    7493      : base() {
     94      Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyScalingParameterName, "Determines if the estimated values should be scaled.", new BoolValue(true)));
    7595      Parameters.Add(new LookupParameter<DoubleValue>("Alpha", "Alpha parameter for linear scaling of the estimated values."));
    7696      Parameters.Add(new LookupParameter<DoubleValue>("Beta", "Beta parameter for linear scaling of the estimated values."));
    7797      Parameters.Add(new LookupParameter<DoubleValue>(QualityVarianceParameterName, "A parameter which stores the variance of the squared errors."));
    7898      Parameters.Add(new LookupParameter<IntValue>(QualitySamplesParameterName, " The number of evaluated samples."));
     99      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionBiasParameterName, "A parameter which stores the relativ bias of the MSE."));
     100      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionVarianceParameterName, "A parameter which stores the relativ bias of the MSE."));
     101      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionCovarianceParameterName, "A parameter which stores the relativ bias of the MSE."));
    79102    }
    80103
     
    83106      double meanSE, varianceSE;
    84107      int count;
    85       double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count);
    86       Alpha = new DoubleValue(alpha);
    87       Beta = new DoubleValue(beta);
     108      double bias, variance, covariance;
     109      double mse;
     110      if (ApplyScaling.Value) {
     111        mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     112        Alpha = new DoubleValue(alpha);
     113        Beta = new DoubleValue(beta);
     114      } else {
     115        mse = CalculateWithScaling(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, 1, 0, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     116      }
    88117      QualityVariance = new DoubleValue(varianceSE);
    89118      QualitySamples = new IntValue(count);
     119      DecompositionBiasParameter.ActualValue = new DoubleValue(bias / meanSE);
     120      DecompositionVarianceParameter.ActualValue = new DoubleValue(variance / meanSE);
     121      DecompositionCovarianceParameter.ActualValue = new DoubleValue(covariance / meanSE);
    90122      return mse;
    91123    }
    92124
    93     public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count) {
     125    public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) {
    94126      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
    95127      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows);
    96128      CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);
    97129
    98       return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count);
    99     }
    100 
    101     public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count) {
     130      return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     131    }
     132
     133    public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) {
    102134      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows);
    103135      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
     
    105137      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    106138      OnlineMeanAndVarianceCalculator seEvaluator = new OnlineMeanAndVarianceCalculator();
     139      OnlineMeanAndVarianceCalculator originalMeanEvaluator = new OnlineMeanAndVarianceCalculator();
     140      OnlineMeanAndVarianceCalculator estimatedMeanEvaluator = new OnlineMeanAndVarianceCalculator();
     141      OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
    107142
    108143      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     
    116151        error *= error;
    117152        seEvaluator.Add(error);
     153        originalMeanEvaluator.Add(original);
     154        estimatedMeanEvaluator.Add(estimated);
     155        r2Evaluator.Add(original, estimated);
    118156      }
    119157
     
    124162        varianceSE = seEvaluator.Variance;
    125163        count = seEvaluator.Count;
     164        bias = (originalMeanEvaluator.Mean - estimatedMeanEvaluator.Mean);
     165        bias *= bias;
     166
     167        double sO = Math.Sqrt(originalMeanEvaluator.Variance);
     168        double sE = Math.Sqrt(estimatedMeanEvaluator.Variance);
     169        variance = sO - sE;
     170        variance *= variance;
     171        double r = Math.Sqrt(r2Evaluator.RSquared);
     172        covariance = 2 * sO * sE * (1 - r);
    126173        return seEvaluator.Mean;
    127174      }
Note: See TracChangeset for help on using the changeset viewer.