Free cookie consent management tool by TermsFeed Policy Generator

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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.