예제 #1
0
        /// <summary>
        /// Runs karma for all entites up to a certain entity id
        /// </summary>
        /// <param name="to_eIdx">Entity id max non-inclusive</param>
        public void RunKarma(int to_eIdx)
        {
            int index = 0;

            int[] countOfEachRelation = new int[7];
            for (int eIdx = 0; eIdx < to_eIdx && eIdx < entityTISs.Count() && eIdx < entitieSize; eIdx++)
            {
                List <SymbolicTimeInterval> tisList = entityTISs[entitiesVec[eIdx]];
                for (int ti1Idx = 0; ti1Idx < tisList.Count; ti1Idx++) // time interval 1
                {
                    SymbolicTimeInterval firsTis = tisList.ElementAt(ti1Idx);
                    AddSymbol(eIdx, firsTis, ref index);                            // update symbol entity support
                    for (int ti2Idx = ti1Idx + 1; ti2Idx < tisList.Count; ti2Idx++) // time interval 2
                    {
                        SymbolicTimeInterval secondTis = tisList.ElementAt(ti2Idx);
                        //if (firsTis.symbol != secondTis.symbol)
                        //{
                        AddSymbol(eIdx, secondTis, ref index);     // DONT update symbol entity support
                        int relation = KLC.WhichRelation(firsTis, secondTis, epsilon, max_gap, relations_style);
                        if (relation > -1)
                        {
                            countOfEachRelation[relation]++;
                            karma.AddStiToTindexRelationEntryBySymbols(Symbols[firsTis.symbol].SymbolINDEX, Symbols[secondTis.symbol].SymbolINDEX, relation, eIdx, firsTis, secondTis);
                        }
                        else
                        {
                            break;
                        }
                        //}
                    }
                }
            }
        }
