Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12581 for trunk


Ignore:
Timestamp:
07/03/15 14:34:21 (9 years ago)
Author:
mkommend
Message:

#2412: Added RMSE and remove mean error from RegressionSolutionBase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs

    r12012 r12581  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    3940    protected const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)";
    4041    protected const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)";
    41     protected const string TrainingMeanErrorResultName = "Mean error (training)";
    42     protected const string TestMeanErrorResultName = "Mean error (test)";
     42    protected const string TrainingRootMeanSquaredErrorResultName = "Root mean squared error (training)";
     43    protected const string TestRootMeanSquaredErrorResultName = "Root mean squared error (test)";
     44
     45    // BackwardsCompatibility3.3
     46    #region Backwards compatible code, remove with 3.5
     47    private const string TrainingMeanErrorResultName = "Mean error (training)";
     48    private const string TestMeanErrorResultName = "Mean error (test)";
     49    #endregion
     50
    4351
    4452    protected const string TrainingMeanSquaredErrorResultDescription = "Mean of squared errors of the model on the training partition";
     
    5260    protected const string TrainingNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the training partition";
    5361    protected const string TestNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the test partition";
    54     protected const string TrainingMeanErrorResultDescription = "Mean of errors of the model on the training partition";
    55     protected const string TestMeanErrorResultDescription = "Mean of errors of the model on the test partition";
     62    protected const string TrainingRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the training partition";
     63    protected const string TestRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the test partition";
    5664
    5765    public new IRegressionModel Model {
     
    111119      private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }
    112120    }
    113     public double TrainingMeanError {
    114       get { return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value; }
    115       private set { ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value; }
    116     }
    117     public double TestMeanError {
    118       get { return ((DoubleValue)this[TestMeanErrorResultName].Value).Value; }
    119       private set { ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value; }
    120     }
     121    public double TrainingRootMeanSquaredError {
     122      get { return ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value; }
     123      private set { ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value = value; }
     124    }
     125    public double TestRootMeanSquaredError {
     126      get { return ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value; }
     127      private set { ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value = value; }
     128    }
     129
     130    // BackwardsCompatibility3.3
     131    #region Backwards compatible code, remove with 3.5
     132    private double TrainingMeanError {
     133      get {
     134        if (!ContainsKey(TrainingMeanErrorResultName)) return double.NaN;
     135        return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value;
     136      }
     137      set {
     138        if (ContainsKey(TrainingMeanErrorResultName))
     139          ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value;
     140      }
     141    }
     142    private double TestMeanError {
     143      get {
     144        if (!ContainsKey(TestMeanErrorResultName)) return double.NaN;
     145        return ((DoubleValue)this[TestMeanErrorResultName].Value).Value;
     146      }
     147      set {
     148        if (ContainsKey(TestMeanErrorResultName))
     149          ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value;
     150      }
     151    }
     152    #endregion
    121153    #endregion
    122154
     
    138170      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, TrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
    139171      Add(new Result(TestNormalizedMeanSquaredErrorResultName, TestNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
    140       Add(new Result(TrainingMeanErrorResultName, TrainingMeanErrorResultDescription, new DoubleValue()));
    141       Add(new Result(TestMeanErrorResultName, TestMeanErrorResultDescription, new DoubleValue()));
     172      Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue()));
     173      Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue()));
    142174    }
    143175
     
    145177    private void AfterDeserialization() {
    146178      // BackwardsCompatibility3.4
    147 
    148179      #region Backwards compatible code, remove with 3.5
    149 
    150180      if (!ContainsKey(TrainingMeanAbsoluteErrorResultName)) {
    151181        OnlineCalculatorError errorState;
     
    162192      }
    163193
    164       if (!ContainsKey(TrainingMeanErrorResultName)) {
    165         OnlineCalculatorError errorState;
    166         Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue()));
    167         double trainingME = OnlineMeanErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);
    168         TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;
    169       }
    170       if (!ContainsKey(TestMeanErrorResultName)) {
    171         OnlineCalculatorError errorState;
    172         Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue()));
    173         double testME = OnlineMeanErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);
    174         TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;
     194      if (!ContainsKey(TrainingRootMeanSquaredErrorResultName)) {
     195        OnlineCalculatorError errorState;
     196        Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue()));
     197        double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState);
     198        TrainingRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(trainingMSE) : double.NaN;
     199      }
     200
     201      if (!ContainsKey(TestRootMeanSquaredErrorResultName)) {
     202        OnlineCalculatorError errorState;
     203        Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue()));
     204        double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState);
     205        TestRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(testMSE) : double.NaN;
    175206      }
    176207      #endregion
     
    213244      TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN;
    214245
    215       double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    216       TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;
    217       double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    218       TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;
     246      TrainingRootMeanSquaredError = Math.Sqrt(TrainingMeanSquaredError);
     247      TestRootMeanSquaredError = Math.Sqrt(TestMeanSquaredError);
     248
     249      // BackwardsCompatibility3.3
     250      #region Backwards compatible code, remove with 3.5
     251      if (ContainsKey(TrainingMeanErrorResultName)) {
     252        double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     253        TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN;
     254      }
     255      if (ContainsKey(TestMeanErrorResultName)) {
     256        double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     257        TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN;
     258      }
     259      #endregion
    219260    }
    220261  }
Note: See TracChangeset for help on using the changeset viewer.