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
|
Rev | Line | |
---|
[5275] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
| 7 | using HeuristicLab.Problems.DataAnalysis.Evaluators;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 | using HeuristicLab.Parameters;
|
---|
| 10 |
|
---|
| 11 | namespace 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.