当前位置: 首页>>代码示例>>C#>>正文


C# MetricDB类代码示例

本文整理汇总了C#中MetricDB的典型用法代码示例。如果您正苦于以下问题:C# MetricDB类的具体用法?C# MetricDB怎么用?C# MetricDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetricDB类属于命名空间,在下文中一共展示了MetricDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

 /// <summary>
 /// Build the index
 /// </summary>
 public virtual void Build(MetricDB db, int num_centers, Random rand)
 {
     this.DB = db;
     var n = this.DB.Count;
     // randomized has very good performance, even compared with more "intelligent" strategies
     this.node_list = new List<Node> (num_centers);
     var subset = RandomSets.GetRandomSubSet (num_centers, this.DB.Count, rand);
     var H = new HashSet<int> (subset);
     for (int centerID = 0; centerID < num_centers; ++centerID) {
         this.node_list.Add (new Node (subset [centerID]));
     }
     var IDX = new SAT_Distal ();
     IDX.Build (new SampleSpace("", db, subset), rand);
     for (int docID = 0; docID < n; ++docID) {
         if (docID % 1000 == 0) {
             Console.WriteLine ("== Vor {0}/{1}, num_centers: {2}, db: {3}", docID + 1, n, num_centers, db.Name);
         }
         if (H.Contains(docID)) {
             continue;
         }
     //				var near = new Result(1);
     //				for (var centerID = 0; centerID < num_centers; ++centerID) {
     //					var node = this.node_list[centerID];
     //					var d = this.DB.Dist(this.DB[node.refID], this.DB[docID]);
     //					near.Push(centerID, d);
     //				}
     //				var _near = near.First;
         var _near = IDX.SearchKNN (this.DB[docID], 1, new Result (1)).First;
         this.node_list[_near.ObjID].Add(docID, _near.Dist);
     }
 }
开发者ID:sadit,项目名称:natix,代码行数:34,代码来源:Vor.cs

示例2: Build

 public virtual void Build(MetricDB db, int numcenters, int lambda, int seed)
 {
     this.LC_LIST = new LC[lambda];
     LongParallel.For(0, lambda, (int i) => {
         this.BuildOneClosure(this.LC_LIST, i, db, numcenters, new Random(seed+i));
     });
 }
开发者ID:sadit,项目名称:natix,代码行数:7,代码来源:PMI.cs

示例3: EPListMeanPivots

        public EPListMeanPivots(MetricDB DB, int seed, int num_pivs)
        {
            this.Items = null;
            var pivs = new List<EPivot> (32);
            var rand = new Random (seed);
            var n = DB.Count;
            var idxseq = new DynamicSequentialOrdered ();
            idxseq.Build (DB, RandomSets.GetIdentity (DB.Count));
            var tmp_items = new List<ItemPair> (DB.Count);
            int next_piv = rand.Next (0, n);
            for (int i = 0; i < num_pivs; ++i) {
                var varX = 0.0;
                double min_diff = double.MaxValue;
                this.ComputeDistRow (next_piv, idxseq, rand, pivs, tmp_items);
                for (int objID = 0; objID < this.Items.Length; ++objID) {
                    var u = this.Items [objID];
                    var diff = Math.Abs (u.Dist - pivs [u.ObjID].mean);
                    if (diff < min_diff) {
                        min_diff = diff;
                        next_piv = objID;
                    }
                    varX += diff * diff / n;
                }
                ++i;

                Console.WriteLine ("XXXXXX i: {0}, variance: {1}", i, varX);
            }
            this.Pivs = pivs.ToArray ();
            Console.WriteLine("Number of pivots per group: {0}", this.Pivs.Length);
        }
开发者ID:sadit,项目名称:natix,代码行数:30,代码来源:EPListMeanPivots.cs

示例4: Build

 /// <summary>
 /// Build the index
 /// </summary>
 public virtual void Build(MetricDB db, int num_centers, Random rand, SequenceBuilder seq_builder = null)
 {
     this.DB = db;
     var n = this.DB.Count;
     // randomized has very good performance, even compared with more "intelligent" strategies
     this.node_list = new List<Node> (num_centers);
     var subset = RandomSets.GetRandomSubSet (num_centers, this.DB.Count, rand);
     for (int centerID = 0; centerID < num_centers; ++centerID) {
         this.node_list.Add (new Node (subset [centerID]));
     }
     var H = new HashSet<int> (subset);
     for (int docID = 0; docID < n; ++docID) {
         if (docID % 1000 == 0) {
             Console.WriteLine ("== {0} {1}/{2}, num_centers: {3}, db: {4}", this, docID + 1, n, num_centers, db.Name);
         }
         if (H.Contains(docID)) {
             continue;
         }
         var far = new Result(1);
         for (var centerID = 0; centerID < num_centers; ++centerID) {
             var node = this.node_list[centerID];
             var d = this.DB.Dist(this.DB[node.refID], this.DB[docID]);
             far.Push(centerID, -d);
         }
         var _far = far.First;
         this.node_list[_far.docid].Add(docID, -_far.dist);
     }
 }
