Exemplo n.º 1
0
        //Execute the algorithm
        public static void run_algorithm(int num_entities, double min_support, int maximal_gap, string file_path)
        {
            Constants.FILE_NAME = file_path + ".csv";
            //Output file
            Constants.OUT_FILE = file_path + "-support-" + min_support + "-maxgap-" + maximal_gap + ".txt";
            double dsp = (num_entities * (min_support / 100.0));

            Constants.MINSUP  = (int)dsp == dsp ? (int)dsp : (int)dsp + 1;
            Constants.MAX_GAP = maximal_gap;
            long dt1 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            //STIs transformation and index construction
            SequenceDB sdb = SequenceDB.createSequencesKLF(Constants.FILE_NAME);

            //Main Algorithm
            TIRPCloAlg.runTIRPClo(sdb);
            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(Constants.OUT_FILE + "-stats.txt", to_write);
            //outputConverter(Constants.OUT_FILE);
        }
Exemplo n.º 2
0
        public static void runTIRPClo(SequenceDB tdb)
        {
            //int count = 0;
            List <string> rks = new List <string>();

            foreach (KeyValuePair <string, MasterTiep> mtiep in TiepsHandler.master_tieps)
            {
                if (mtiep.Value.supporting_entities.Count < Constants.MINSUP)
                {
                    rks.Add(mtiep.Key);
                }
            }
            foreach (string rk in rks)
            {
                TiepsHandler.master_tieps.Remove(rk);
            }
            tdb.filterInfrequentTiepsFromInitialSDB();
            foreach (KeyValuePair <string, MasterTiep> mtiep in TiepsHandler.master_tieps)
            {
                //count++;
                //For each frequent start tiep
                string t = mtiep.Key;
                //Console.WriteLine(t + ", " + count + "/" + TiepsHandler.master_tieps.Count);
                if (t[t.Length - 1] == Constants.ST_REP)
                {
                    //Project the sequence db by the tiep
                    SequenceDB projDB = tdb.first_projectDB(t, mtiep.Value.supporting_entities);
                    extendTIRP(projDB, t, null);
                }
            }
        }
Exemplo n.º 3
0
 //Adds a pattern to the patterns collection
 public static void addPattern(SequenceDB projDB)
 {
     //lock(this)
     //{
     tw.WriteLine(TIRP.getTIRP(projDB));
     //}
 }
Exemplo n.º 4
0
        public static string getTIRP(SequenceDB pp)
        {
            int support = pp.sup;
            int length  = pp.trans_db[0].Item2.tieps.Count / 2;

            STI[] ints  = new STI[length];
            int   index = 0;

            foreach (Tiep t in pp.trans_db[0].Item2.tieps)
            {
                if (t.type == Constants.ST_REP)
                {
                    ints[index] = t.e;
                    index++;
                }
            }
            Array.Sort(ints);
            string res = "";

            res += length + " ";
            for (int i = 0; i < length; i++)
            {
                res = res + ints[i].sym + "-";
            }
            res += " ";
            if (length == 1)
            {
                res += "-.";
            }
            else
            {
                for (int i = 0; i < length; i++)
                {
                    for (int j = i + 1; j < length; j++)
                    {
                        res += getRelation(ints[i], ints[j]) + ".";
                    }
                }
            }
            res += " ";
            res += support + " ";
            res += (length == 1 ? support : Math.Round((double)pp.trans_db.Count / support, 2)) + " ";
            res += pp.trans_db[0].Item1.entity + " " + printIntervals(ints) + " ";
            for (int i = 1; i < pp.trans_db.Count; i++)
            {
                index = 0;
                foreach (Tiep t in pp.trans_db[i].Item2.tieps)
                {
                    if (t.type == Constants.ST_REP)
                    {
                        ints[index] = t.e;
                        index++;
                    }
                }
                Array.Sort(ints);
                res += pp.trans_db[i].Item1.entity + " " + printIntervals(ints) + " ";
            }
            return(res);
        }
Exemplo n.º 5
0
 //Adds a pattern to the patterns collection
 public static void addPattern(SequenceDB projDB)
 {
     using (FileStream fileStream = new FileStream(Constants.OUT_FILE, FileMode.Append, FileAccess.Write)) {
         TextWriter tw = new StreamWriter(fileStream);
         tw.WriteLine(TIRP.getTIRP(projDB));
         tw.Close();
     }
 }
Exemplo n.º 6
0
        //Extend frequent sequences recursively
        private static void extendTIRP(SequenceDB projDB, string last, Dictionary <string, TiepProjector> sf)
        {
            Dictionary <string, TiepProjector> LFs = projDB.tiepsFreq_alt(last, sf);

            //Check if the grown sequence is indeed a TIRP
            if (SequenceDB.allInPairs(projDB.trans_db))
            {
                TIRPsWriter.addPattern(projDB);
            }
            //For each frequent tiep
            foreach (KeyValuePair <string, TiepProjector> z in LFs)
            {
                if (z.Value.sup_entities.Count < Constants.MINSUP)
                {
                    continue;
                }
                SequenceDB alpha_projDB = projDB.projectDB(z.Key, LFs[z.Key]);
                if (alpha_projDB.sup >= Constants.MINSUP)
                {
                    extendTIRP(alpha_projDB, z.Key, LFs);
                }
            }
        }
