Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/15/17 10:29:40 (8 years ago)
Author:
gkronber
Message:

#2699,#2700
merged r14862, r14863, r14911, r14936, r15156, r15157, r15158, r15164, r15169, r15207:15209, r15225, r15227, r15234, r15248 from trunk to stable

Location:
stable
Files:
1 deleted
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/CosineDistance.cs

    r15209 r15249  
    3030
    3131  /// <summary>
    32   /// The angluar distance as defined as a normalized distance measure dependent on the angle between two vectors.
    33   /// It is designed for vectors with all positive coordinates.
     32  /// The angular distance as defined as a normalized distance measure dependent on the angle between two vectors.
    3433  /// </summary>
    3534  [StorableClass]
    36   [Item("CosineDistance", "The angluar distance as defined as a normalized distance measure dependent on the angle between two vectors.\nIt is designed for vectors with all positive coordinates")]
     35  [Item("CosineDistance", "The angular distance as defined as a normalized distance measure dependent on the angle between two vectors.")]
    3736  public class CosineDistance : DistanceBase<IEnumerable<double>> {
    3837
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/DistanceBase.cs

    r14767 r15249  
    2020#endregion
    2121
     22using System.Collections;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    2930  public abstract class DistanceBase<T> : Item, IDistance<T> {
    3031
    31     #region HLConstructors & Boilerplate
     32    #region HLConstructors & Cloning
    3233    [StorableConstructor]
    3334    protected DistanceBase(bool deserializing) : base(deserializing) { }
     
    4243    }
    4344
    44     private class DistanceComparer : IComparer<T> {
     45    public double Get(object x, object y) {
     46      return Get((T)x, (T)y);
     47    }
     48
     49    public IComparer GetDistanceComparer(object item) {
     50      return new DistanceComparer((T)item, this);
     51    }
     52
     53    private class DistanceComparer : IComparer<T>, IComparer {
    4554      private readonly T item;
    4655      private readonly IDistance<T> dist;
     
    5463        return dist.Get(x, item).CompareTo(dist.Get(y, item));
    5564      }
     65
     66      public int Compare(object x, object y) {
     67        return Compare((T)x, (T)y);
     68      }
    5669    }
    5770  }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/EuclideanDistance.cs

    r14784 r15249  
    3232  public class EuclideanDistance : DistanceBase<IEnumerable<double>> {
    3333
    34     #region HLConstructors & Boilerplate
     34    #region HLConstructors & Cloning
    3535    [StorableConstructor]
    3636    protected EuclideanDistance(bool deserializing) : base(deserializing) { }
     
    4040    #endregion
    4141
    42     public static double GetDistance(double[] point1, double[] point2) {
    43       if (point1.Length != point2.Length) throw new ArgumentException("Euclidean distance not defined on vectors of different length");
    44       return Math.Sqrt(point1.Zip(point2, (a1, b1) => (a1 - b1) * (a1 - b1)).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;
     48      }
     49
     50      return Math.Sqrt(sum);
    4551    }
    4652
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/ManhattanDistance.cs

    r14911 r15249  
    3232  public class ManhattanDistance : DistanceBase<IEnumerable<double>> {
    3333
    34     #region HLConstructors & Boilerplate
     34    #region HLConstructors & Cloning
    3535    [StorableConstructor]
    3636    protected ManhattanDistance(bool deserializing) : base(deserializing) { }
     
    4747    public static double GetDistance(double[] point1, double[] point2) {
    4848      if (point1.Length != point2.Length) throw new ArgumentException("Manhattan distance not defined on vectors of different length");
    49       return point1.Zip(point2, (a1, b1) => Math.Abs(a1 - b1)).Sum();
     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;
    5053    }
    5154
Note: See TracChangeset for help on using the changeset viewer.