开发者ID:KeithNel,项目名称:natix,代码行数:31,代码来源:VorFar.cs

示例5: ComputeDistances

 public static List<ItemPair> ComputeDistances(MetricDB db, IEnumerable<int> sample, object piv, List<ItemPair> output, out Stats stats, out int min_objID, out int max_objID)
 {
     if (output == null) {
         output = new List<ItemPair>();
     }
     //var L = new Item[this.DOCS.Count];
     max_objID = min_objID = -1;
     stats = default(Stats);
     stats.min = double.MaxValue;
     stats.max = 0;
     double mean = 0;
     var count = 0;
     foreach (var objID in sample) {
         var dist = db.Dist(piv, db[objID]);
         mean += dist;
         output.Add (new ItemPair (objID, dist));
         if (dist < stats.min) {
             stats.min = dist;
             min_objID = objID;
         }
         if (dist > stats.max) {
             stats.max = dist;
             max_objID = objID;
         }
         ++count;
     }
     stats.mean = mean / count;
     double stddev = 0;
     foreach (var item in output) {
         var m = item.Dist - stats.mean;
         stddev += m * m;
     }
     stats.stddev = Math.Sqrt(stddev / count);
     return output;
 }
开发者ID:sadit,项目名称:natix,代码行数:35,代码来源:DynamicSequential.cs

示例6: Build

 public virtual void Build(MetricDB db, int num_pairs, int maxCandidates = -1)
 {
     this.DB = db;
     this.Fingerprints = new BinQ8HammingSpace (1);
     this.Sample = new SampleSpace("", this.DB, num_pairs * 2);
     this.MaxCandidates = maxCandidates;
     var n = this.DB.Count;
     var A = new byte[n][];
     int pc = this.DB.Count / 100 + 1;
     int advance = 0;
     var create_one = new Action<int> (delegate(int i) {
         var fp = this.GetFP(this.DB[i]);
         A[i] = fp;
         if (advance % pc == 0) {
             Console.WriteLine ("DEBUG {0}  ({1}/{2}), db: {3}, num_pairs: {4}, timestamp: {5}", this, advance, n, db.Name, num_pairs, DateTime.Now);
         }
         advance++;
     });
     ParallelOptions ops = new ParallelOptions();
     ops.MaxDegreeOfParallelism = -1;
     Parallel.For (0, n, create_one);
     foreach (var fp in A) {
         this.Fingerprints.Add( fp );
     }
     var s = new Sequential ();
     s.Build (this.Fingerprints);
     this.InternalIndex = s;
 }
开发者ID:KeithNel,项目名称:natix,代码行数:28,代码来源:HyperplaneFP.cs

示例7: Build

 /// <summary>
 /// Build the index
 /// </summary>
 public virtual void Build(MetricDB db, int bsize, Random rand)
 {
     this.DB = db;
     var n = this.DB.Count;
     // randomized has very good performance, even compared with more "intelligent" strategies
     var dseq = new DynamicSequentialOrdered ();
     dseq.Build (db, rand);
     this.NODES = new List<Node> (n / bsize + 1);
     var L = new List<ItemPair> (n);
     while (dseq.Count > 0) {
         if (this.NODES.Count % 100 == 0) {
             Console.WriteLine ("XXX {0}, bucketSize: {1}, remain {2}/{3}, db: {4}, date-time: {5}",
                                this, bsize, dseq.Count, db.Count, Path.GetFileName(db.Name), DateTime.Now);
         }
         var refID = dseq.GetAnyItem ();
         dseq.Remove (refID);
         L.Clear ();
         dseq.ComputeDistances (this.DB[refID], L);
         var near = new Result(bsize);
         var far = new Result (1);
         dseq.AppendKExtremes (near, far, L);
         var node = new Node (refID);
         this.NODES.Add (node);
         dseq.Remove (near);
         foreach (var p in near) {
             node.Add(p.ObjID, p.Dist);
         }
     }
 }
