Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/26/16 13:07:26 (8 years ago)
Author:
abeham
Message:

#2457: worked on testing recommendation algorithms through x-validation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Clustering/ClusterHelper.cs

    r13794 r13797  
    3131    private List<KeyValuePair<T, double>> excluded;
    3232    private int[] clusterValues;
     33    private int[] rankedMap;
    3334
    3435    private ClusteringHelper(int K) {
     
    5051      var helper = new ClusteringHelper<T>(k);
    5152      helper.Initialize(values, excludeFunc);
    52       if (helper.instances.Count == 0)
     53      if (helper.instances.Count == 0) {
    5354        helper.clusterValues = new int[0];
    54       else CkMeans1D.Cluster(helper.instances.Select(x => x.Value).ToArray(), k, out helper.clusterValues);
     55        helper.rankedMap = new int[k + 1];
     56      } else {
     57        var centroids = CkMeans1D.Cluster(helper.instances.Select(x => x.Value).ToArray(), k, out helper.clusterValues);
     58        helper.rankedMap = new int[k + 1];
     59        var rank = 0;
     60        foreach (var c in centroids) helper.rankedMap[c.Value] = rank++;
     61      }
     62      // excluded are always ranked last
     63      helper.rankedMap[k] = k;
    5564      return helper;
    5665    }
     
    6170    /// <returns></returns>
    6271    public IEnumerable<KeyValuePair<T, Tuple<double, int>>> GetByInstance() {
    63       return GetClustered().Select(x => new KeyValuePair<T, Tuple<double, int>>(x.Item1.Key, Tuple.Create(x.Item1.Value, x.Item2)));
     72      return GetClustered().Select(x => new KeyValuePair<T, Tuple<double, int>>(x.Item1.Key, Tuple.Create(x.Item1.Value, rankedMap[x.Item2])));
    6473    }
    6574
    6675    public IEnumerable<KeyValuePair<int, List<KeyValuePair<T, double>>>> GetByCluster() {
    6776      return GetClustered().GroupBy(x => x.Item2)
    68         .Select(x => new KeyValuePair<int, List<KeyValuePair<T, double>>>(x.Key, x.Select(y => y.Item1).ToList()));
     77        .Select(x => new KeyValuePair<int, List<KeyValuePair<T, double>>>(rankedMap[x.Key], x.Select(y => y.Item1).ToList()));
    6978    }
    7079
Note: See TracChangeset for help on using the changeset viewer.