Exemplo n.º 7
0
        public static void runTIRPClo(SequenceDB tdb)
        {
            TIRPsWriter.setUp();
            int           count = 0;
            List <string> rks   = new List <string>();

            foreach (KeyValuePair <string, MasterTiep> mslc in TiepsHandler.master_tieps)
            {
                if (mslc.Value.supporting_entities.Count < Constants.MINSUP)
                {
                    rks.Add(mslc.Key);
                }
            }
            foreach (string rk in rks)
            {
                TiepsHandler.master_tieps.Remove(rk);
            }
            foreach (KeyValuePair <string, MasterTiep> mslc in TiepsHandler.master_tieps)
            {
                //For each frequent start tiep
                count++;
                string t = mslc.Key;
                Console.WriteLine(count + "/" + TiepsHandler.master_tieps.Count + "/" + t);
                if (t[t.Length - 1] == Constants.ST_REP)
                {
                    //Project the sequence db by the tiep
                    bool is_closed = true;
                    Dictionary <string, List <BETiep> > bets = new Dictionary <string, List <BETiep> >();
                    SequenceDB projDB = tdb.first_projectDB(t, mslc.Value.supporting_entities, ref is_closed, ref bets);
                    //Continue only if it can be extended to form a closed TIRP
                    if (is_closed)
                    {
                        extendTIRP(t, projDB, t, null, ref bets);
                    }
                }
            }
        }
Exemplo n.º 8
0
        //Extend frequent sequences recursively
        private static void extendTIRP(string p, SequenceDB projDB, string last, Dictionary <string,
                                                                                             TiepProjector> sf, ref Dictionary <string, List <BETiep> > bets)
        {
            Dictionary <string, TiepProjector> LFs = projDB.tiepsFreq_alt(last, sf);

            //Only if it forms a TIRP
            if (SequenceDB.allInPairs(projDB.trans_db))
            {
                bool is_closed = true;
                //Verify it is not a closed TIRP
                foreach (KeyValuePair <string, TiepProjector> entry in LFs)
                {
                    if (projDB.sup == entry.Value.sup_entities.Count)
                    {
                        if (entry.Key[entry.Key.Length - 1] == Constants.ST_REP)
                        {
                            is_closed = false;
                            break;
                        }
                        string t = entry.Key[0] == Constants.CO_REP ? entry.Key.Substring(1) : entry.Key;
                        t = t.Replace(Constants.FIN_REP, Constants.ST_REP);
                        if (bets.ContainsKey(t))
                        {
                            if (projDB.checkStFinMatch(bets[t], entry.Value))
                            {
                                is_closed = false;
                                break;
                            }
                        }
                    }
                }
                //Check if the grown sequence is indeed a closed TIRP
                if (is_closed)
                {
                    TIRPsWriter.addPattern(projDB);
                }
            }
            //For each frequent tiep
            foreach (KeyValuePair <string, TiepProjector> z in LFs)
            {
                if (z.Value.sup_entities.Count < Constants.MINSUP)
                {
                    continue;
                }
                //Finishing tieps only
                if (z.Key[z.Key.Length - 1] == Constants.FIN_REP)
                {
                    string tmp = z.Key[0] == Constants.CO_REP ? z.Key.Substring(1) : z.Key;
                    if (projDB.pre_matched.Contains(tmp))
                    {
                        SequenceDB alpha_projDB = projDB.projectDB(z.Key, LFs[z.Key]);
                        if (alpha_projDB.sup >= Constants.MINSUP)
                        {
                            Dictionary <string, List <BETiep> > nbets = new Dictionary <string, List <BETiep> >();
                            //Continue only if it can be extended to form a closed TIRP
                            if (alpha_projDB.back_scan(ref nbets))
                            {
                                extendTIRP(p + z.Key, alpha_projDB, z.Key, LFs, ref nbets);
                            }
                        }
                    }
                }
                else
                {
                    //Starting tieps only
                    SequenceDB alpha_projDB = projDB.projectDB(z.Key, LFs[z.Key]);
                    if (alpha_projDB.sup >= Constants.MINSUP)
                    {
                        Dictionary <string, List <BETiep> > nbets = new Dictionary <string, List <BETiep> >();
                        //Continue only if it can be extended to form a closed TIRP
                        if (alpha_projDB.back_scan(ref nbets))
                        {
                            extendTIRP(p + z.Key, alpha_projDB, z.Key, LFs, ref nbets);
                        }
                    }
                }
            }
        }