开发者ID:sadit,项目名称:natix,代码行数:32,代码来源:LC.cs

示例8: Build

        public void Build(MetricDB db, int k, Index ref_index)
        {
            this.DB = db;
            this.K = k;
            this.R = ref_index;
            int sigma = this.R.DB.Count;
            this.INVINDEX = new List<List<int>> (sigma);
            for (int i = 0; i < sigma; ++i) {
                this.INVINDEX.Add(new List<int>());
            }
            var A = new int[this.DB.Count][];
            int count = 0;
            var compute_one = new Action<int>(delegate(int objID) {
                var u = this.GetKnr(this.DB[objID], this.K);
                A[objID] = u;
                ++count;
                if (count % 1000 == 0) {
                    Console.WriteLine ("==== {0}/{1} db: {2}, k: {3}", count, this.DB.Count, this.DB.Name, k);
                }
            });
            ParallelOptions ops = new ParallelOptions();
            ops.MaxDegreeOfParallelism = -1;
            Parallel.ForEach(new ListGen<int>((int i) => i, this.DB.Count), ops, compute_one);

            for (int objID = 0; objID < this.DB.Count; ++objID) {
                var u = A[objID];
                for (int i = 0; i < this.K; ++i) {
                    this.INVINDEX[u[i]].Add (objID);
                }
            }
        }
开发者ID:KeithNel,项目名称:natix,代码行数:31,代码来源:NappHash.cs

示例9: Build

 /// <summary>
 /// Build the index
 /// </summary>
 public virtual void Build(MetricDB db, Random rand)
 {
     this.DB = db;
     var n = this.DB.Count;
     var items = RandomSets.GetIdentity (n);
     this.root = new Node (items, db, rand, false);
 }
开发者ID:sadit,项目名称:natix,代码行数:10,代码来源:VPTX.cs

示例10: Build

 /// <summary>
 /// Build the index
 /// </summary>
 public virtual void Build(MetricDB db, int num_centers, Random rand, SequenceBuilder seq_builder = null)
 {
     this.DB = db;
     var n = this.DB.Count;
     // randomized has very good performance, even compared with more "intelligent" strategies
     this.node_list = new List<Node> (num_centers);
     var subset = RandomSets.GetRandomSubSet (num_centers, this.DB.Count, rand);
     for (int centerID = 0; centerID < num_centers; ++centerID) {
         this.node_list.Add (new Node (subset [centerID]));
     }
     var H = new HashSet<int> (subset);
     for (int docID = 0; docID < n; ++docID) {
         if (H.Contains(docID)) {
             continue;
         }
         var near = new Result(1);
         var far = new Result(1);
         for (var centerID = 0; centerID < num_centers; ++centerID) {
             var node = this.node_list[centerID];
             var d = this.DB.Dist(this.DB[node.refID], this.DB[docID]);
             near.Push(centerID, d);
             far.Push(centerID, -d);
         }
         var _near = near.First;
         var _far = far.First;
         this.node_list[_near.ObjID].AddNear(docID, _near.Dist);
         this.node_list[_far.ObjID].AddFar(docID, -_far.Dist);
     }
 }
开发者ID:sadit,项目名称:natix,代码行数:32,代码来源:DualVor.cs

示例11: Build

 public virtual void Build(MetricDB original, Index refs, int k)
 {
     this.K = k;
     this.IdxRefs = refs;
     var n = original.Count;
     this.Fingerprints = new List<int[]> (n);
     for (int i = 0; i < n; ++i) {
         this.Fingerprints.Add (null);
     }
     var tasks = Environment.ProcessorCount << 3;
     int blocksize = n / tasks;
     int advance = 0;
     long minElapsedTicks = 20000000; // control the print rate
     long prevTicks = DateTime.Now.Ticks;
     long currTicks;
     var create_block = new Action<int> (delegate(int blockID) {
         var sp = blockID * blocksize;
         var ep = Math.Min (n, sp + blocksize);
         currTicks = DateTime.Now.Ticks;
         if (advance == 0 || currTicks - prevTicks > minElapsedTicks) {
             Console.WriteLine ("KnrFP {0}  ({1}/{2}), db: {3}, num_refs: {4}, K: {5}, timestamp: {6}",
                                this, advance, n, Path.GetFileName(original.Name), this.IdxRefs.DB.Count, this.K, DateTime.Now);
             prevTicks = currTicks;
         }
         for (; sp < ep; ++sp) {
             var fp = this.GetFP(original[sp]);
             this.Fingerprints[sp] = fp;
             advance++;
         }
     });
     LongParallel.For (0, 1 + n / blocksize, create_block);
     Console.WriteLine ("done");
 }
