Changeset 3452 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs
- Timestamp:
- 04/20/10 20:31:23 (14 years ago)
- 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 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 5 26 using HeuristicLab.Core; 6 27 using HeuristicLab.Data; 7 using HeuristicLab. DataAnalysis;28 using HeuristicLab.Parameters; 8 29 9 namespace HeuristicLab. Modeling{10 public class SimpleNMSEEvaluator : SimpleEvaluator Base{30 namespace HeuristicLab.Problems.DataAnalysis.Evaluators { 31 public class SimpleNMSEEvaluator : SimpleEvaluator { 11 32 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"]; } 24 35 } 25 36 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(); 41 53 } 42 54 }
Note: See TracChangeset
for help on using the changeset viewer.