Inheritance: MetricDB
Example #1
0
        public static void testLSHV(string listname, string qlist, int Q, int S)
        {
            int porcen=0;
            int numconsult=0;
            Console.WriteLine("<-- Building LSH Multiple Tables -->");
            string indexName = string.Format("Index.LSC.Prueba.xml");
            HammingMLSC I;
            if (!File.Exists(indexName)) {
                I = new HammingMLSC();
                I.SeqBuilder = SequenceBuilders.GetSeqXLB_SArray64 (16);
                if (! (File.Exists(listname + ".header"))) {
                    var A = new AudioSpace();
                    A.Build(listname, 30*3, 3);
                }
                I.Build(indexName,"audio-space",listname,20,1);
            }
            I = IndexLoader.Load(indexName) as HammingMLSC;

            Console.WriteLine("<-- Searching first object -->");
            var aspace = (AudioSpace)I.MainSpace;
            Chronos tiempo = new Chronos();

            foreach (var qname in (new QueryStream(qlist)).Iterate()) {
                numconsult++;
                Console.WriteLine ("<<<--- Inizializing query --->>>");
                tiempo.Start();
                var R = SearchAudio (qname, aspace,I);
                tiempo.End();

                if(R.Count>0){
                    porcen++;
                }
                Console.WriteLine ("qname: {0}",qname.QRaw);
                tiempo.PrintStats("****Tiempo de consulta****");

                var qext = BinaryHammingSpace.ParseAndLoadFromFile(qname.QRaw,false);

                foreach ( var p in R){
                    Console.WriteLine ("docid: {0}, dist: {1}, name: {2}",p.docid, p.dist, aspace.GetNameFromDocId(p.docid));
                    var audio = aspace.GetAudio(p.docid);
                    var distanciaHamming = BinaryHammingSpace.DistMinHamming(audio,qext,aspace.SymbolSize);
                    Console.WriteLine ("***********DocId:  {0}, Distancia BinaryHamming: {1}***************",p.docid, distanciaHamming);
                    Console.WriteLine ("***********Error: {0}%",distanciaHamming/(qext.Count/aspace.SymbolSize * 24)*100);
                }
                Console.WriteLine ("<<<--- Finalizing query --->>>");
            }

            Console.WriteLine("Porcentaje de respuesta: {0}%",porcen*100/numconsult);
        }
Example #2
0
File: Main.cs Project: vfaby/natix
 public void TestLSH_Audio()
 {
     var name = "hamming-files.list.audio.bin";
     var source = "hamming-files.list";
     AudioSpace db0 = null;
     if (!File.Exists (name)) {
         db0 = new AudioSpace();
         db0.Build(source, 30, 3);
         SpaceGenericIO.Save (name, db0, false);
     }
     var db = SpaceGenericIO.Load (name, false);
     if (db0 != null) {
         this.AssertEqualityDB (db0, db);
         db0 = null;
     }
     this.TestLSC_H8(db, name, "queries-hamming");
 }
Example #3
0
        public static IResult SearchAudio(CommandQuery qname,AudioSpace aspace,HammingMLSC I)
        {
            ResultTies Respuesta = new ResultTies(candidatos,false);
            var Rfull = new ResultTies(100,false);
            List<IResult> res_list = new List<IResult>();
            var qext = BinaryHammingSpace.ParseAndLoadFromFile(qname.QRaw,false);

            foreach(var idx in I.Indexes){
                Console.WriteLine("XXXXXX: {0}",qname.QRaw);

                int numqgrams = (qext.Count - aspace.Q) / aspace.SymbolSize;
                double probabilidad = 0.05;
                var acc = new Dictionary<int, double>();

                Rfull = Search1(qext,acc,numqgrams,idx,probabilidad);
                res_list.Add(Rfull);

                int count=0;
                double panterior = -1;
                foreach(var p in Rfull){

                    if(count > 0){
                        if(p.dist - panterior > 10){
                            break;
                        }
                    }
                    count++;
                    panterior = p.dist;

                }

                if(count < 10){
                    foreach(var p in Rfull){
                        Respuesta.Push(p.docid,p.dist);
                        count--;
                        if(count==0)
                            return Respuesta;
                    }
                }
            }

            return Respuesta;    //Eliminar esto para que todo quede normal

            if(Respuesta.Count==0){
                Dictionary<int,double> rcc = new Dictionary<int,double>();
                foreach(var rl in res_list){
                    double dist;
                    foreach(var respair in rl){
                        if(!rcc.TryGetValue(respair.docid,out dist)){
                            rcc[respair.docid] = -1;
                        }
                        else{
                            rcc[respair.docid]--;
                        }
                    }
                }
                Rfull = new ResultTies(100,false);
                foreach(var pair in rcc){
                    Rfull.Push(pair.Key,pair.Value);
                }

                var RFinal = new Result(100, false);

                foreach (var pair in Rfull){
                    var audio = aspace.GetAudio (pair.docid);
                    var dist = BinaryHammingSpace.DistMinHamming (audio, qext,aspace.SymbolSize);
                    RFinal.Push (pair.docid, dist);
                }

                var error = (qext.Count/aspace.SymbolSize * 24) * perror;
                //Console.WriteLine ("Error: {0}",error);

                foreach(var p in RFinal){
                    if(p.dist < error){
                        Respuesta.Push(p.docid,p.dist);
                    }
                    else{
                        break;
                    }

                }

            }
            return Respuesta;
        }