开发者ID:sadit,项目名称:natix,代码行数:33,代码来源:KnrFP.cs

示例12: Build

 public void Build(MetricDB db, Random rand, int num_refs, int K=7, int maxcand=1024, SequenceBuilder seq_builder=null)
 {
     var sample = new SampleSpace ("", db, num_refs, rand);
     var sat = new SAT_Distal ();
     sat.Build (sample, RandomSets.GetRandom());
     this.Build (db, sat, K, maxcand, seq_builder);
 }
开发者ID:KeithNel,项目名称:natix,代码行数:7,代码来源:KnrSeqSearch.cs

示例13: Build

 public virtual void Build(MetricDB original, MetricDB pairs)
 {
     this.Fingerprints = new BinQ8HammingSpace (1);
     this.Pairs = pairs;
     var n = original.Count;
     var A = new byte[n][];
     int blocksize = 1000;
     int pc = original.Count / 100 + 1;
     int advance = 0;
     var create_block = new Action<int> (delegate(int blockID) {
         var sp = blockID * blocksize;
         var ep = Math.Min (n, sp + blocksize);
         for (; sp < ep; ++sp) {
             var fp = this.GetFP(original[sp]);
             A[sp] = fp;
             if (advance % pc == 0) {
                 Console.WriteLine ("DEBUG {0}  ({1}/{2}), db: {3}, num_pairs: {4}, timestamp: {5}", this, advance, n, original.Name, this.Pairs.Count/2, DateTime.Now);
             }
             advance++;
         }
     });
     ParallelOptions ops = new ParallelOptions();
     ops.MaxDegreeOfParallelism = 1;
     Parallel.For (0, 1 + n/blocksize, create_block);
     foreach (var fp in A) {
         this.Fingerprints.Add( fp );
     }
 }
开发者ID:KeithNel,项目名称:natix,代码行数:28,代码来源:HFP.cs

示例14: EstimateQueryStatistics

 public static void EstimateQueryStatistics(MetricDB DB, Random rand, int num_queries, int sample_size, out double mean, out double varY, out double qrad)
 {
     var n = DB.Count;
     var N = num_queries * sample_size;
     mean = 0.0;
     var square_mean = 0.0;
     qrad = 0;
     for (int qID = 0; qID < num_queries; ++qID) {
         var q = DB[ rand.Next(0, n) ];
         var min = double.MaxValue;
         for (int sampleID = 0; sampleID < sample_size; ++sampleID) {
             var u = DB[ rand.Next(0, n) ];
             var d = DB.Dist(q, u);
             mean += d / N;
             square_mean += d * d / N;
             if (d > 0) {
                 min = Math.Min(min, d);
             }
         }
         qrad = Math.Max (min, qrad);
     //				if (qrad == 0) {
     //					qrad = min;
     //				} else {
     //					qrad = (min + qrad) * 0.5;
     //				}
     }
     varY = square_mean - mean * mean;
 }
开发者ID:sadit,项目名称:natix,代码行数:28,代码来源:PivotSelector.cs

示例15: Build

        public void Build(MetricDB db, ANNISetup setup, int num_indexes, int num_tasks = -1)
        {
            // num_build_processors = 1;
            this.DB = db;
            var _rows = new ANNI[num_indexes];

            LongParallel.For (0, num_indexes, (int i) => {
                _rows [i] = new ANNI ();
                _rows [i].InternalBuild (setup, 0, 1.0, db, num_indexes);
            }, num_tasks);
            //			ParallelOptions ops = new ParallelOptions ();
            //			ops.MaxDegreeOfParallelism = num_processors;
            //			Parallel.For (0, num_indexes, ops, (int i) => {
            //				_rows [i] = new ILC ();
            //				_rows [i].Build (db, num_indexes, pivsel);
            //			});

            this.leader = new NANNI();
            this.leader.Build(_rows [0]);

            this.rows = new ANNI[num_indexes - 1];
            for (int i = 1; i < num_indexes; ++i) {
                this.rows[i - 1] = _rows[i];
            }
        }
开发者ID:sadit,项目名称:natix,代码行数:25,代码来源:MANNI.cs


注:本文中的MetricDB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。