Khai phá tập mục lợi ích cao sử dụng cấu trúc cây tiền tố

92 9 0
Khai phá tập mục lợi ích cao sử dụng cấu trúc cây tiền tố

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ĐẠI HỌC THÁI NGUYÊN TRƢỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG NGUYỄN HỒNG SÂM KHAI PHÁ TẬP MỤC LỢI ÍCH CAO SỬ DỤNG CẤU TRÚC CÂY TIỀN TỐ Chuyên ngành: Khoa học máy tính Mã số: 60.48.01 LUẬN VĂN THẠC SĨ KHOA HỌC MÁY TÍNH NGƢỜI HƢỚNG DẪN KHOA HỌC TS NGUYỄN HUY ĐỨC Thái Nguyên - 2014 Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ i LỜI CẢM ƠN Lời xin gửi lời cảm ơn chân thành biết ơn sâu sắc tới TS Nguyễn Huy Đức – Trường Cao đẳng Sư phạm Trung ương, người bảo hướng dẫn tận tình cho tơi suốt q trình nghiên cứu khoa học thực luận văn Tôi xin chân thành cảm ơn dạy bảo, giúp đỡ, tạo điều kiện khuyến khích tơi q trình học tập nghiên cứu thầy cô giáo Viện Công nghệ Thông tin, Trường Đại học Công nghệ Thông tin Truyền thông – Đại học Thái Nguyên Và cuối cùng, xin gửi lời cảm ơn tới gia đình, người thân bạn bè – người ln bên tơi lúc khó khăn nhất, ln động viên tơi, khuyến khích tơi sống công việc Tôi xin chân thành cảm ơn! Thái Nguyên, ngày 12 tháng 03 năm 2014 Tác giả Nguyễn Hồng Sâm Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ ii LỜI CAM ĐOAN Tôi xin cam đoan Luận văn “Khai phá tập mục lợi ích cao sử dụng cấu trúc tiền tố” thực theo mục tiêu đề hướng dẫn TS Nguyễn Huy Đức Trong toàn luận văn, điều trình bày cá nhân tổng hợp từ nhiều nguồn tài liệu Tất loại tài liệu có xuất xứ rõ ràng trích dẫn hợp pháp Tơi xin chịu trách nhiệm luận văn Thái Nguyên, ngày 12 tháng 03 năm 2014 Tác giả Nguyễn Hồng Sâm Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ iii MỤC LỤC Trang phụ bìa Trang LỜI CẢM ƠN i LỜI CAM ĐOAN ii MỤC LỤC iii DANH MỤC CÁC KÝ HIỆU VÀ CÁC CHỮ VIẾT TẮT v DANH MỤC CÁC BẢNG vi DANH MỤC HÌNH VẼ vii LỜI MỞ ĐẦU CHƢƠNG 1: TỔNG QUAN VỀ KHAI PHÁ DỮ LIỆU VÀ KHAI PHÁ TẬP MỤC THƢỜNG XUYÊN 1.1 Khái niệm khai phá tri thức khai phá liệu 1.2 Kiến trúc hệ thống khai phá liệu 1.3 Quá trình khai phá liệu .5 1.4 Một số kỹ thuật khai phá liệu .6 1.5 Các sở liệu phục vụ cho khai phá liệu 1.6 Một số ứng dụng khai phá liệu 11 1.7 Khai phá tập mục thường xuyên 12 1.7.1 Các khái niệm .12 1.7.1.1 Cơ sở liệu giao tác 12 1.7.1.2 Tập mục thường xuyên luật kết hợp 14 1.7.1.3 Bài toán khai phá luật kết hợp .15 1.7.2 Cách tiếp cận khai phá tập mục thường xuyên .16 1.7.3 Một số thuật tốn điển hình tìm tập mục thường xun .17 1.7.3.1 Thuật toán Apriori 17 1.7.3.2 Thuật toán COFI-tree 21 1.7.4 Mở rộng toán khai phá tập mục thường xuyên .26 1.8 Kết luận chương 27 CHƢƠNG 2: KHAI PHÁ TẬP MỤC LỢI ÍCH CAO SỬ DỤNG CẤU TRÚC CÂY TIỀN TỐ .28 2.1 Mở đầu 28 Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ iv 2.2 Bài toán khai phá tập mục lợi ích cao 29 2.3 Khai phá tập mục lợi ích cao sử dụng cấu trúc tiền tố 33 2.3.1 Thuật toán COUI-Mine 33 2.3.1.1 Xây dựng TWUI-tree 34 2.3.1.2 Khai phá TWUI-tree 39 2.3.1.3 Nhận xét đánh giá thuật toán COUI-Mine 45 2.3.1.4 Khai phá tương tác với TWUI-tree 47 2.3.2 Các cấu trúc tiền tố cho khai phá lợi ích cao 48 2.3.3 Thuật toán UP-Growth 51 2.4 Kết luận chương 54 CHƢƠNG 3: THỰC NGHIỆM KHAI PHÁ TẬP MỤC LỢI ÍCH CAO 56 3.1 Bài tốn phát nhóm mặt hàng có lợi nhuận cao 56 3.2 Mô tả liệu 56 3.3 Xây dựng chương trình 60 3.4 Thực nghiệm khai phá tìm tập mục lợi ích cao .60 3.5 Kết thực nghiệm 61 KẾT LUẬN 62 TÀI LIỆU THAM KHẢO 63 Tiếng Việt .63 Tiếng Anh .63 PHỤ LỤC 65 Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ v DANH MỤC CÁC KÝ HIỆU VÀ CÁC CHỮ VIẾT TẮT Trong luận văn này, dùng thống ký hiệu chữ viết tắt sau: Các ký hiệu: I = {i1, i2,…, in}: Tập n mục liệu DB = {T1, T2,…, Tm}: Cơ sở liệu có m giao tác Db: sở liệu giao tác DB, db DB Ip: Mục liệu thứ p Tq: Giao tác thứ q n: Số mục liệu sở liệu giao tác m: Số giao tác sở liệu giao tác A, B, C,…: Tên mục liệu sở liệu giao tác ví dụ X, Y,…: Tập tập mục liệu I, X, Y I X = ABC thay cho X = {A, B, C} sở liệu giao tác ví dụ Nếu X Y X gọi tập tập Y, Y gọi tập cha tập X minsup: Ngưỡng độ hỗ trợ tối thiểu minutil: Giá trị lợi ích tối thiểu X : Số phần tử tập hợp X Viết tắt: KPDL: Khai phá liệu CSDL: Cơ sở liệu CNTT: Công nghệ thông tin CNTT TT: Công nghệ Thơng tin Truyền thơng Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ vi DANH MỤC CÁC BẢNG Bảng 1.1: Biểu diễn ngang sở liệu giao tác 13 Bảng 1.2: Biểu diễn dọc sở liệu giao tác .13 Bảng 1.3: Ma trận giao tác sở liệu cho bảng 1.1 14 Bảng 1.4: Cơ sở liệu giao tác minh họa thực thuật toán Apriori 20 Bảng 1.5: Cơ sở liệu giao tác minh họa thực thuật toán COFI-tree .22 Bảng 1.6: Các mục liệu độ hỗ trợ 23 Bảng 1.7: Các mục liệu thường xuyên thứ tự 23 Bảng 1.8: Các mục liệu giao tác xếp giảm dần theo độ hỗ trợ .23 Bảng 2.1: Cơ sở liệu giao tác 30 Bảng 2.2: Bảng lợi ích .30 Bảng 2.3: Lợi ích giao tác sở liệu bảng 2.1 bảng 2.2 .36 Bảng 2.4: Lợi ích TWU mục liệu 36 Bảng 2.5: Các mục liệu có lợi ích TWU c 36 Bảng 2.6: Các mục liệu giao tác giảm dần theo lợi ích TWU 37 Bảng 2.7: Lợi ích tập mục ứng viên 43 Bảng 2.8: Cơ sở liệu ví dụ cho thuật toán UP-Growth 52 Bảng 2.9: Bảng lợi ích CSDL bảng 2.8 53 Bảng 2.10: Các giao tác lại mục liệu theo TWU giảm dần 53 Bảng 3.1: Dữ liệu trích chọn để khai phá .57 Bảng 3.2: Bảng lợi ích mặt hàng 58 Bảng 3.3: Mã hóa mặt hàng 58 Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ vii DANH MỤC HÌNH VẼ Hình 1.1: Q trình phát tri thức Hình 1.2: Kiến trúc hệ thống khai phá liệu Hình 1.3: Quá trình KPDL Hình 1.4: Cây định Hình 1.5: Mẫu kết nhiệm vụ phân cụm liệu .8 Hình 1.6: Mẫu kết nhiệm vụ hồi quy .8 Hình 1.7: Phân loại thuật toán khai phá tập mục thường xuyên 17 Hình 1.8: Cây FP-tree CSDL bảng 1.5 24 Hình 1.9: Cây COFI-tree mục D 24 Hình 1.10: Các bước khai phá D-COFI-tree 25 Hình 2.1: Cây TWUI-tree sau lưu giao tác T1 .37 Hình 2.2: Cây TWUI-tree sau lưu giao tác T1 T2 .38 Hình 2.3: Cây TWUI-tree sở liệu bảng 2.1 bảng 2.2 38 Hình 2.4: Cây C-COUI-tree sau lưu mẫu CBE 40 Hình 2.5: Cây C-COUI-tree sau lưu mẫu CBE CE 40 Hình 2.6: Cây C-COUI-tree sau xây dựng xong .40 Hình 2.7: Cây D-COUI-tree 41 Hình 2.8: Cây B-COUI-tree 41 Hình 2.9: Các bước khai phá D-COUI-Tree 42 Hình 2.10: Cây TWUI-tree có mục liệu tăng dần theo trật tự từ điển sở liệu bảng 2.1 bảng 2.2 .49 Hình 2.11: Cây TWUI-tree có mục liệu giảm dần theo số lần xuất chúng sở liệu bảng 2.1 bảng 2.2 49 Hình 2.12: Cây TWUI-tree có mục liệu giảm dần theo TWU chúng sở liệu bảng 2.1 bảng 2.2 .50 Hình 2.13: Cây TWUI-tree CSDL bảng 2.8 với minutil = 40 54 Hình 2.14: Cây UP-tree CSDL bảng 2.8 với minutil = 40 54 Hình 3.1: Dữ liệu mã hóa chuẩn bị cho khai phá 59 Hình 3.2: Dữ liệu mã hóa bảng 3.2 59 Hình 3.3: Giao diện chương trình .60 Hình 3.4: Giao diện kết khai phá 61 Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ LỜI MỞ ĐẦU Khai phá tập mục thường xun đóng vai trị quan trọng nhiều nhiệm vụ khai phá liệu Khai phá tập mục thường xuyên xuất toán nhiều lĩnh vực khai phá liệu khám phá luật kết hợp, khám phá mẫu tuần tự,… Bài toán khai phá luật kết hợp Agrawal, T.Imielinski A N Swami đề xuất nghiên cứu lần đầu vào năm 1993 với mục tiêu phát tập mục thường xuyên, từ tạo luật kết hợp Trong mơ hình tốn này, giá trị mục liệu giao tác 1, tức quan tâm mục liệu có xuất giao tác hay khơng Bài tốn có nhiều ứng dụng, vậy, tập mục thường xuyên mang ngữ nghĩa thống Nhằm khắc phục hạn chế toán khai phá luật kết hợp, nhiều nhà nghiên cứu mở rộng toán theo nhiều hướng khác Năm 1997, Hilderman cộng đề xuất toán khai phá , giá trị mục liệu giao tác số Năm 2004, nhóm nhà nghiên cứu H Yao, Hamilton Butz, mở rộng tiếp tốn, đề xuất mơ hình khai phá tập mục lợi ích cao Trong mơ hình khai phá tập mục lợi ích cao, giá trị mục liệu giao tác số (như số lượng bán mặt hàng, gọi giá trị khách quan), ngồi cịn có bảng lợi ích cho biết lợi ích mang lại bán đơn vị hàng (gọi giá trị chủ quan) Lợi ích tập mục số đo lợi nhuận mà tập mục mang lại Khai phá tập mục lợi ích cao khám phá tất tập mục có lợi ích khơng nhỏ ngưỡng lợi ích tối thiểu người sử dụng Trong năm gần đây, toán thu hút quan tâm nhiều nhà nghiên cứu ngồi nước Đã có số thuật tốn phát tập mục lợi ích cao đề xuất Các thuật tốn phân thành hai loại: - Thuật toán kiểu Apriori (Apriori-like), sinh tập mục ứng viên, duyệt theo chiều rộng - Thuật tốn khơng sinh ứng viên, chuyển đổi sở liệu thành cấu trúc cây, duyệt theo chiều sâu để phát tập mục lợi ích cao Các thuật toán loại hiệu tránh khối lượng tính tốn lớn Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ Với ý nghĩa mục đích tìm hiểu tốn tìm tập mục lợi ích cao thuật toán khai phá sử dụng cấu trúc tiền tố, em định lựa chọn đề tài luận văn: “ KHAI PHÁ TẬP MỤC LỢI ÍCH CAO SỬ DỤNG CẤU TRÚC CÂY TIỀN TỐ” Nội dung luận văn gồm chương: Chương 1: Tổng quan khai phá liệu khai phá tập mục thường xuyên Chương 2: Khai phá tập mục lợi ích cao sử dụng cấu trúc tiền tố Chương 3: Chương trình thực nghiệm ứng dụng Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 70 // //Hàm có ý nghĩa tương tự void UpdateCOHUTable(struct ItemRecord OneItem, COUITree* NewCurrent) { int loc = OneItem.Index ; if (HUItemsArray[loc].cohuFirst == NULL) HUItemsArray[loc].cohuFirst = NewCurrent; else { NewCurrent->Next = HUItemsArray[loc].cohuFirst; HUItemsArray[loc].cohuFirst= NewCurrent; } } // bool SearchCOUIBrother( long nodeItem, COUITree*& NewCurrent, COUITree*& LastBrother) { bool found,over; found = false; over = false; LastBrother = NULL; while ((NewCurrent != NULL) && (!found) && (!over)) { if (NewCurrent->Item == nodeItem) found = true; else if (HUItemsArray[FindInHashTable[nodeItem]].cohuTwu > HUItemsArray[FindInHashTable[NewCurrent->Item]].cohuTwu) over = true; else { LastBrother = NewCurrent; NewCurrent = NewCurrent->Brother; } } return found; } ///////////////////////////////////////////////////////////////////////////////////////////////////// bool SearchHUTBrother(int nodeItem, TWUITree* & NewCurrent, TWUITree*& LastBrother) { bool found; found = false; LastBrother = NULL; while ((NewCurrent != NULL) && (!found)) { if (NewCurrent->Item == nodeItem ) { found = true; } else { Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 71 LastBrother = NewCurrent; NewCurrent = NewCurrent->Brother; } } return found; } // //Tim kiem not giong cay candidate bool SearchCandidateBrother(int nodeItem, CandidateTree* & NewCurrent, CandidateTree*& LastBrother) { bool found; found = false; LastBrother = NULL; while ((NewCurrent != NULL) && (!found)) { if (NewCurrent->Item == nodeItem ) { found = true; } else { LastBrother = NewCurrent; NewCurrent = NewCurrent->Brother; } } return found; } ///////////////////////////////////////////////////////////////////////////////////////////////////// void AddNewChildWithBrother(struct HUTransaction huTransaction, int i, TWUITree* FatherNode, TWUITree* LastBrother, TWUITree*& NewCurrent) { TWUITree* node = new TWUITree; node->Item = huTransaction.HUItemsArray[i].Item ; node->TWU = huTransaction.TU ; node->Depth = FatherNode->Depth + ; node->Child = NULL; node->Next = NULL; node->Father = FatherNode; node->Brother = FatherNode->Child ; FatherNode->Child = node ; NewCurrent = node; } ///////////////////////////////////////////////////////////////////////////////////////////////////// void AddNewChildNoBrother(struct HUTransaction huTransaction, int i, TWUITree* FatherNode, TWUITree*& NewCurrent) { TWUITree* node = new TWUITree; node->Item = huTransaction.HUItemsArray [i].Item ; node->TWU = huTransaction.TU ; node->Depth = FatherNode->Depth + ; Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 72 node->Brother = NULL; node->Child = NULL; node->Next = NULL; node->Father = FatherNode; FatherNode->Child = node; NewCurrent = node; } /////////////////////////////////////////////////////////////////////////////////////////////////// void AddToTWUITree(HUTransaction huTransaction, int i, TWUITree*& Current, TWUITree* LastBrother, TWUITree* Fathernode) { if (Fathernode->Child == NULL) AddNewChildNoBrother(huTransaction,i,Fathernode, Current); else { AddNewChildWithBrother(huTransaction, i, Fathernode, LastBrother, Current); } UpdateTable(huTransaction.HUItemsArray [i], Current); } // //Các hàm phục vụ cho việc thêm node vào COUI void AddNewCOUIChildWithBrother(struct HUTransaction huBranch, int i, COUITree* FatherNode, COUITree* LastBrother, COUITree *& NewCurrent) { COUITree* node = new COUITree; node->Item = huBranch.HUItemsArray[i].Item ; node->TWU = huBranch.TU ; node->Depth = FatherNode->Depth + ; node->Participation = 0; node->Child = NULL; node->Next = NULL; node->Father = FatherNode; node->Brother = FatherNode->Child ; FatherNode->Child = node ; NewCurrent = node; } ///////////////////////////////////////////////////////////////////////////////////////////////////// /*Ham them mot muc vao cay TWU-Tree chua co not nao la anh em voi no void AddNewCOUIChildNoBrother(struct HUTransaction huBranch, int i, COUITree* FatherNode, COUITree*& NewCurrent) { COUITree* node = new COUITree; node->Item = huBranch.HUItemsArray [i].Item ; node->TWU = huBranch.TU ; node->Depth = FatherNode->Depth + ; node->Participation = 0; node->Brother = NULL; node->Child = NULL; node->Next = NULL; node->Father = FatherNode; FatherNode->Child = node; Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 73 NewCurrent = node; } /////////////////////////////////////////////////////////////////////////////////////////////////// */ void AddToCOUITree(HUTransaction huBranch, int i, COUITree*& Current, COUITree* LastBrother, COUITree* Fathernode) { if (Fathernode->Child == NULL) AddNewCOUIChildNoBrother(huBranch, i, Fathernode, Current); else { AddNewCOUIChildWithBrother(huBranch, i, Fathernode, LastBrother, Current); } UpdateCOHUTable(huBranch.HUItemsArray [i], Current); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void AddNewCandidateChildWithBrother(CandidateItem saveRoot, struct CTransaction huTransaction, int i, CandidateTree* FatherNode, CandidateTree* LastBrother, CandidateTree*& NewCurrent) { CandidateTree* node = new CandidateTree; node->Item = huTransaction.HUItemsArray[i].Item ; node->TWU = huTransaction.TU ; node->Depth = FatherNode->Depth + ; node->NodeList.push_back (saveRoot.Item); node->Counter.push_back (saveRoot.Counter); for (int j=1; jNodeList.size (); j++) for (int k=0; kNodeList [j] == huTransaction.HUItemsArray[k].Item) { node->NodeList.push_back (huTransaction.HUItemsArray[k].Item); node->Counter.push_back (huTransaction.HUItemsArray[k].Counter ); } } node->NodeList.push_back (huTransaction.HUItemsArray [i].Item); node->Counter.push_back (huTransaction.HUItemsArray [i].Counter ); node->Child = NULL; node->Next = NULL; node->Father = FatherNode; node->Brother = FatherNode->Child ; FatherNode->Child = node ; NewCurrent = node; } ///////////////////////////////////////////////////////////////////////////////////////////////////// void AddNewCandidateChildNoBrother(CandidateItem saveRoot, struct CTransaction huTransaction, int i, CandidateTree* FatherNode, CandidateTree*& NewCurrent) { CandidateTree* node = new CandidateTree; node->Item = huTransaction.HUItemsArray [i].Item ; Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 74 node->TWU = huTransaction.TU ; node->Depth = FatherNode->Depth + ; node->NodeList.push_back (saveRoot.Item); node->Counter.push_back (saveRoot.Counter); for (int j=1; jNodeList.size (); j++) for (int k=0; kNodeList [j] == huTransaction.HUItemsArray[k].Item) { node->NodeList.push_back (huTransaction.HUItemsArray[k].Item); node->Counter.push_back (huTransaction.HUItemsArray[k].Counter ); } } node->NodeList.push_back (huTransaction.HUItemsArray [i].Item); node->Counter.push_back (huTransaction.HUItemsArray [i].Counter ); node->Brother = NULL; node->Child = NULL; node->Next = NULL; node->Father = FatherNode; FatherNode->Child = node; NewCurrent = node; } ///////////////// void AddToCandidateTree(CandidateItem saveRoot, CTransaction huTransaction, int i, CandidateTree*& Current, CandidateTree* LastBrother, CandidateTree* Fathernode) { if (Fathernode->Child == NULL) { AddNewCandidateChildNoBrother(saveRoot, huTransaction,i,Fathernode, Current); } else { AddNewCandidateChildWithBrother(saveRoot, huTransaction, i, Fathernode, LastBrother, Current); } } ///////////////////////////////////////////////////////////////////////////////////// //Duyet cay void TraverseTWUITree(TWUITree* twuiRoot) { if (twuiRoot != NULL) { coutBrother != NULL) FreeCandidateTree(root->Brother ); long TotalTu = ; for (int i = ; i< root->NodeList.size (); i++) { TotalTu += root->Counter[i] * UnitUtil[root->NodeList [i]]; } if (TotalTu >= MinUtil) //neu lon hon nguong loi ich thi in file { fprintf(fpout,"( "); for (int i = 0; i< root->NodeList.size (); i++) { fprintf(fpout," %d ",root->NodeList [i] + 1); fprintf(fpout," ) : %1d \n",TotalTu); } free (root); } //Giai phong cay void FreeCOUITree(COUITree* root) { Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ } 77 if (root->Child != NULL) FreeCOUITree(root->Child ); if (root->Brother != NULL) FreeCOUITree(root->Brother ); free (root); } //////////////////////////////////////////////////////////////////////////////// void Candidate_Generation(CandidateTree* RootNode, CandidateItem saveRoot, CTransaction cBranch, int startPoint) { int i; CandidateTree* tempNode; FatherF = RootNode; CurrentF = RootF->Child; NewCurrentF = RootF->Child; LastBrotherF = RootF->Child ; bool Found ; tempNode = FatherF; for ( i = startPoint; iChild ; if (CurrentF != NULL) { NewCurrentF = CurrentF ; LastBrotherF = CurrentF; Found = SearchCandidateBrother(cBranch.HUItemsArray[i].Item , NewCurrentF, LastBrotherF); } if (Found) { CurrentF = NewCurrentF; if (CurrentF->Father == RootF) { CurrentF->Counter [ CurrentF->Counter.size ()-1] += cBranch.HUItemsArray[i].Counter ; } else { for( int j = 0; j < CurrentF->Depth +1; j++) for (int k = 0; k < cBranch.HUItemsArray.size () ; k++) { if ( CurrentF->NodeList[j] == cBranch.HUItemsArray [k].Item ) CurrentF->Counter [j] += cBranch.HUItemsArray [k].Counter ; } } CurrentF->Counter[0] += saveRoot.Counter ; CurrentF->TWU += cBranch.TU; } Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 78 else { AddToCandidateTree(saveRoot, cBranch,i, CurrentF, LastBrotherF, FatherF); } if (i+1 != cBranch.HUItemsArray.size ()) Candidate_Generation(CurrentF, saveRoot, cBranch, i+1); } } ///////////////////////////////////////////////////////////////////////////// int FindNextCohuLocal(int currentCohuItem, int OriginalLocation) { int location = OriginalLocation; bool found = false; while ( (location > currentCohuItem) && (!found)) { if ((HUItemsArray[location].cohuFirst != NULL) && (HUItemsArray[location].cohuTwu >= MinUtil)) found = true; else location ; } return location; } //////////////////////////////////////////////////////////////////////////// //Khai thac cay void MineCOUITree(COUITree* couiRoot, int itemlocation) { int i,j; int SizeOfHUBranch = NumberOfHUItems - itemlocation; int LocationOfCurrentLocalF = FindNextCohuLocal(itemlocation, NumberOfHUItems); CurrentF = new CandidateTree; FatherF = new CandidateTree; NewCurrentF = new CandidateTree; LastBrotherF = new CandidateTree; RootOrignal = new CandidateTree; RootF = new CandidateTree; RootF->Item = couiRoot->Item; RootF->Depth = 0; RootF->Brother = NULL ; RootF->Child = NULL ; RootF->Father = NULL ; RootF->Next = NULL ; RootF->TWU = couiRoot->TWU; RootF->NodeList.push_back (couiRoot->Item); RootF->Counter.push_back (0); RootOrignal = RootF ; if (LocationOfCurrentLocalF != itemlocation) { int patternsize ; COUITree* cohuNode ; Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 79 COUITree* traverse; while ( LocationOfCurrentLocalF != itemlocation) { cohuNode = HUItemsArray[LocationOfCurrentLocalF].cohuFirst ; while ((cohuNode != NULL))// { CTransaction CBranch; CandidateItem saveRoot; CBranch.TU = cohuNode->TWU - cohuNode->Participation; traverse = cohuNode; while (traverse->Depth > ) { int loc = FindInHashTable[traverse->Item]; CandidateItem temp; temp.Item = traverse->Item;; temp.Counter = 0; temp.Index = loc; CBranch.HUItemsArray.push_back (temp); traverse = traverse->Father; } saveRoot.Counter = 0; saveRoot.Item = traverse->Item; traverse = cohuNode->Father ; while (traverse->Depth > -1) { traverse->Participation += cohuNode->TWU; traverse = traverse->Father; } if (CBranch.HUItemsArray.size () >0) Candidate_Generation(RootF, saveRoot, CBranch, 0); RootF = RootOrignal; cohuNode = cohuNode->Next; } LocationOfCurrentLocalF = FindNextCohuLocal(itemlocation, LocationOfCurrentLocalF-1); } } } // -int main() { int i ; TWUITree* huCurrent = new TWUITree; TWUITree* huFather = new TWUITree; TWUITree* twuiRoot = new TWUITree; TWUITree* huNewCurrent = new TWUITree; TWUITree* huLastBrother = new TWUITree; bool Found ; //Yeu cau nhap gia tri MinUtilRatio khoang [0,100] Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 80 { coutTWU; int NumberOfBranchNode = cohuNode->Depth + 1; traverse = cohuNode; while (traverse != twuiRoot) { locationCohu = FindInHashTable[traverse->Item]; HUItemsArray[locationCohu].cohuTwu += cohuNode->TWU; if (HUItemsArray[locationCohu].cohuTwu >= MinUtil) foundOne = true; traverse = traverse->Father; } cohuNode = cohuNode->Next; } cohuItem = HUItemsArray[j].Item; cohuNode = HUItemsArray[j].huFirst ; if (foundOne == true) { while (cohuNode != NULL) { traverse = cohuNode; branchTwu = traverse->TWU; cohuFather = couiRoot; cohuCurrent = couiRoot->Child; cohuNewCurrent = couiRoot->Child ; cohuLastBrother = couiRoot->Child ; HUTransaction huBranch; Số hóa Trung tâm Học liệu http://www.lrc-tnu.edu.vn/ 83 huBranch.TU = cohuNode->TWU; while (traverse != twuiRoot) { loc = FindInHashTable[traverse->Item]; if (HUItemsArray[loc].cohuTwu >= MinUtil) { ItemRecord temp; temp.Item = traverse->Item; temp.Index = loc; huBranch.HUItemsArray.push_back (temp); } traverse = traverse->Father; } for (i = 0; i< huBranch.HUItemsArray.size (); i++) { loc = huBranch.HUItemsArray[i].Index ; Found = false; if (cohuCurrent != NULL) { cohuNewCurrent = cohuCurrent; cohuLastBrother = cohuCurrent; Found = SearchCOUIBrother(huBranch.HUItemsArray[i].Item , cohuNewCurrent, cohuLastBrother); } if (Found) { cohuCurrent = cohuNewCurrent ; cohuCurrent->TWU += huBranch.TU; } else AddToCOUITree(huBranch, i, cohuCurrent, cohuLastBrother, cohuFather); cohuFather = cohuCurrent; cohuCurrent = cohuCurrent->Child ; } cohuNode = cohuNode->Next ; } } if (couiRoot->Child != NULL) { MineCOUITree(couiRoot->Child, j); if( (fp = fopen( inputFileName,"r" )) == NULL ) cout

Ngày đăng: 24/02/2021, 21:41

Tài liệu cùng người dùng

Tài liệu liên quan