/// <summary> /// Tinh tap L tu tap F hien tai /// </summary> /// <param name="fCurrent"></param> /// <returns></returns> public static ItemSetsCollection TinhL(List <ItemSetsCollection> fCurrent) { ItemSetsCollection results = new ItemSetsCollection(); // Lap lay danh sach cac chi muc thuoc F foreach (ItemSetsCollection listItemsets in fCurrent) { foreach (Itemsets itemsets in listItemsets) { results.AddItemsets(itemsets); } } // Cac chi muc cua tap L thoa minSup // Loai bo cac tap muc khong thoa minSup ItemSetsCollection tmp1 = new ItemSetsCollection(); foreach (Itemsets i in results) { if (i.support >= Program.sup) { i.support = (float)Math.Round(((i.support) / Program.tongSoGiaoTac * 100), 2); if (!Program.tapL.IsContains(i)) { Program.tapL.Add(i); } tmp1.Add(i); } } return(tmp1); }
/// <summary> /// Thuat toan apriori_gen, sinh ra tap ung vien C tu tap L(k-1) /// </summary> /// <param name="lPrevious">L(k-1)</param> /// <returns></returns> public static ItemSetsCollection AprioriGen(ItemSetsCollection lPrevious) { ItemSetsCollection result = new ItemSetsCollection(); if (lPrevious.Count <= 1) { return(result); } int k = lPrevious[0].Count; for (int i = 0; i < lPrevious.Count - 1; i++) { Itemsets p = new Itemsets(lPrevious[i]); p.RemoveAt(k - 1); for (int j = i + 1; j < lPrevious.Count; j++) { Itemsets q = new Itemsets(lPrevious[j]); q.RemoveAt(k - 1); if (p.IsEqual(q)) { q.Add(lPrevious[i][k - 1]); q.Add(lPrevious[j][k - 1]); result.Add(q); } } } return(result); }
/// <summary> /// Sinh ra tap F moi tu F(k-1) va L(k-1) /// </summary> /// <param name="fPrevious"></param> /// <param name="lPrevious"></param> /// <returns></returns> public static List <ItemSetsCollection> SinhF(List <ItemSetsCollection> fPrevious, ItemSetsCollection lPrevious) { Program.k += 1; ItemSetsCollection tapC = AprioriGen(lPrevious); List <ItemSetsCollection> result = new List <ItemSetsCollection>(); foreach (ItemSetsCollection fItem in fPrevious) { // tid ItemSetsCollection tmp = new ItemSetsCollection(); foreach (Itemsets item in tapC) { if (ThuocTid(fItem, item)) { tmp.Add(item); tmp.tid = fItem.tid; } } if (tmp.Count > 0) { result.Add(tmp); } } Program.tapF.Add(result); return(result); }
public ItemSetsCollection findSubSet() { ItemSetsCollection result = new ItemSetsCollection(); for (int i = 1; i < this.Count; i++) { result.Add(new Itemsets(this[i - 1])); ItemSetsCollection newSubsets = new ItemSetsCollection(); for (int j = 0; j < result.Count; j++) { Itemsets newSubset = new Itemsets(); newSubset.AddRange(result[j]); newSubset.Add(this[i]); newSubsets.Add(newSubset); } result.AddRange(newSubsets); } result.Add(new Itemsets(this[this.Count - 1])); return(result); }
/// <summary> /// Lap tren datatable lay tu sql server do ve, Kiem tra cac ceil co gia tri la 1 thi them vao F /// </summary> /// <param name="dataTable"></param> /// <returns></returns> public static List <ItemSetsCollection> SinhTapFTuTapD(DataTable dataTable) { List <ItemSetsCollection> fResults = new List <ItemSetsCollection>(); for (int i = 0; i < dataTable.Rows.Count; i++) { ItemSetsCollection tapCacMuc = new ItemSetsCollection(); for (int j = 1; j < dataTable.Columns.Count; j++) { if (dataTable.Rows[i][j].ToString().Equals("1")) { Itemsets muc = new Itemsets(); muc.Add(j); tapCacMuc.Add(muc); } } tapCacMuc.tid = dataTable.Rows[i][0].ToString(); fResults.Add(tapCacMuc); } return(fResults); }