예제 #2
0
        //Index one entity's sti series
        public void indexEntitySTIs(int eIdx, ref int index, ref int[] relStat, List <int> tonceptIds)
        {
            List <SymbolicTimeInterval> tisList = entityTISs[entitiesVec[eIdx]];

            for (int ti1Idx = 0; ti1Idx < tisList.Count; ti1Idx++)
            {
                SymbolicTimeInterval firsTis = tisList.ElementAt(ti1Idx);
                if (tonceptIds == null || tonceptIds.Contains(firsTis.symbol))
                {
                    addToncept(eIdx, firsTis, ref index); // update toncept entity support
                    //karma..
                    for (int ti2Idx = ti1Idx + 1; ti2Idx < tisList.Count; ti2Idx++)
                    {
                        SymbolicTimeInterval secondTis = tisList.ElementAt(ti2Idx);
                        if (tonceptIds == null || tonceptIds.Contains(secondTis.symbol))
                        {
                            //if (firsTis.symbol != secondTis.symbol)
                            //{
                            addToncept(eIdx, secondTis, ref index);     // DONT update toncept entity support
                            int relation = KLC.WhichRelation(firsTis, secondTis, epsilon, max_gap, relations_style);
                            if (relation > -1)
                            {
                                relStat[relation]++;
                                indexTISPair(firsTis, secondTis, relation, eIdx);
                            }
                            else
                            {
                                break;
                            }
                            //}
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets all suporting instances for the newly extended TIRP
        /// </summary>
        /// <param name="tNew"></param>
        /// <param name="tinstances"></param>
        /// <returns></returns>
        private bool SearchSupportingInstances(ref TIRP tNew, List <StiInstance> tinstances)
        {
            bool seedRelEmpty = true;

            bool[] entitieSupport = new bool[KLC.NUM_OF_ENTITIES];
            int    topRelIdx = ((tNew.size - 1) * (tNew.size - 2) / 2), seedRelIdx = (tNew.size * (tNew.size - 1) / 2 - 1);
            int    seedRelation = tNew.rels[seedRelIdx];
            int    tncptLst = tNew.symbols[tNew.size - 2], tncptNew = tNew.symbols[tNew.size - 1];

            int lsTncptIdx = karma.getSymbolIndexByID(tncptLst);
            int nxTncptIdx = karma.getSymbolIndexByID(tncptNew);

            for (int tins = 0; tins < tinstances.Count; tins++)
            {
                seedRelEmpty = false;
                //Get all intervals where the relation takes place for the last STI added to the TIRP
                List <SymbolicTimeInterval> tisList = karma.karma.GetStisInRelationWithKeyStiForEntityByRelationAndSymbols(lsTncptIdx, nxTncptIdx, seedRelation, tinstances[tins].entityIdx, tinstances[tins].sti[tNew.size - 2]);
                if (tisList != null)
                {
                    //Add all the found instances to the TIRP
                    for (int i = 0; (karma.getHS1() == false && i < tisList.Count) || (karma.getHS1() == true && i < 1); i++)
                    {
                        int relIdx = 0;
                        for (relIdx = topRelIdx; relIdx < seedRelIdx; relIdx++)
                        {
                            if (!KLC.checkRelationAmongTwoTIs(tinstances[tins].sti[relIdx - topRelIdx], tisList.ElementAt(i), tNew.rels[relIdx], karma.getEpsilon(), karma.getMaxGap()))
                            {
                                break;
                            }
                        }
                        if (relIdx == seedRelIdx)
                        {
                            StiInstance newIns = new StiInstance(tNew.size, tinstances[tins].sti, tisList.ElementAt(i), tinstances[tins].entityIdx);
                            tNew.AddEntity(newIns.entityIdx);
                            tNew.tinstancesList.Add(newIns);
                        }
                    }
                }
            }
            return(seedRelEmpty);
        }
예제 #4
0
        //constructor for karma
        public Karma(int setEpsilon, int setMaxGap, double setMinVerSup, string dsFilePath, bool setHS1, int entitieSizeLimit = KLC.NUM_OF_ENTITIES)
        {
            //set variables
            epsilon = setEpsilon;
            max_gap = setMaxGap;
            HS1     = setHS1;

            //read input
            KLC.read_tids_file(dsFilePath, ref entityTISs, ref Symbols);

            entitieSize = entityTISs.Count;
            min_ver_sup = ((double)setMinVerSup / 100) * entitieSize;
            entitiesVec = new int[entitieSize];
            for (int eIdx = 0; eIdx < entitieSize; eIdx++)
            {
                entitiesVec[eIdx] = entityTISs.Keys.ElementAt(eIdx);
            }
            karma = new Tindex(entitieSize, relations_style);
            //load transition table
            KLC.LoadTransitionTableALLEN7(ref transition);
            RunKarma(entitieSizeLimit);
        }
예제 #5
0
        // For Single KarmaLego
        public Dharma(int setMaxTirpSize, bool setFullDics, int dharmaIndexType, int frstEntIdx, int lstEntIdx, int setForBackWards, int setRelationStyle, int setEpsilon, int setMaxGap, string dsFilePath, bool runKarma, List <int> tonceptIds)
        {
            mxAccsCounter   = 0;
            forBackWards    = setForBackWards;
            relations_style = setRelationStyle;
            epsilon         = setEpsilon;
            max_gap         = setMaxGap;
            HS1             = false;
            maxTirpSize     = setMaxTirpSize;

            KLC.read_tids_file(dsFilePath, ref entityTISs, ref toncepts);

            entitieSize = entityTISs.Count;
            min_ver_sup = 0; // ((double)setMinVerSup / 100) * entitieSize;
            entitiesVec = new int[entitieSize];
            for (int eIdx = 0; eIdx < entitieSize; eIdx++)
            {
                entitiesVec[eIdx] = entityTISs.Keys.ElementAt(eIdx);
            }

            ////twoSizedTIRPsMatrix = new twoSizedTIRPsMATRIXEntry[KLC.NUM_OF_SYMBOLS][]; //initialize keys vector
            ////for (int i = 0; i < KLC.NUM_OF_SYMBOLS; i++)
            ////    twoSizedTIRPsMatrix[i] = new twoSizedTIRPsMATRIXEntry[KLC.NUM_OF_SYMBOLS]; // initialize val vector
            //karma = new tindex(entitieSize, relations_style);
            dharmaIdx = new dharmaIndex(dharmaIndexType, entitieSize, relations_style);//, setFullDics);
            //print = setPrint;
            //trans = seTrans;
            if (trans)
            {
                KLC.LoadTransitionTableALLEN7(ref transition);//load transition table
            }

            if (forBackWards == KLC.backwardsMining)
            {
                logiRelsIndxs          = new int[KLC.MAX_TIRP_TONCEPTS_SIZE][];
                logiRelsIndxs[0 /*3*/] = new int[1] {
                    0
                };
                logiRelsIndxs[1 /*3*/] = new int[3] {
                    2, 1, 0
                };
                logiRelsIndxs[2 /*4*/] = new int[6] {
                    5, 4, 2, 3, 1, 0
                };
                logiRelsIndxs[3 /*5*/] = new int[10] {
                    9, 8, 5, 7, 4, 2, 6, 3, 1, 0
                };
                logiRelsIndxs[4 /*6*/] = new int[15] {
                    14, 13, 9, 12, 8, 5, 11, 7, 4, 2, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[5 /*7*/] = new int[21] {
                    20, 19, 14, 18, 13, 9, 17, 12, 8, 5, 16, 11, 7, 4, 2, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[6 /*8*/] = new int[28] {
                    27, 26, 20, 25, 19, 14, 24, 18, 13, 9, 23, 17, 12, 8, 5, 22, 16, 11, 7, 4, 2, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[7 /*9*/] = new int[36] {
                    35, 34, 27, 33, 26, 20, 32, 25, 19, 14, 31, 24, 18, 13, 9, 30, 23, 17, 12, 8, 5, 29, 22, 16, 11, 7, 4, 2, 28, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[8 /*9*/] = new int[45] {
                    44, 43, 35, 42, 34, 27, 41, 33, 26, 20, 40, 32, 25, 19, 14, 39, 31, 24, 18, 13, 9, 38, 30, 23, 17, 12, 8, 5, 37, 29, 22, 16, 11, 7, 4, 2, 36, 28, 21, 15, 10, 6, 3, 1, 0
                };
            }

            if (runKarma == true)
            {
                RunKarmaRun(tonceptIds, frstEntIdx, lstEntIdx);
            }
        }
예제 #6
0
        // For KarmaLego
        public Dharma(int setMaxTirpSize, bool setFulleDics, int dharmaIndexType, bool runKarma, int setForBackWards, int setRelationStyle, int setEpsilon, int setMaxGap, double setMinVerSup, string dsFilePath, bool seTrans, bool setHS1, int setPrint, ref string runTime, int entitieSizeLimit = KLC.NUM_OF_ENTITIES)
        {
            DateTime starTime = DateTime.Now;
            string   timings  = "";

            mxAccsCounter   = 0;
            forBackWards    = setForBackWards;
            relations_style = setRelationStyle;
            epsilon         = setEpsilon;
            max_gap         = setMaxGap;
            HS1             = setHS1;
            maxTirpSize     = setMaxTirpSize;

            KLC.read_tids_file(dsFilePath, ref entityTISs, ref toncepts);

            entitieSize = entityTISs.Count;
            min_ver_sup = ((double)setMinVerSup / 100) * entitieSize;
            entitiesVec = new int[entitieSize];
            for (int eIdx = 0; eIdx < entitieSize; eIdx++)
            {
                entitiesVec[eIdx] = entityTISs.Keys.ElementAt(eIdx);
            }

            //twoSizedTIRPsMatrix = new twoSizedTIRPsMATRIXEntry[KLC.NUM_OF_SYMBOLS][]; //initialize keys vector
            //for (int i = 0; i < KLC.NUM_OF_SYMBOLS; i++)
            //    twoSizedTIRPsMatrix[i] = new twoSizedTIRPsMATRIXEntry[KLC.NUM_OF_SYMBOLS]; // initialize val vector

            //twoSizedTIRPsMatrixWithPsik = new twoSizedTIRPsMATRIXEntry[KLC.NUM_OF_SYMBOLS, KLC.NUM_OF_SYMBOLS];

            //karma = new tindex(entitieSize, relations_style);
            dharmaIdx = new dharmaIndex(dharmaIndexType, entitieSize, relations_style); //, setFulleDics);

            print = setPrint;
            trans = seTrans;
            if (trans)
            {
                KLC.LoadTransitionTableALLEN7(ref transition);//load transition table
            }

            if (forBackWards == KLC.backwardsMining)
            {
                logiRelsIndxs          = new int[KLC.MAX_TIRP_TONCEPTS_SIZE][];
                logiRelsIndxs[0 /*3*/] = new int[1]  {
                    0
                };
                logiRelsIndxs[1 /*3*/] = new int[3]  {
                    2, 1, 0
                };
                logiRelsIndxs[2 /*4*/] = new int[6]  {
                    5, 4, 2, 3, 1, 0
                };
                logiRelsIndxs[3 /*5*/] = new int[10] {
                    9, 8, 5, 7, 4, 2, 6, 3, 1, 0
                };
                logiRelsIndxs[4 /*6*/] = new int[15] {
                    14, 13, 9, 12, 8, 5, 11, 7, 4, 2, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[5 /*7*/] = new int[21] {
                    20, 19, 14, 18, 13, 9, 17, 12, 8, 5, 16, 11, 7, 4, 2, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[6 /*8*/] = new int[28] {
                    27, 26, 20, 25, 19, 14, 24, 18, 13, 9, 23, 17, 12, 8, 5, 22, 16, 11, 7, 4, 2, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[7 /*9*/] = new int[36] {
                    35, 34, 27, 33, 26, 20, 32, 25, 19, 14, 31, 24, 18, 13, 9, 30, 23, 17, 12, 8, 5, 29, 22, 16, 11, 7, 4, 2, 28, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[8 /*9*/] = new int[45] {
                    44, 43, 35, 42, 34, 27, 41, 33, 26, 20, 40, 32, 25, 19, 14, 39, 31, 24, 18, 13, 9, 38, 30, 23, 17, 12, 8, 5, 37, 29, 22, 16, 11, 7, 4, 2, 36, 28, 21, 15, 10, 6, 3, 1, 0
                };
            }

            if (runKarma == true)
            {
                RunKarmaRun(null, 0, entitieSizeLimit);
            }

            DateTime endTime = DateTime.Now;

            runTime = endTime.Subtract(starTime).TotalMilliseconds.ToString(); // ((endTime - starTime).Minutes * 60 + (endTime - starTime).Seconds) + "," + (endTime - starTime).Minutes + ":" + (endTime - starTime).Seconds;
        }
예제 #7
0
        private int KarmaEntity(int eIdx, ref int[] relStat)
        {
            int allGapCnt = 0, counter = 0;
            List <SymbolicTimeInterval> tisList = entityTISs[entitiesKarmaVec[eIdx].entityID];
            double allGap = tisList.ElementAt(tisList.Count - 1).startTime - tisList.ElementAt(0).endTime;

            if (allGap > 365)
            {
                allGapCnt++;
            }
            for (int ti1Idx = 0; ti1Idx < tisList.Count; ti1Idx++)
            {
                addToncept(eIdx, tisList.ElementAt(ti1Idx), ref toncepts);//, true); // update toncept entity support
                for (int ti2Idx = ti1Idx + 1; ti2Idx < tisList.Count; ti2Idx++)
                {
                    //if (tisList.ElementAt(ti1Idx).symbol != tisList.ElementAt(ti2Idx).symbol)
                    //{
                    //addToncept(eIdx, tisList.ElementAt(ti2Idx), ref toncepts);//, false); // DONT update toncept entity support
                    int relation = KLC.WhichRelation(tisList.ElementAt(ti1Idx), tisList.ElementAt(ti2Idx), epsilon, max_gap, relations_style);
                    if (relation > -1)
                    {
                        relStat[relation]++;
                        indexTISPair(tisList.ElementAt(ti1Idx), tisList.ElementAt(ti2Idx), relation, eIdx);
                        counter++;
                        if (relation == 0)
                        {
                            ti2Idx++;
                            while (ti2Idx < tisList.Count)
                            {
                                relation = KLC.WhichRelation(tisList.ElementAt(ti1Idx), tisList.ElementAt(ti2Idx), epsilon, max_gap, relations_style);
                                double gap = tisList.ElementAt(ti2Idx).startTime - tisList.ElementAt(ti1Idx).endTime;
                                if (gap >= max_gap || relation == -1)
                                {
                                    ti2Idx = tisList.Count;
                                    break;
                                }
                                //if (tisList.ElementAt(ti1Idx).symbol != tisList.ElementAt(ti2Idx).symbol)
                                {
                                    //addToncept(eIdx, tisList.ElementAt(ti2Idx), ref toncepts);//, false); // DONT update toncept entity support
                                    relStat[relation]++;
                                    indexTISPair(tisList.ElementAt(ti1Idx), tisList.ElementAt(ti2Idx), relation, eIdx);
                                    counter++;
                                }
                                ti2Idx++;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                    //}
                }
            }
            if (allGap > 365)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
예제 #8
0
        /*
         * public static void runKLD(int legologi, int rels, int epsilon, int maxGap, int minSup, string klFile, bool seTrans, string mXprntD, string outFolder, string outFile, ref string karmaDTime, ref string legoDTime)
         * {
         *  DateTime starTime = DateTime.Now;
         *  KarmaLegoLib.KarmaD kD = new KarmaD(legologi, KLC.RELSTYLE_ALLEN7, epsilon, maxGap, minSup, klFile, seTrans);
         *  kD.RunKarmaRun();
         *  if(mXprntD != "")
         *      kD.printMatrixEntries(mXprntD);
         *  karmaDTime = (DateTime.Now - starTime).Minutes + ":" + (DateTime.Now - starTime).Seconds;
         *  starTime = DateTime.Now;
         *  kD.RunLegoALL(outFolder, seTrans, KLC.KL_PRINT_YES, outFile);
         *  legoDTime = (DateTime.Now - starTime).Minutes + ":" + (DateTime.Now - starTime).Seconds;
         *  starTime = DateTime.Now;
         *  kD = null;
         * }*/

        //public KarmaD(int setKarmaLegoLogi, int setRelationStyle, int setEpsilon, int setMaxGap, int setMinVerSup, string dsFilePath, bool seTrans)
        public KarmE(int setForBackWards, int setRelationStyle, int setEpsilon, int setMaxGap, double setMinVerSup, double setMinHrzSup, string dsFilePath, bool seTrans, bool setHS1, int setPrint, bool setParallel, ref string runTime, int setMaxTIRPSize, int eLast = KLC.NUM_OF_ENTITIES, int eFrst = 0)
        {
            parallel = setParallel;
            //karmalegologi = setKarmaLegoLogi;
            DateTime starTime = DateTime.Now;

            forBackWards    = setForBackWards;
            relations_style = setRelationStyle;
            epsilon         = setEpsilon;
            max_gap         = setMaxGap;
            maxTirpSize     = setMaxTIRPSize;
            //read_tids_file(0, KLC.NUM_OF_ENTITIES, dsFilePath, ref entityTISs, ref toncepts);
            read_tids_file(eFrst, eLast, dsFilePath, ref entityTISs, ref toncepts);
            entitieSize      = entityTISs.Count;
            min_ver_sup      = ((double)setMinVerSup / 100) * entitieSize;
            min_hrz_sup      = setMinHrzSup;
            entitiesKarmaVec = new entityKarma[entitieSize];
            int eIdx = 0;

            foreach (int eKey in entityTISs.Keys)
            {
                entitiesKarmaVec[eIdx++] = new entityKarma(eKey);
            }

            //glblMxRelsVerSupport = new int[KLC.NUM_OF_SYMBOLS][][];
            //glblMxRelsHrzSupport = new int[KLC.NUM_OF_SYMBOLS][][];
            //for (int i = 0; i < KLC.NUM_OF_SYMBOLS; i++)
            //{
            //    glblMxRelsVerSupport[i] = new int[KLC.NUM_OF_SYMBOLS][];
            //    glblMxRelsHrzSupport[i] = new int[KLC.NUM_OF_SYMBOLS][];
            //    for (int j = 0; j < KLC.NUM_OF_SYMBOLS; j++)
            //    {
            //        glblMxRelsVerSupport[i][j] = new int[relations_style];
            //        glblMxRelsHrzSupport[i][j] = new int[relations_style];
            //    }
            //}

            print = setPrint;
            string tesTrans;

            if (seTrans)
            {
                KLC.LoadTransitionTableALLEN7(ref transition);//load transition table
                transition = null;
            }

            if (forBackWards == KLC.backwardsMining)
            {
                logiRelsIndxs          = new int[KLC.MAX_TIRP_TONCEPTS_SIZE][];
                logiRelsIndxs[0 /*2*/] = new int[1]  {
                    0
                };
                logiRelsIndxs[1 /*3*/] = new int[3]  {
                    2, 1, 0
                };
                logiRelsIndxs[2 /*4*/] = new int[6]  {
                    5, 4, 2, 3, 1, 0
                };
                logiRelsIndxs[3 /*5*/] = new int[10] {
                    9, 8, 5, 7, 4, 2, 6, 3, 1, 0
                };
                logiRelsIndxs[4 /*6*/] = new int[15] {
                    14, 13, 9, 12, 8, 5, 11, 7, 4, 2, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[5 /*7*/] = new int[21] {
                    20, 19, 14, 18, 13, 9, 17, 12, 8, 5, 16, 11, 7, 4, 2, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[6 /*8*/] = new int[28] {
                    27, 26, 20, 25, 19, 14, 24, 18, 13, 9, 23, 17, 12, 8, 5, 22, 16, 11, 7, 4, 2, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[7 /*9*/] = new int[36] {
                    35, 34, 27, 33, 26, 20, 32, 25, 19, 14, 31, 24, 18, 13, 9, 30, 23, 17, 12, 8, 5, 29, 22, 16, 11, 7, 4, 2, 28, 21, 15, 10, 6, 3, 1, 0
                };
                logiRelsIndxs[8 /*10*/] = new int[45] {
                    44, 43, 35, 42, 34, 27, 41, 33, 26, 20, 40, 32, 25, 19, 14, 39, 31, 24, 18, 13, 9, 38, 30, 23, 17, 12, 8, 5, 37, 29, 22, 16, 11, 7, 4, 2, 36, 28, 21, 15, 10, 6, 3, 1, 0
                };
            }

            if (runTime != "")
            {
                RunKarmaRun();
            }

            DateTime endTime = DateTime.Now;

            runTime = endTime.Subtract(starTime).TotalMilliseconds.ToString();
        }