Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1888


Ignore:
Timestamp:
05/25/09 15:09:44 (15 years ago)
Author:
gkronber
Message:

Added simple evaluators for mean absolute percentage error, mean absolute percentage of range error and, variance accounted for. #635 (Plugin HeuristicLab.Modeling as a common basis for all data-based modeling algorithms)

Location:
trunk/sources/HeuristicLab.Modeling/3.2
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r1869 r1888  
    8383  <ItemGroup>
    8484    <Compile Include="ClassificationProblemInjector.cs" />
     85    <Compile Include="SimpleEvaluatorBase.cs" />
    8586    <Compile Include="ITimeSeriesAlgorithm.cs" />
    8687    <Compile Include="IClassificationAlgorithm.cs" />
     
    8889    <Compile Include="HeuristicLabModelingPlugin.cs" />
    8990    <Compile Include="IAlgorithm.cs" />
     91    <Compile Include="SimpleMeanAbsolutePercentageErrorEvaluator.cs" />
     92    <Compile Include="SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.cs" />
    9093    <Compile Include="ProblemInjector.cs" />
    9194    <Compile Include="ProblemInjectorView.cs">
     
    99102    <Compile Include="SimpleR2Evaluator.cs" />
    100103    <Compile Include="TimeSeriesProblemInjector.cs" />
     104    <Compile Include="SimpleVarianceAccountedForEvaluator.cs" />
    101105  </ItemGroup>
    102106  <ItemGroup>
  • trunk/sources/HeuristicLab.Modeling/3.2/SimpleMSEEvaluator.cs

    r1869 r1888  
    88
    99namespace HeuristicLab.Modeling {
    10   public class SimpleMSEEvaluator : OperatorBase {
     10  public class SimpleMSEEvaluator : SimpleEvaluatorBase {
    1111
    12     public SimpleMSEEvaluator()
    13       : base() {
    14       AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.In));
    15       AddVariableInfo(new VariableInfo("MSE", "Mean squarred error", typeof(DoubleData), VariableKind.New | VariableKind.Out));
     12    public override string OutputVariableName {
     13      get {
     14        return "MSE";
     15      }
     16    }
     17    public override double Evaluate(double[,] values) {
     18      return Calculate(values);
    1619    }
    1720
    18     public override IOperation Apply(IScope scope) {
    19       DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true);
     21    public static double Calculate(double[,] values) {
    2022      double sse = 0;
    2123      double cnt = 0;
    22       for (int i = 0; i < values.Data.GetLength(0); i++) {
    23         double estimated = values.Data[i, 0];
    24         double target = values.Data[i, 1];
     24      for (int i = 0; i < values.GetLength(0); i++) {
     25        double estimated = values[i, 0];
     26        double target = values[i, 1];
    2527        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
    2628            !double.IsNaN(target) && !double.IsInfinity(target)) {
     
    3234
    3335      double mse = sse / cnt;
    34       scope.AddVariable(new Variable(scope.TranslateName("MSE"), new DoubleData(mse)));
    35       return null;
     36      return mse;
    3637    }
    3738  }
  • trunk/sources/HeuristicLab.Modeling/3.2/SimpleR2Evaluator.cs

    r1869 r1888  
    88
    99namespace HeuristicLab.Modeling {
    10   public class SimpleR2Evaluator : OperatorBase {
     10  public class SimpleR2Evaluator : SimpleEvaluatorBase {
    1111
    12     public SimpleR2Evaluator()
    13       : base() {
    14       AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.In));
    15       AddVariableInfo(new VariableInfo("R2", "Coefficient of determination", typeof(DoubleData), VariableKind.New | VariableKind.Out));
     12    public override string OutputVariableName {
     13      get {
     14        return "R2";
     15      }
    1616    }
    1717
    18     public override IOperation Apply(IScope scope) {
    19       DoubleMatrixData values = GetVariableValue<DoubleMatrixData>("Values", scope, true);
     18    public override double Evaluate(double[,] values) {
     19      return Calculate(values);
     20    }
    2021
     22    public static double Calculate(double[,] values) {
    2123      double targetMean = 0;
    2224      double sse = 0;
    2325      double cnt = 0;
    24       for (int i = 0; i < values.Data.GetLength(0); i++) {
    25         double estimated = values.Data[i, 0];
    26         double target = values.Data[i, 1];
     26      for (int i = 0; i < values.GetLength(0); i++) {
     27        double estimated = values[i, 0];
     28        double target = values[i, 1];
    2729        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
    2830            !double.IsNaN(target) && !double.IsInfinity(target)) {
     
    3638
    3739      double targetDeviationTotalSumOfSquares = 0;
    38       for (int i = 0; i < values.Data.GetLength(0); i++) {
    39         double target = values.Data[i, 1];
     40      for (int i = 0; i < values.GetLength(0); i++) {
     41        double target = values[i, 1];
    4042        if (!double.IsNaN(target) && !double.IsInfinity(target)) {
    4143          target = target - targetMean;
     
    4850        throw new InvalidProgramException();
    4951
    50       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("R2"), new DoubleData(quality)));
    51       return null;
     52      return quality;
    5253    }
    5354  }
Note: See TracChangeset for help on using the changeset viewer.