Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6643


Ignore:
Timestamp:
08/08/11 17:47:46 (13 years ago)
Author:
mkommend
Message:

#1613: Added !MAE to RegressionSolutions.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r6589 r6643  
    139139    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    140140    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
     141    <Compile Include="OnlineCalculators\OnlineMeanAbsoluteErrorCalculator.cs" />
    141142    <Compile Include="OnlineCalculators\OnlineLinearScalingParameterCalculator.cs" />
    142143    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationModel.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs

    r6589 r6643  
    3232    private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
    3333    private const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
     34    private const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)";
     35    private const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)";
    3436    private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)";
    3537    private const string TestSquaredCorrelationResultName = "Pearson's R² (test)";
     
    6264      get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; }
    6365      private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }
     66    }
     67    public double TrainingMeanAbsoluteError {
     68      get { return ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value; }
     69      private set { ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value = value; }
     70    }
     71    public double TestMeanAbsoluteError {
     72      get { return ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value; }
     73      private set { ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value = value; }
    6474    }
    6575    public double TrainingRSquared {
     
    98108      Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
    99109      Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
     110      Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));
     111      Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));
    100112      Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    101113      Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     
    104116      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
    105117      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
     118    }
     119
     120    [StorableHook(HookType.AfterDeserialization)]
     121    private void AfterDeserialization() {
     122      // BackwardsCompatibility3.4
     123
     124      #region Backwards compatible code, remove with 3.5
     125
     126      if (!ContainsKey(TrainingMeanAbsoluteErrorResultName)) {
     127        OnlineCalculatorError errorState;
     128        Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));
     129        double trainingMAE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes), out errorState);
     130        TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
     131      }
     132
     133      if (!ContainsKey(TestMeanAbsoluteErrorResultName)) {
     134        OnlineCalculatorError errorState;
     135        Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));
     136        double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes), out errorState);
     137        TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
     138      }
     139      #endregion
    106140    }
    107141
     
    117151      double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
    118152      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
     153
     154      double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     155      TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
     156      double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     157      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
    119158
    120159      double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionSolution.cs

    r6588 r6643  
    3333    double TrainingMeanSquaredError { get; }
    3434    double TestMeanSquaredError { get; }
     35    double TrainingMeanAbsoluteError { get; }
     36    double TestMeanAbsoluteError { get; }
    3537    double TrainingRSquared { get; }
    3638    double TestRSquared { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs

    r6641 r6643  
    2424
    2525namespace HeuristicLab.Problems.DataAnalysis {
    26   public class OnlineMeanSquaredErrorCalculator : IOnlineCalculator {
     26  public class OnlineMeanAbsoluteErrorCalculator : IOnlineCalculator {
    2727
    28     private double sse;
     28    private double sae;
    2929    private int n;
    30     public double MeanSquaredError {
     30    public double MeanAbsoluteError {
    3131      get {
    32         return n > 0 ? sse / n : 0.0;
     32        return n > 0 ? sae / n : 0.0;
    3333      }
    3434    }
    3535
    36     public OnlineMeanSquaredErrorCalculator() {
     36    public OnlineMeanAbsoluteErrorCalculator() {
    3737      Reset();
    3838    }
     
    4444    }
    4545    public double Value {
    46       get { return MeanSquaredError; }
     46      get { return MeanAbsoluteError; }
    4747    }
    4848    public void Reset() {
    4949      n = 0;
    50       sse = 0.0;
     50      sae = 0.0;
    5151      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    5252    }
     
    5858      } else {
    5959        double error = estimated - original;
    60         sse += error * error;
     60        sae += Math.Abs(error);
    6161        n++;
    6262        errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded);        // n >= 1
     
    6868      IEnumerator<double> firstEnumerator = first.GetEnumerator();
    6969      IEnumerator<double> secondEnumerator = second.GetEnumerator();
    70       OnlineMeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();
     70      OnlineMeanAbsoluteErrorCalculator maeCalculator = new OnlineMeanAbsoluteErrorCalculator();
    7171
    7272      // always move forward both enumerators (do not use short-circuit evaluation!)
     
    7474        double estimated = secondEnumerator.Current;
    7575        double original = firstEnumerator.Current;
    76         mseCalculator.Add(original, estimated);
    77         if (mseCalculator.ErrorState != OnlineCalculatorError.None) break;
     76        maeCalculator.Add(original, estimated);
     77        if (maeCalculator.ErrorState != OnlineCalculatorError.None) break;
    7878      }
    7979
    8080      // check if both enumerators are at the end to make sure both enumerations have the same length
    81       if (mseCalculator.ErrorState == OnlineCalculatorError.None &&
     81      if (maeCalculator.ErrorState == OnlineCalculatorError.None &&
    8282         (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    8383        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    8484      } else {
    85         errorState = mseCalculator.ErrorState;
    86         return mseCalculator.MeanSquaredError;
     85        errorState = maeCalculator.ErrorState;
     86        return maeCalculator.MeanAbsoluteError;
    8787      }
    8888    }
Note: See TracChangeset for help on using the changeset viewer.