Example #1
0
        private PatternTree Combine2Patterns(PatternTree px, PatternTree py, Depth depth)
        {
            var preList = px.CombinePreorderRepresentation(py);
            var child   = PatternTree.Create(preList, false, MiningParams);

            PatternsExtended.AddPattern(child);
            var curDepth = depth + 1;

            while (--curDepth >= 0)
            {
                if (!px.ContainsDepth(curDepth) || !py.ContainsDepth(curDepth))
                {
                    continue;
                }

                foreach (TreeOccSet tSet in px[curDepth].GetTreeSet())
                {
                    if (!py.ContainsTreeAtDepth(curDepth, tSet.TreeId))
                    {
                        continue;
                    }
                    foreach (RootOcc root in tSet.GetRootSet())
                    {
                        if (!py.ContainsRootIndex(curDepth, tSet.TreeId, root.RootIndex))
                        {
                            continue;
                        }

                        var xOcc = px.GetOccurrence(curDepth, tSet.TreeId, root.RootIndex);
                        var yOcc = py.GetFirstOccAfterSpecifiedIndex(xOcc.Depth, xOcc.TreeId, xOcc.RootIndex, xOcc.RightMostIndex);

                        if (yOcc == null)
                        {
                            continue;
                        }

                        child.AddOccurrence(xOcc.Combine(yOcc));
                    }
                }
            }

            if (!child.IsFrequent)
            {
                return(null);
            }

            PatternsFrequent.AddFrequentPattern(child);

            child.Father = px;
            child.Mother = py;

            px.CheckMatch(child);
            py.CheckMatch(child);

            return(child);
        }
Example #2
0
        /// <summary>
        /// Frequency evaluation of each pattern (either 1-pattern or 2-pattern)
        /// generated after scanning the input transaction data set.
        /// </summary>
        private void EvaluateFrequency()
        {
            foreach (var pt in OnePatterns.Values.Where(pt => pt.IsFrequent))
            {
                PatternsFrequent.AddFrequentPattern(pt);
            }

            foreach (var pt in TwoPatterns.Values.Where(pt => pt.IsFrequent))
            {
                PatternsFrequent.AddFrequentPattern(pt);
            }

            if (MiningParams.MineClosed || MiningParams.MineMaximal)
            {
                EvaluateF1();
            }
        }
Example #3
0
        private void ConnectTwoPatterns(PatternTree f2, PatternTree fpt, Depth depth)
        {
            if (f2.Size != 2)
            {
                throw new InvalidOperationException("The connect pattern must be 2-pattern.");
            }

            var preList = f2.ConnectPreorderRepresentation(fpt);
            var child   = PatternTree.Create(preList, true, MiningParams);

            PatternsExtended.AddPattern(child);

            var depthC = depth + 1; // Depth of connect

            while (--depthC >= 0)
            {
                if (!f2.ContainsDepth(depthC))
                {
                    continue;
                }
                var depthTbc = depthC + 1; // Depth of to be connected
                if (!fpt.ContainsDepth(depthTbc))
                {
                    continue;
                }

                foreach (TreeOccSet tSet in f2[depthC].GetTreeSet())
                {
                    if (!fpt.ContainsTreeAtDepth(depthTbc, tSet.TreeId))
                    {
                        continue;
                    }

                    foreach (RootOcc root in tSet.GetRootSet())
                    {
                        foreach (IOccurrence f2Occ in root.GetRightMostSet())
                        {
                            if (!fpt[depthTbc][tSet.TreeId].RootSet.ContainsKey(f2Occ.SecondIndex))
                            {
                                continue;
                            }

                            var newOcc = f2Occ.Connect(fpt[depthTbc][tSet.TreeId][f2Occ.SecondIndex].FirstOcc);
                            child.AddOccurrence(newOcc);
                        }
                    }
                }
            }

            if (!child.IsFrequent)
            {
                return;
            }
            PatternsFrequent.AddFrequentPattern(child);

            child.Father = f2;
            child.Mother = fpt;

            f2.CheckMatch(child);
            fpt.CheckMatch(child);
        }