コード例 #1
0
        //Execute the algorithm
        public static void run_algorithm(int num_entities, double min_support, int maximal_gap, string file_path)
        {
            string filename = file_path + ".csv";
            //Output file
            string outfile = file_path + "-support-" + min_support + "-maxgap-" + maximal_gap + ".txt";
            double dsp     = min_support / 100.0;
            long   dt1     = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            //Run Algorithm
            ZMiner.runZMiner(filename, dt1, outfile, num_entities, dsp, 0, maximal_gap, int.MaxValue, int.MaxValue, true, true);
            long dt2  = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            long diff = dt2 - dt1;

            Console.WriteLine("Finished Running: support - " + min_support + " gap - " + maximal_gap);
            Console.WriteLine(diff);
            Thread.Sleep(2000);
            string[] to_write = new string[1];
            to_write[0] = diff + "";
            File.WriteAllLines(outfile + "-stats.txt", to_write);
            //outputConverter(outfile);
        }
コード例 #2
0
                                                                                                      List <Tuple <List <EventInterval>, int> > > > > > > runZMiner(string dataname, long t1, string output, int num_entities,
                                                                                                                                                                    double support, double epsilon, double gap, double timeout = int.MaxValue, int max_level = int.MaxValue,
                                                                                                                                                                    bool printTIRPs = true, bool printInstances = true)
        {
            FileStream fileStream = new FileStream(output, FileMode.Create, FileAccess.Write);

            fileStream.Close();
            string[] args = { support + "",   epsilon + "",    gap + "", timeout + "",
                              max_level + "", printTIRPs + "", printInstances + "" };
            string   filename = dataname.Split("/")[dataname.Split("/").Length - 1].Split(".")[0];

            Console.WriteLine("TEST WITH: " + dataname + " DATASET");
            Tuple <int, int, int, double, double, Dictionary <string, List <Tuple <int, int, int> > > > tup = Utils.preprocess(dataname);
            int    tseq    = tup.Item1;
            int    tdis    = tup.Item2;
            int    tintv   = tup.Item3;
            double aintv   = tup.Item4;
            double avgtime = tup.Item5;
            Dictionary <string, List <Tuple <int, int, int> > > dataset = tup.Item6;

            Console.WriteLine("TOTAL SEQUENCE: " + tseq);
            Console.WriteLine("TOTAL DISTINCT EVENTS: " + tdis);
            Console.WriteLine("TOTAL INTERVALS: " + tintv);
            Console.WriteLine("AVERAGE INTERVAL PER SEQ: " + aintv);
            Console.WriteLine("AVERAGE TIMESPAN: " + avgtime);
            Console.WriteLine("TEST WITH " + dataname + " DATASET");
            Database database = new Database(dataset);
            Dictionary <string, double> constraints = Utils.makeConstraints(args, dataset);
            ZMiner algorithm = new ZMiner(database, constraints, t1);

            Console.WriteLine("########## Z-MINER ##########");
            Console.WriteLine("1-1. MINIMUM SUPPORT: " + algorithm.constraints["minSup"]);
            Console.WriteLine("1-2. EPSILON CONSTRAINT: " + algorithm.constraints["epsilon"]);
            Console.WriteLine("1-3. GAP CONSTRAINT: " + algorithm.constraints["gap"]);
            Console.WriteLine("1-4. TIMEOUT: " + algorithm.constraints["timeoutseconds"]);
            Console.WriteLine("1-5. LEVEL: " + algorithm.constraints["level"]);
            Console.WriteLine("2. NUMBER OF E-SEQUENCES: " + algorithm.database.getSequences().Count);
            if (algorithm.constraints["minSup"] != 0)
            {
                algorithm.pruneWithMinSup();
            }
            algorithm.createZTable(output);
            algorithm.FLk.Add(3, new Dictionary <List <int>, Dictionary <string,
                                                                         Dictionary <string, List <Tuple <List <EventInterval>, int> > > > >(new IntListEqualityComparer()));
            foreach (List <int> pair in algorithm.FL2[2].Keys)
            {
                foreach (string Rpair in algorithm.FL2[2][pair].Keys)
                {
                    Console.WriteLine(pair[0] + "," + pair[1] + "," + Rpair);
                    algorithm.growZ(pair, Rpair, 3, output);
                }
            }
            if (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > algorithm.timeout)
            {
                Console.WriteLine("Reached timeout");
                return(new Tuple <int, int, long, bool, Dictionary <int, Dictionary <List <int>,
                                                                                     Dictionary <string, Dictionary <string, Dictionary <EventInterval, List <EventInterval> > > > > >,
                                  Dictionary <int, Dictionary <List <int>, Dictionary <string, Dictionary <string,
                                                                                                           List <Tuple <List <EventInterval>, int> > > > > > >(0, 0,
                                                                                                                                                               DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, true, null, null));
            }
            long t2 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            Console.WriteLine("3. TOTAL COMPARISON COUNTS: " + algorithm.comparisoncount);
            Console.WriteLine("4. TOTAL FREQUENT ARRANGEMENTS: " + algorithm.totalfrequency);
            Console.WriteLine("5. TOTAL TIME CONSUMED: " + (t2 - algorithm.t1));
            return(new Tuple <int, int, long, bool, Dictionary <int, Dictionary <List <int>, Dictionary <string,
                                                                                                         Dictionary <string, Dictionary <EventInterval, List <EventInterval> > > > > >, Dictionary <int,
                                                                                                                                                                                                    Dictionary <List <int>, Dictionary <string, Dictionary <string,
                                                                                                                                                                                                                                                            List <Tuple <List <EventInterval>, int> > > > > > >(algorithm.comparisoncount, algorithm.totalfrequency,
                                                                                                                                                                                                                                                                                                                t2 = algorithm.t1, false, algorithm.FL2, algorithm.FLk));
        }