Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Evaluators/OnlineMultiVariateEvaluator.cs @ 9420

Last change on this file since 9420 was 4555, checked in by gkronber, 14 years ago

Improved time series evaluators. #1142

File size: 2.2 KB
Line 
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 OnlineMultiVariateEvaluator<T> : IMultiVariateOnlineEvaluator where T : IOnlineEvaluator, new() {
13    private List<T> evaluators;
14
15    public OnlineMultiVariateEvaluator() {
16
17      Reset();
18    }
19
20    #region IMultiVariateOnlineEvaluator Members
21    public double Value {
22      get { return evaluators.Sum(e => e.Value); }
23    }
24
25    public void Add(IEnumerable<double> original, IEnumerable<double> estimated) {
26      var originalEnumerator = original.GetEnumerator();
27      var estimatedEnumerator = estimated.GetEnumerator();
28      // first call of Add() => initialize evaluators list
29      if (evaluators == null) {
30        evaluators = new List<T>();
31        while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
32          T evaluator = new T();
33          evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current);
34          evaluators.Add(evaluator);
35        }
36      } else {
37        // subsequent call of Add(): for each evaluator a value must be added
38        int i = 0;
39        while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext() && i < evaluators.Count) {
40          evaluators[i++].Add(originalEnumerator.Current, estimatedEnumerator.Current);
41        }
42        if (i < evaluators.Count) {
43          throw new ArgumentException("Number of elements in original and estimated does not match the number of elements in previously added vectors.");
44        }
45      }
46      if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext()) {
47        throw new ArgumentException("Number of elements in original and estimated does not match.");
48      }
49    }
50
51    public void Reset() {
52      if (evaluators != null) {
53        foreach (var evaluator in evaluators)
54          evaluator.Reset();
55      }
56    }
57
58    #endregion
59  }
60}
Note: See TracBrowser for help on using the repository browser.