/// <summary> /// Kiem tra tap muc thuoc tid /// </summary> /// <param name="tid">Transaction id cua F</param> /// <param name="muc">Mot muc cua L, Example: {1,2}</param> /// <returns></returns> public static bool ThuocTid(ItemSetsCollection tid, Itemsets muc) { Itemsets p = new Itemsets(muc); p.RemoveAt(muc.Count - 1); // p: c-c[k] List <int> q = new List <int>(muc); q.RemoveAt(muc.Count - 2); //q: c-c[k-1] int count = 0; foreach (Itemsets item in tid) { if (item.IsEqual(p)) { count += 1; } if (item.IsEqual(q)) { count += 1; } } return(count >= 2); }
/// <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); }
public Itemsets(Itemsets itemsets) { foreach (int a in itemsets) { this.Add(a); } this.support = itemsets.support; }
public double FindSupport(Itemsets itemsets) { /*int matchCount = (from i in this * where i.Contains(itemset) * select i).Count(); * * double support = ((double)matchCount / (double)this.Count) * 100.0;*/ double support = 0; return(support); }
public Itemsets Remove(Itemsets itemsets) { Itemsets removed = new Itemsets(); foreach (int item in this) { if (!itemsets.Contains(item)) { removed.Add(item); } } //removed.AddRange(from item in thiswhere !itemsets.Contains(item)select item); return(removed); }
/// <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); }
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); }
public bool Contains(Itemsets itemsets) { return(this.Intersect(itemsets).Count() == itemsets.Count); }