public List <Rule> StartProcess(double minSupport, CancellationToken token = new CancellationToken())
        {
            rules.Clear();
            this.token      = token;
            this.minSupport = minSupport * dataset.countRows;
            var tidList = new Dictionary <BitSet, HashSet <int> >();

            foreach (var item in dataset.tidList)
            {
                if (item.Value.Count >= minSupport)
                {
                    tidList.Add(item.Key, item.Value);
                }
            }
            tidArr     = new BitSet[tidList.Count];
            tidHashArr = new HashSet <int> [tidList.Count];
            int itemTid = 0;

            foreach (var item in tidList)
            {
                tidArr[itemTid]     = item.Key;
                tidHashArr[itemTid] = item.Value;
                itemTid++;
            }
            Parallel.For(0, tidArr.Length,
                         (item, st) =>
            {
                Process(tidArr[item], tidHashArr[item], item);
                if (this.token.IsCancellationRequested)
                {
                    st.Break();
                }
                ProgressReportEvent?.Invoke(this, new ProgressChangedArgs(1));
            });
            var list = new List <Rule>();

            foreach (var item in rules)
            {
                list.Add(new Rule(item.Key, item.Value / countRows));
            }
            return(list);
        }
Exemple #2
0
        private void Process()
        {
            var toAddDict = new Dictionary <BitSet, HashSet <int> >();

            do
            {
                toAddDict.Clear();
                var top = tidList.GetEnumerator();
                for (int i = 0; i < tidList.Count; i++)
                {
                    top.MoveNext();
                    var item = top.Current;

                    Debug.Assert(item.Key != null, "Top out");
                    var key   = new BitSet(countColumns);
                    var inner = tidList.GetEnumerator();
                    for (int j = 0; j < i; j++)
                    {
                        inner.MoveNext();
                    }
                    for (int j = i; j < tidList.Count; j++)
                    {
                        inner.MoveNext();
                        var value = inner.Current;
                        Debug.Assert(value.Key != null, "Inner out");
                        key.SetFrom(item.Key);
                        key.Or(value.Key);

                        if (key.Equals(item.Key) ||
                            key.Equals(value.Key) ||
                            tidList.ContainsKey(key) ||
                            toAddDict.ContainsKey(key))
                        {
                            continue;
                        }

                        var hashSet = new HashSet <int>(item.Value);
                        hashSet.IntersectWith(value.Value);

                        double support = hashSet.Count;
                        if (support < minSupport)
                        {
                            continue;
                        }
                        var keyNew = new BitSet(key);
                        toAddDict.Add(keyNew, hashSet);
                        rules.Add(new Rule(keyNew, support));
                    }
                }
                foreach (var item in toAddDict)
                {
                    tidList.Add(item.Key, item.Value);
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }
                ProgressReportEvent?.Invoke(this, new ProgressChangedArgs(1));
            } while (toAddDict.Count != 0);
        }