Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/15/18 08:21:48 (6 years ago)
Author:
bwerth
Message:

#2847 made changes to M5 according to review comments

Location:
branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis

  • branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4

    • Property svn:mergeinfo set to (toggle deleted branches)
      /stable/HeuristicLab.Algorithms.DataAnalysis/3.4mergedeligible
      /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4mergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Algorithms.DataAnalysis/3.410321-10322
      /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.413329-15286
      /branches/Benchmarking/sources/HeuristicLab.Algorithms.DataAnalysis/3.46917-7005
      /branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.49070-13099
      /branches/CloningRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.44656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.45471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.45815-6180
      /branches/DataAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.44458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Algorithms.DataAnalysis/3.410085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Algorithms.DataAnalysis/3.46284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Algorithms.DataAnalysis/3.45060
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.DataAnalysis/3.411570-12508
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Algorithms.DataAnalysis/3.411130-12721
      /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis/3.413819-14091
      /branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.48116-8789
      /branches/LogResidualEvaluator/HeuristicLab.Algorithms.DataAnalysis/3.410202-10483
      /branches/NET40/sources/HeuristicLab.Algorithms.DataAnalysis/3.45138-5162
      /branches/ParallelEngine/HeuristicLab.Algorithms.DataAnalysis/3.45175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Algorithms.DataAnalysis/3.47773-7810
      /branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.46350-6627
      /branches/Restructure trunk solution/HeuristicLab.Algorithms.DataAnalysis/3.46828
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Algorithms.DataAnalysis/3.410204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.45370-5682
      /branches/Trunk/HeuristicLab.Algorithms.DataAnalysis/3.46829-6865
      /branches/VNS/HeuristicLab.Algorithms.DataAnalysis/3.45594-5752
      /branches/Weighted TSNE/3.415451-15531
      /branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.45959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.414232-14825
  • branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Distances/CosineDistance.cs

    r15234 r15614  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    2827
    2928namespace HeuristicLab.Algorithms.DataAnalysis {
    30 
    3129  /// <summary>
    3230  /// The angular distance as defined as a normalized distance measure dependent on the angle between two vectors.
     
    3533  [Item("CosineDistance", "The angular distance as defined as a normalized distance measure dependent on the angle between two vectors.")]
    3634  public class CosineDistance : DistanceBase<IEnumerable<double>> {
    37 
    3835    #region HLConstructors & Cloning
    3936    [StorableConstructor]
     
    4845
    4946    #region statics
    50     public static double GetDistance(IReadOnlyList<double> point1, IReadOnlyList<double> point2) {
    51       if (point1.Count != point2.Count) throw new ArgumentException("Cosine distance not defined on vectors of different length");
    52       var innerprod = 0.0;
    53       var length1 = 0.0;
    54       var length2 = 0.0;
    55 
    56       for (var i = 0; i < point1.Count; i++) {
    57         double d1 = point1[i], d2 = point2[i];
    58         innerprod += d1 * d2;
    59         length1 += d1 * d1;
    60         length2 += d2 * d2;
     47    public static double GetDistance(IEnumerable<double> point1, IEnumerable<double> point2) {
     48      using (IEnumerator<double> p1Enum = point1.GetEnumerator(), p2Enum = point2.GetEnumerator()) {
     49        var innerprod = 0.0;
     50        var length1 = 0.0;
     51        var length2 = 0.0;
     52        while (p1Enum.MoveNext() & p2Enum.MoveNext()) {
     53          double d1 = p1Enum.Current, d2 = p2Enum.Current;
     54          innerprod += d1 * d2;
     55          length1 += d1 * d1;
     56          length2 += d2 * d2;
     57        }
     58        var divisor = Math.Sqrt(length1 * length2);
     59        if (divisor.IsAlmost(0)) throw new ArgumentException("Cosine distance is not defined on vectors of length 0");
     60        if (p1Enum.MoveNext() || p2Enum.MoveNext()) throw new ArgumentException("Cosine distance not defined on vectors of different length");
     61        return 1 - innerprod / divisor;
    6162      }
    62       var l = Math.Sqrt(length1 * length2);
    63       if (l.IsAlmost(0)) throw new ArgumentException("Cosine distance is not defined on vectors of length 0");
    64       return 1 - innerprod / l;
    6563    }
    6664    #endregion
    6765    public override double Get(IEnumerable<double> a, IEnumerable<double> b) {
    68       return GetDistance(a.ToArray(), b.ToArray());
     66      return GetDistance(a, b);
    6967    }
    7068  }
Note: See TracChangeset for help on using the changeset viewer.