Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/20/18 13:52:40 (5 years ago)
Author:
pfleck
Message:

#2845 reverted the last merge (r16307) because some revisions were missing

Location:
branches/2845_EnhancedProgress
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2845_EnhancedProgress

  • branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis

  • branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4

    • Property svn:mergeinfo deleted
  • branches/2845_EnhancedProgress/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/EuclideanDistance.cs

    r16307 r16308  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131  [Item("EuclideanDistance", "A norm function that uses Euclidean distance")]
    3232  public class EuclideanDistance : DistanceBase<IEnumerable<double>> {
     33
    3334    #region HLConstructors & Cloning
    3435    [StorableConstructor]
    3536    protected EuclideanDistance(bool deserializing) : base(deserializing) { }
    3637    protected EuclideanDistance(EuclideanDistance original, Cloner cloner) : base(original, cloner) { }
    37     public override IDeepCloneable Clone(Cloner cloner) {
    38       return new EuclideanDistance(this, cloner);
    39     }
     38    public override IDeepCloneable Clone(Cloner cloner) { return new EuclideanDistance(this, cloner); }
    4039    public EuclideanDistance() { }
    4140    #endregion
    4241
    43     public static double GetDistance(IEnumerable<double> point1, IEnumerable<double> point2) {
    44       using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator()) {
    45         var sum = 0.0;
    46         while (p1Enum.MoveNext() & p2Enum.MoveNext()) {
    47           var d = p1Enum.Current - p2Enum.Current;
    48           sum += d * d;
    49         }
    50         if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Euclidean distance not defined on vectors of different length");
    51         return Math.Sqrt(sum);
     42    public static double GetDistance(IReadOnlyList<double> point1, IReadOnlyList<double> point2) {
     43      if (point1.Count != point2.Count) throw new ArgumentException("Euclidean distance not defined on vectors of different length");
     44      var sum = 0.0;
     45      for (var i = 0; i < point1.Count; i++) {
     46        var d = point1[i] - point2[i];
     47        sum += d * d;
    5248      }
     49
     50      return Math.Sqrt(sum);
    5351    }
    5452
    5553    public override double Get(IEnumerable<double> a, IEnumerable<double> b) {
    56       return GetDistance(a, b);
     54      return GetDistance(a.ToArray(), b.ToArray());
    5755    }
    5856  }
Note: See TracChangeset for help on using the changeset viewer.