Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Evaluators/OnlineMeanFractionalDistanceEvaluator.cs @ 6451

Last change on this file since 6451 was 5275, checked in by gkronber, 14 years ago

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File size: 1.7 KB
RevLine 
[5275]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Problems.DataAnalysis.Evaluators;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Parameters;
10
11namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Evaluators {
12  public class OnlineMeanFractionalDistanceEvaluator : IMultiVariateOnlineEvaluator {
13    private OnlineMeanAndVarianceCalculator meanEvaluator;
14    private readonly double d;
15    public OnlineMeanFractionalDistanceEvaluator(double d) {
16      this.d = d;
17      meanEvaluator = new OnlineMeanAndVarianceCalculator();
18      Reset();
19    }
20
21    public double MeanFractionalDistance {
22      get { return meanEvaluator.Mean ; }
23    }
24
25    #region IMultiVariateOnlineEvaluator Members
26    public double Value {
27      get { return MeanFractionalDistance; }
28    }
29
30    public void Add(IEnumerable<double> original, IEnumerable<double> estimated) {
31      var originalEnumerator = original.GetEnumerator();
32      var estimatedEnumerator = estimated.GetEnumerator();
33      double sum = 0.0;
34      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
35        sum += Math.Pow(Math.Abs(originalEnumerator.Current - estimatedEnumerator.Current), 1.0 / d);
36      }
37      if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext()) {
38        throw new ArgumentException("Number of elements in original and estimated does not match.");
39      }
40      double fracDist = Math.Pow(sum, d);
41      meanEvaluator.Add(fracDist);
42    }
43
44    public void Reset() {
45      meanEvaluator.Reset();
46    }
47
48    #endregion
49  }
50}
Note: See TracBrowser for help on using the repository browser.