コード例 #1
0
        public static void TinyImagesExperiment()
        {
            Index <Meta1DataFormat> si = Index <Meta1DataFormat> .Load(Globals.IndexRootDir);

            string          queryFile = @"F:\Exp\TinyImages_256Len_8Word_2KThreshold\_queries\queries.txt";
            List <double[]> queries   = Util.ReadFiletoDoubleList(queryFile, false);

            for (int i = 0; i < queries.Count; ++i)
            {
                queries[i] = Util.NormalizationHandler(Util.DownSample(queries[i], TinyImagesDataLoader.DOWNSAMPLERATE));
                if (queries[i].Length != Globals.TimeSeriesLength)
                {
                    throw new ApplicationException("queries[i].Length != Globals.TimeSeriesLength");
                }

                TermEntry res = si.ApproximateSearch(queries[i]);
                Console.WriteLine("Query:{0} FileName:{1}", i, res.FileName);

                List <Meta1DataFormat> metas = si.ReturnDataFormatFromTermEntry(res);
                double          bsf          = Double.MaxValue;
                Meta1DataFormat bsfMeta      = new Meta1DataFormat();
                foreach (Meta1DataFormat m in metas)
                {
                    double dist = Util.EuclideanDistance(m.GetTimeSeries(), queries[i]);
                    if (dist < bsf)
                    {
                        bsf     = dist;
                        bsfMeta = m;
                    }
                }
                Console.WriteLine("BsfDist:{0} LocMeta:{1}", bsf, bsfMeta.meta);
            }
        }
コード例 #2
0
        public override void LoadIndex()
        {
            ushort     maskval = (ushort)(Math.Log(Globals.SaxMaxCard, 2) - Math.Log(Globals.SaxBaseCard, 2));
            SaxOptions opts    = new SaxOptions(Util.UnsignedShortArray(Globals.SaxWordLength, maskval));

            double[]    tmp = new double[ORIGINAL_LENGTH];
            double[]    ts;
            IDataFormat dl;

            int numFiles = Directory.GetFiles(_dataDir, "*.dat").Length;

            if (numFiles != NUMFILES)
            {
                throw new ApplicationException("numFiles != NUMFILES");
            }

            for (int i = 1; i <= numFiles; ++i)
            {
                string file = Path.Combine(_dataDir, string.Format("i{0}.dat", i));
                if (!File.Exists(file))
                {
                    throw new ApplicationException("!File.Exists(file)");
                }

                using (BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read)))
                {
                    if (br.BaseStream.Length != EXPECTEDBYTES)
                    {
                        throw new ApplicationException("br.BaseStream.Length != ORIGINAL_LENGTH * NUMTSPERFILE * sizeof(double)");
                    }

                    int bytesRead = br.Read(imageBuffer, 0, EXPECTEDBYTES);
                    if (bytesRead != EXPECTEDBYTES)
                    {
                        throw new ApplicationException("EXPECTEDBYTES");
                    }

                    int pos = 0;
                    while (pos < EXPECTEDBYTES)
                    {
                        Buffer.BlockCopy(imageBuffer, pos, tsBuffer, 0, ORIGINAL_LENGTH * sizeof(double));
                        ts = Util.NormalizationHandler(Util.DownSample(Util.ByteArrayToDoubleArray(tsBuffer), DOWNSAMPLERATE));

                        dl = new Meta1DataFormat(processed, ts);
                        _si.Insert(new SaxData(dl, Sax.ArrayToSaxVals(ts, opts)));
                        processed++;

                        if (processed % Globals.FlushTsVal == 0)
                        {
                            _si.FlushEntries();
                        }

                        pos += ORIGINAL_LENGTH * sizeof(double);
                    }
                    Console.WriteLine("{0} read. TsNum:{1}", Path.GetFileName(file), processed);
                }
            }
            _si.FlushEntries();
        }