Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/10 20:31:23 (14 years ago)
Author:
gkronber
Message:

Included tracking of best of run solution (based on validation set) and calculation of MSE, R² and rel. Error on training and test sets. #938 (Data types and operators for regression problems)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs

    r3441 r3452  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526using HeuristicLab.Core;
    627using HeuristicLab.Data;
    7 using HeuristicLab.DataAnalysis;
     28using HeuristicLab.Parameters;
    829
    9 namespace HeuristicLab.Modeling {
    10   public class SimpleNMSEEvaluator : SimpleEvaluatorBase {
     30namespace HeuristicLab.Problems.DataAnalysis.Evaluators {
     31  public class SimpleNMSEEvaluator : SimpleEvaluator {
    1132
    12     public override string OutputVariableName {
    13       get {
    14         return "NMSE";
    15       }
    16     }
    17     public override double Evaluate(double[,] values) {
    18       try {
    19         return Calculate(values);
    20       }
    21       catch (ArgumentException) {
    22         return double.PositiveInfinity;
    23       }
     33    public ILookupParameter<DoubleValue> NormalizedMeanSquaredErrorParameter {
     34      get { return (ILookupParameter<DoubleValue>)Parameters["NormalizedMeanSquaredError"]; }
    2435    }
    2536
    26     public static double Calculate(double[,] values) {
    27       double mse = SimpleMSEEvaluator.Calculate(values);
    28       double mean = Statistics.Mean(Matrix<double>.GetColumn(values, ORIGINAL_INDEX));
    29       double ssd = 0;
    30       int n = 0;
    31       for (int i = 0; i < values.GetLength(0); i++) {
    32         double original = values[i, ORIGINAL_INDEX];
    33         if (!(double.IsNaN(original) || double.IsInfinity(original))) {
    34           double dev = original - mean;
    35           ssd += dev * dev;
    36           n++;
    37         }
    38       }
    39       double variance = ssd / (n - 1);
    40       return mse / variance;
     37    public SimpleNMSEEvaluator() {
     38      Parameters.Add(new LookupParameter<DoubleValue>("NormalizedMeanSquaredError", "The normalized mean squared error (divided by variance) of estimated values."));
     39    }
     40
     41    protected override void Apply(DoubleMatrix values) {
     42      var original = from i in Enumerable.Range(0, values.Rows)
     43                     select values[i, ORIGINAL_INDEX];
     44      var estimated = from i in Enumerable.Range(0, values.Rows)
     45                      select values[i, ESTIMATION_INDEX];
     46
     47      NormalizedMeanSquaredErrorParameter.ActualValue = new DoubleValue(Calculate(original, estimated));
     48    }
     49
     50    public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) {
     51      double mse = SimpleMSEEvaluator.Calculate(original, estimated);
     52      return mse / original.Variance();
    4153    }
    4254  }
Note: See TracChangeset for help on using the changeset viewer.