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/ManhattanDistance.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("ManhattanDistance", "A distance function that uses block distance")]
    3232  public class ManhattanDistance : DistanceBase<IEnumerable<double>> {
     33
    3334    #region HLConstructors & Cloning
    3435    [StorableConstructor]
     
    4445    #endregion
    4546
    46     public static double GetDistance(IEnumerable<double> point1, IEnumerable<double> point2) {
    47       using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator()) {
    48         var sum = 0.0;
    49         while (p1Enum.MoveNext() & p2Enum.MoveNext())
    50           sum += Math.Abs(p1Enum.Current - p2Enum.Current);
    51         if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Manhattan distance not defined on vectors of different length");
    52         return sum;
    53       }
     47    public static double GetDistance(double[] point1, double[] point2) {
     48      if (point1.Length != point2.Length) throw new ArgumentException("Manhattan distance not defined on vectors of different length");
     49      var sum = 0.0;
     50      for (var i = 0; i < point1.Length; i++)
     51        sum += Math.Abs(point1[i] + point2[i]);
     52      return sum;
    5453    }
    5554
    5655    public override double Get(IEnumerable<double> a, IEnumerable<double> b) {
    57       return GetDistance(a, b);
     56      return GetDistance(a.ToArray(), b.ToArray());
    5857    }
    5958  }
Note: See TracChangeset for help on using the changeset viewer.