- Timestamp:
- 07/12/17 15:17:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/VantagePointTree.cs
r14862 r15207 68 68 /// </summary> 69 69 /// <typeparam name="T"></typeparam> 70 public class VantagePointTree<T> : IVantagePointTree<T> { 71 #region properties 70 public class VantagePointTree<T> { 72 71 private readonly List<T> items; 73 72 private readonly Node root; 74 73 private readonly IDistance<T> distance; 75 #endregion76 74 77 75 public VantagePointTree(IDistance<T> distance, IEnumerable<T> items) : base() { … … 82 80 } 83 81 82 /// <summary> 83 /// provides the k-nearest neighbours to a certain target element 84 /// </summary> 85 /// <param name="target">The target element</param> 86 /// <param name="k">How many neighbours</param> 87 /// <param name="results">The nearest neighbouring elements</param> 88 /// <param name="distances">The distances form the target corresponding to the neighbouring elements</param> 84 89 public void Search(T target, int k, out IList<T> results, out IList<double> distances) { 85 90 var heap = new PriorityQueue<double, IndexedItem<double>>(double.MaxValue, double.MinValue, k); 86 doubletau = double.MaxValue;91 var tau = double.MaxValue; 87 92 Search(root, target, k, heap, ref tau); 88 93 var res = new List<T>(); 89 94 var dist = new List<double>(); 90 95 while (heap.Size > 0) { 91 res.Add(items[heap.PeekMinValue().Index]); 96 res.Add(items[heap.PeekMinValue().Index]);// actually max distance 92 97 dist.Add(heap.PeekMinValue().Value); 93 98 heap.RemoveMin(); 94 99 } 95 res.Reverse(); 100 res.Reverse(); 96 101 dist.Reverse(); 97 102 results = res; … … 104 109 if (dist < tau) { 105 110 if (heap.Size == k) heap.RemoveMin(); // remove furthest node from result list (if we already have k results) 106 heap.Insert(-dist, new IndexedItem<double>(node.index, dist)); 111 heap.Insert(-dist, new IndexedItem<double>(node.index, dist)); 107 112 if (heap.Size == k) tau = heap.PeekMinValue().Value; 108 113 }
Note: See TracChangeset
for help on using the changeset viewer.