/// <summary> /// Creates a new bitmap by S-Step with a given item-bitmap. /// </summary> public Bitmap128 CreateNewBySStep(Bitmap128 itemBitmap) { // A new bitmap for S-Step will be create by ANDing transformed sequence-bitmap with item-bitmap. // During creating a new bitmap also counts the support for a new bitmap. var support = 0; var newBitmaps = new UInt128[SequencesCount]; var itemBitmaps = itemBitmap._bitmaps; for (var sid = 0; sid < SequencesCount; ++sid) { if (_bitmaps[sid] == 0) { continue; } var tid = DeBruijn.FirstSetBit(_bitmaps[sid]); if ((newBitmaps[sid] = (TransformedBitmap[tid] & itemBitmaps[sid])) == 0) { continue; } ++support; } return(support > 0 ? new Bitmap128(newBitmaps, support) : null); }
/// <summary> /// For a given prefix returns the frequent candidates. /// </summary> public List <uint> GetFrequentItems(SeqBitmap prefixBitmap, IList <uint> candidates) { int transactions = 0; var transactionSBitVectors = new byte[ prefixBitmap.Sequences8Count + prefixBitmap.Sequences16Count + prefixBitmap.Sequences32Count + prefixBitmap.Sequences64Count + prefixBitmap.Sequences128Count][]; if (prefixBitmap.Sequences8Count > 0) { var prefixBitmaps8 = prefixBitmap.Bitmaps8; for (int sid = 0; sid < prefixBitmap.Sequences8Count; sid++) { if (prefixBitmaps8[sid] == 0) { continue; } transactionSBitVectors[transactions++] = _bitVectors8[sid, DeBruijn.FirstSetBit(prefixBitmaps8[sid])]; } } if (prefixBitmap.Sequences16Count > 0) { var prefixBitmaps16 = prefixBitmap.Bitmaps16; for (int sid = 0; sid < prefixBitmap.Sequences16Count; sid++) { if (prefixBitmaps16[sid] == 0) { continue; } transactionSBitVectors[transactions++] = _bitVectors16[sid, DeBruijn.FirstSetBit(prefixBitmaps16[sid])]; } } if (prefixBitmap.Sequences32Count > 0) { var prefixBitmaps32 = prefixBitmap.Bitmaps32; for (int sid = 0; sid < prefixBitmap.Sequences32Count; sid++) { if (prefixBitmaps32[sid] == 0) { continue; } transactionSBitVectors[transactions++] = _bitVectors32[sid, DeBruijn.FirstSetBit(prefixBitmaps32[sid])]; } } if (prefixBitmap.Sequences64Count > 0) { var prefixBitmaps64 = prefixBitmap.Bitmaps64; for (int sid = 0; sid < prefixBitmap.Sequences64Count; sid++) { if (prefixBitmaps64[sid] == 0) { continue; } transactionSBitVectors[transactions++] = _bitVectors64[sid, DeBruijn.FirstSetBit(prefixBitmaps64[sid])]; } } if (prefixBitmap.Sequences128Count > 0) { var prefixBitmaps128 = prefixBitmap.Bitmaps128; for (int sid = 0; sid < prefixBitmap.Sequences128Count; sid++) { if (prefixBitmaps128[sid] == 0) { continue; } transactionSBitVectors[transactions++] = _bitVectors128[sid, DeBruijn.FirstSetBit(prefixBitmaps128[sid])]; } } var frequetItems = new List <uint>(); for (int i = 0, j = candidates.Count; i < j; i++) { var candidate = candidates[i]; int candidateSupport = 0; for (int tid = 0; tid < transactions; tid++) { candidateSupport += transactionSBitVectors[tid][candidate]; if (candidateSupport < _minSupport) { continue; } frequetItems.Add(candidate); break; } } return(frequetItems); }