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 OnlineMultiVariateEvaluator : IMultiVariateOnlineEvaluator where T : IOnlineEvaluator, new() { private List evaluators; public OnlineMultiVariateEvaluator() { Reset(); } #region IMultiVariateOnlineEvaluator Members public double Value { get { return evaluators.Sum(e => e.Value); } } public void Add(IEnumerable original, IEnumerable estimated) { var originalEnumerator = original.GetEnumerator(); var estimatedEnumerator = estimated.GetEnumerator(); // first call of Add() => initialize evaluators list if (evaluators == null) { evaluators = new List(); while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { T evaluator = new T(); evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); evaluators.Add(evaluator); } } else { // subsequent call of Add(): for each evaluator a value must be added int i = 0; while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext() && i < evaluators.Count) { evaluators[i++].Add(originalEnumerator.Current, estimatedEnumerator.Current); } if (i < evaluators.Count) { throw new ArgumentException("Number of elements in original and estimated does not match the number of elements in previously added vectors."); } } if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext()) { throw new ArgumentException("Number of elements in original and estimated does not match."); } } public void Reset() { if (evaluators != null) { foreach (var evaluator in evaluators) evaluator.Reset(); } } #endregion } }