using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Problems.DataAnalysis.Evaluators; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Parameters; namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Evaluators { public class OnlineMeanFractionalDistanceEvaluator : IMultiVariateOnlineEvaluator { private OnlineMeanAndVarianceCalculator meanEvaluator; private readonly double d; public OnlineMeanFractionalDistanceEvaluator(double d) { this.d = d; meanEvaluator = new OnlineMeanAndVarianceCalculator(); Reset(); } public double MeanFractionalDistance { get { return meanEvaluator.Mean ; } } #region IMultiVariateOnlineEvaluator Members public double Value { get { return MeanFractionalDistance; } } public void Add(IEnumerable original, IEnumerable estimated) { var originalEnumerator = original.GetEnumerator(); var estimatedEnumerator = estimated.GetEnumerator(); double sum = 0.0; while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { sum += Math.Pow(Math.Abs(originalEnumerator.Current - estimatedEnumerator.Current), 1.0 / d); } if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext()) { throw new ArgumentException("Number of elements in original and estimated does not match."); } double fracDist = Math.Pow(sum, d); meanEvaluator.Add(fracDist); } public void Reset() { meanEvaluator.Reset(); } #endregion } }