- Timestamp:
- 04/26/16 13:07:26 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Clustering/ClusterHelper.cs
r13794 r13797 31 31 private List<KeyValuePair<T, double>> excluded; 32 32 private int[] clusterValues; 33 private int[] rankedMap; 33 34 34 35 private ClusteringHelper(int K) { … … 50 51 var helper = new ClusteringHelper<T>(k); 51 52 helper.Initialize(values, excludeFunc); 52 if (helper.instances.Count == 0) 53 if (helper.instances.Count == 0) { 53 54 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; 55 64 return helper; 56 65 } … … 61 70 /// <returns></returns> 62 71 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]))); 64 73 } 65 74 66 75 public IEnumerable<KeyValuePair<int, List<KeyValuePair<T, double>>>> GetByCluster() { 67 76 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())); 69 78 } 70 79
Note: See TracChangeset
for help on using the changeset viewer.