/// <summary> /// Constructor /// </summary> /// <param name="k"> /// The number of nearest neighbors to search (use int.MaxValue or space.Length for range queries) /// </param> /// <param name="ceiling"> /// Kept results items with radius equalt to the kth NN /// </param> public Result(int k, bool ceiling) { this.kmax = k; this.ceiling_knn = ceiling; if (this.ceiling_knn) { this.overflow = new List<ResultPair> (); } this.dmax = MaxValue; //this.Pool = new SortedDictionary<ResultPair, int>(); this.pairset = new SkipList2<ResultPair> (0.5, (ResultPair x, ResultPair y) => x.CompareTo (y)); }
public EPListRandomPivotsPriorized(MetricDB DB, int seed, int num_pivs) { var n = DB.Count; this.Items = new ItemPair[n]; var pivs = new List<EPivot> (32); var rand = new Random (seed); var pivsel = new PivotSelector (n, rand); var piv = pivsel.NextPivot (); var pivOBJ = DB [piv]; for (int objID = 0; objID < n; ++objID) { var d = DB.Dist(pivOBJ, DB[objID]); this.Items[objID] = new ItemPair(0, d); } double mean, variance; this.Statistics (out mean, out variance); pivs.Add(new EPivot(piv, Math.Sqrt(variance), mean, 0, 0, 0, 0)); var item_cmp = new Comparison<ItemPair>((x,y) => { var diff_x = Math.Abs (x.dist - pivs[x.objID].mean); var diff_y = Math.Abs (y.dist - pivs[y.objID].mean); return diff_x.CompareTo(diff_y); }); var queue = new SkipList2<int> (0.5, (x,y) => item_cmp (this.Items [x], this.Items [y])); for (int objID = 0; objID < n; ++objID) { queue.Add(objID, null); } var max_review = 2 * n / num_pivs; var list = new List<int> (); for (int i = 0; i < num_pivs; ++i) { Console.WriteLine("XXXXXX BEGIN {0} i: {1}", this, i); piv = pivsel.NextPivot(); double piv_mean, piv_variance, qrad; PivotSelector.EstimatePivotStatistics(DB, rand, DB[piv], 256, out piv_mean, out piv_variance, out qrad); var pivID = pivs.Count; pivs.Add(new EPivot(piv, Math.Sqrt(piv_variance), mean, 0, 0, 0, 0)); list.Clear(); for (int s = 0; s < max_review; ++s) { var objID = queue.RemoveFirst(); var d = DB.Dist(DB[objID], pivOBJ); var new_item = new ItemPair(pivID, d); if (item_cmp(new_item, this.Items[objID]) > 0) { this.Items[objID] = new_item; } list.Add (objID); } foreach (var objID in list) { queue.Add(objID, null); } Console.WriteLine("XXXXXX END {0} i: {1}", this, i); } this.Pivs = pivs.ToArray (); Console.WriteLine("Number of pivots per group: {0}", this.Pivs.Length); }
// int alphabet_numbits; public SA_fss(IList<int> text, int alphabet_size) { this.TXT = text; var n = text.Count; // this.alphabet_numbits = ListIFS.GetNumBits(alphabet_size); // this.SA = new int[n]; //this.Char_Offsets = new int[alphabet_size]; this.Char_SA = new SkipListRank<int>[alphabet_size]; var cmp_fun = new Comparison<int> (this.compare_suffixes); for (int i = 0; i < alphabet_size; ++i) { this.Char_SA [i] = new SkipListRank<int> (cmp_fun); } this.SA_pointers = new SkipList2<SkipListRank<int>.DataRank>.Node[n]; for (int suffixID = this.TXT.Count-1; suffixID >= 0; --suffixID) { var c = this.TXT [suffixID]; var list = this.Char_SA [c]; //Console.WriteLine ("=== adding: {0} ({1})", c, Convert.ToChar(c)); var p = list.Add (suffixID); this.SA_pointers [suffixID] = p; } this.A = new int[n+1]; this.A[0] = n; int I = 1; foreach (var SLR in this.Char_SA) { foreach (var data in SLR.SKIPLIST.Traverse()) { this.A[I] = data.Data; ++I; } } this.SA_pointers = null; var stream = new BitStream32(); this.charT = new List<int>(); stream.Write(true); // $ symbol this.charT.Add(0); for (int i = 0; i < alphabet_size; ++i) { var count = this.Char_SA[i].Count; if (count > 0) { stream.Write(true); stream.Write(false, count-1); this.charT.Add(i+1); } this.Char_SA[i] = null; } this.Char_SA = null; this.newF = BitmapBuilders.GetGGMN_wt(12).Invoke(new FakeBitmap(stream)); }
/// <summary> /// API build command /// </summary> public virtual void Build(MetricDB db, IList<int> sample = null) { this.DB = db; if (sample == null) { sample = RandomSets.GetExpandedRange (this.DB.Count); } this.DOCS = new SkipList2<int> (0.5, (x,y) => x.CompareTo (y)); var ctx = new SkipList2<int>.AdaptiveContext(true, this.DOCS.HEAD); foreach (var s in sample) { this.DOCS.Add(s, ctx); } }
/// <summary> /// Constructor /// </summary> public Result(int k) { this.K = k; this.pairset = new SkipList2<ItemPair> (0.5, (ItemPair x, ItemPair y) => x.CompareTo (y)); }