Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15487


Ignore:
Timestamp:
11/27/17 10:22:08 (7 years ago)
Author:
bwerth
Message:

#2850 reenabled backwards compatibility; fixed distances

Location:
branches/Weighted TSNE/3.4/TSNE
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/Weighted TSNE/3.4/TSNE/Distances/CosineDistance.cs

    r15479 r15487  
    5050        var length1 = 0.0;
    5151        var length2 = 0.0;
    52         var p1Next = p1Enum.MoveNext();
    53         var p2Next = p2Enum.MoveNext();
    54         while (p1Next && p2Next) {
     52        while (p1Enum.MoveNext() & p2Enum.MoveNext()) {
    5553          double d1 = p1Enum.Current, d2 = p2Enum.Current;
    5654          innerprod += d1 * d2;
    5755          length1 += d1 * d1;
    5856          length2 += d2 * d2;
    59           p1Next = p1Enum.MoveNext();
    60           p2Next = p1Enum.MoveNext();
    6157        }
    6258        var divisor = Math.Sqrt(length1 * length2);
    6359        if (divisor.IsAlmost(0)) throw new ArgumentException("Cosine distance is not defined on vectors of length 0");
    64         if (p2Next || p1Next) throw new ArgumentException("Cosine distance not defined on vectors of different length");
     60        if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Cosine distance not defined on vectors of different length");
    6561        return 1 - innerprod / divisor;
    6662      }
  • branches/Weighted TSNE/3.4/TSNE/Distances/DistanceBase.cs

    r15479 r15487  
    2828namespace HeuristicLab.Algorithms.DataAnalysis {
    2929  [StorableClass]
    30   public abstract class DistanceBase<T> : ParameterizedNamedItem, IDistance<T> {
    31 
     30  public abstract class DistanceBase<T> : Item, IDistance<T> {
    3231    #region HLConstructors & Cloning
    3332    [StorableConstructor]
     
    4443
    4544    public double Get(object x, object y) {
    46       return Get((T)x, (T)y);
     45      return Get((T) x, (T) y);
    4746    }
    4847
    4948    public IComparer GetDistanceComparer(object item) {
    50       return new DistanceComparer((T)item, this);
     49      return new DistanceComparer((T) item, this);
    5150    }
    5251
     
    6564
    6665      public int Compare(object x, object y) {
    67         return Compare((T)x, (T)y);
     66        return Compare((T) x, (T) y);
    6867      }
    6968    }
  • branches/Weighted TSNE/3.4/TSNE/Distances/EuclideanDistance.cs

    r15479 r15487  
    4444      using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator()) {
    4545        var sum = 0.0;
    46         var p1Next = p1Enum.MoveNext();
    47         var p2Next = p2Enum.MoveNext();
    48         while (p1Next && p2Next) {
     46        while (p1Enum.MoveNext() & p2Enum.MoveNext()) {
    4947          var d = p1Enum.Current - p2Enum.Current;
    5048          sum += d * d;
    51           p1Next = p1Enum.MoveNext();
    52           p2Next = p1Enum.MoveNext();
    5349        }
    54         if (p2Next || p1Next) throw new ArgumentException("Euclidean distance not defined on vectors of different length");
     50        if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Euclidean distance not defined on vectors of different length");
    5551        return Math.Sqrt(sum);
    5652      }
  • branches/Weighted TSNE/3.4/TSNE/Distances/ManhattanDistance.cs

    r15479 r15487  
    4747      using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator()) {
    4848        var sum = 0.0;
    49         var p1Next = p1Enum.MoveNext();
    50         var p2Next = p2Enum.MoveNext();
    51         while (p1Next && p2Next) {
     49        while (p1Enum.MoveNext() & p2Enum.MoveNext())
    5250          sum += Math.Abs(p1Enum.Current - p2Enum.Current);
    53           p1Next = p1Enum.MoveNext();
    54           p2Next = p1Enum.MoveNext();
    55         }
    56         if (p2Next || p1Next) throw new ArgumentException("Manhattan distance not defined on vectors of different length");
     51        if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Manhattan distance not defined on vectors of different length");
    5752        return sum;
    5853      }
  • branches/Weighted TSNE/3.4/TSNE/Distances/WeightedEuclideanDistance.cs

    r15479 r15487  
    6565      using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator(), weEnum = weights.GetEnumerator()) {
    6666        var sum = 0.0;
    67         var p1Next = p1Enum.MoveNext();
    68         var p2Next = p2Enum.MoveNext();
    69         var weNext = weEnum.MoveNext();
    70         while (p1Next && p2Next && weNext) {
     67        while (p1Enum.MoveNext() & p2Enum.MoveNext() & weEnum.MoveNext()) {
    7168          var d = p1Enum.Current - p2Enum.Current;
    7269          var w = weEnum.Current;
    7370          sum += d * d * w * w;
    74           p1Next = p1Enum.MoveNext();
    75           p2Next = p2Enum.MoveNext();
    76           weNext = weEnum.MoveNext();
    7771        }
    78         if (weNext) throw new ArgumentException("Weighted Euclidean distance requires a non-null weight vector of length equal to the number of allowed input double variables the compared points");
    79         if (p1Next || p2Next) throw new ArgumentException("Weighted Euclidean distance not defined on vectors of different length");
     72        if (weEnum.MoveNext() || p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Weighted Euclidean distance not defined on vectors of different length");
    8073        return Math.Sqrt(sum);
    8174      }
  • branches/Weighted TSNE/3.4/TSNE/TSNEAlgorithm.cs

    r15485 r15487  
    299299
    300300        if (Normalization) data = NormalizeInputData(data);
    301         state = TSNEStatic<double[]>.CreateState(data, DistanceFunction, random, NewDimensions, Perplexity, Theta, StopLyingIteration, MomentumSwitchIteration, InitialMomentum, FinalMomentum, Eta, RandomInitialization);
     301        var randomInit = Parameters.ContainsKey(RandomInitializationParameterName) ? RandomInitialization : true;
     302        state = TSNEStatic<double[]>.CreateState(data, DistanceFunction, random, NewDimensions, Perplexity, Theta, StopLyingIteration, MomentumSwitchIteration, InitialMomentum, FinalMomentum, Eta, randomInit);
    302303        SetUpResults(allindices);
    303304        iter = 0;
Note: See TracChangeset for help on using the changeset viewer.