static void Main(string[] args) { List <Transaction <char> > database = new List <Transaction <char> >(); database.Add(new Transaction <char>('f', 'a', 'c', 'd', 'g', 'i', 'm', 'p')); database.Add(new Transaction <char>('a', 'b', 'c', 'f', 'l', 'm', 'o')); database.Add(new Transaction <char>('b', 'f', 'h', 'j', 'o', 'w')); database.Add(new Transaction <char>('b', 'c', 'k', 's', 'p')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n', 'z')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'h', 'c', 'e', 'o', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'o', 'm', 'n')); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n')); database.Add(new Transaction <char>('a', 'j', 'c', 'e', 'b', 'p', 'm', 'n')); DateTime start_time = DateTime.UtcNow; FPGrowth <char> method = new FPGrowth <char>(); var ftDomain = Transaction <char> .ExtractDomain(database); ItemSets <char> fis = method.MinePatterns(database, ftDomain, 0.4); DateTime end_time = DateTime.UtcNow; Show(fis); Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds); Console.WriteLine("Finding Closed Pattern"); Show(method.FindMaxPatterns(database, Transaction <char> .ExtractDomain(database), 0.4)); Console.ReadKey(); }
// public async Task SaveDictionary(string dictionaryFilePath) // { // await File.WriteAllLinesAsync(dictionaryFilePath, // transactions.intToPredicateDict.Select(x => $"{x.Key} {x.Value}") // ); // } public PatternDiscovery.ItemSets <T> GetFrequentPatternV2( TransactionList <T> transactions, double minSupport) { if (minSupport > 1) { throw new ArgumentException("Threshold must be between 0 and 1"); } this.transactions = transactions; this.minSupport = minSupport; // this.objectPropertiesInfo = new List<(HashSet<string> classes, int propertySupport, bool dash)>(); var domain = transactions.domain; log.LogInformation("Mining..."); var method = new PatternDiscovery.FrequentPatterns.Apriori <T>(); fis = method.MinePatterns(transactions.transactions, minSupport, domain); #region MFP // var fisSet = fis.Select(x => x.ToHashSet()).ToHashSet(); // for (int i = 0; i < fis.Count; ++i) // { // log.LogInformation(string.Join(" ", fis[i]) + " #SUP: " + fis[i].TransactionCount // + " " + IsMFPV2(fis[i].ToHashSet(), fisSet)); // } // log.LogInformation("Maximum"); // foreach (var rule in GetMFPV2(fisSet)) // { // log.LogInformation(string.Join(" ", rule)); // } #endregion return(fis); }
private static void Show(ItemSets <char> fis) { for (int i = 0; i < fis.Count; ++i) { Console.WriteLine("{0} (Support: {1})", fis[i], fis[i].Support); } }
public void Example() { List <Transaction <char> > database = new List <Transaction <char> >(); database.Add(new Transaction <char>('a', 'c', 'd', 'e') { ID = 10 }); database.Add(new Transaction <char>('a', 'b', 'e') { ID = 20 }); database.Add(new Transaction <char>('b', 'c', 'e') { ID = 30 }); database.Add(new Transaction <char>('b', 'c', 'e') { ID = 40 }); Apriori <char> method = new Apriori <char>(); ItemSets <char> itemsets = method.MinePatterns(database, 2, new List <char>() { 'a', 'b', 'c', 'd', 'e' }); for (int i = 0; i < itemsets.Count; ++i) { ItemSet <char> itemset = itemsets[i]; Console.WriteLine(itemset); } }
public void Loop() { if (hasSets) { ItemSets.ForEach(s => s.Loop()); } // do stuff here }
public List <OutfitPreview> GetJobOutfitSprites(Gender gender, bool useInventoryIcon, out Vector2 maxDimensions) { List <OutfitPreview> outfitPreviews = new List <OutfitPreview>(); maxDimensions = Vector2.One; var equipIdentifiers = Element.GetChildElements("ItemSet").Elements().Where(e => e.GetAttributeBool("outfit", false)).Select(e => e.GetAttributeString("identifier", "")); var outfitPrefabs = ItemPrefab.Prefabs.Where(itemPrefab => equipIdentifiers.Contains(itemPrefab.Identifier)).ToList(); if (!outfitPrefabs.Any()) { return(null); } for (int i = 0; i < outfitPrefabs.Count; i++) { var outfitPreview = new OutfitPreview(); if (!ItemSets.TryGetValue(i, out var itemSetElement)) { continue; } var previewElement = itemSetElement.GetChildElement("PreviewSprites"); if (previewElement == null || useInventoryIcon) { if (outfitPrefabs[i] is ItemPrefab prefab && prefab.InventoryIcon != null) { outfitPreview.AddSprite(prefab.InventoryIcon, Vector2.Zero); outfitPreview.Dimensions = prefab.InventoryIcon.SourceRect.Size.ToVector2(); maxDimensions.X = MathHelper.Max(maxDimensions.X, outfitPreview.Dimensions.X); maxDimensions.Y = MathHelper.Max(maxDimensions.Y, outfitPreview.Dimensions.Y); } outfitPreviews.Add(outfitPreview); continue; } var children = previewElement.Elements().ToList(); for (int n = 0; n < children.Count; n++) { XElement spriteElement = children[n]; string spriteTexture = spriteElement.GetAttributeString("texture", "").Replace("[GENDER]", (gender == Gender.Female) ? "female" : "male"); var sprite = new Sprite(spriteElement, file: spriteTexture); sprite.size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height); outfitPreview.AddSprite(sprite, children[n].GetAttributeVector2("offset", Vector2.Zero)); } outfitPreview.Dimensions = previewElement.GetAttributeVector2("dims", Vector2.One); maxDimensions.X = MathHelper.Max(maxDimensions.X, outfitPreview.Dimensions.X); maxDimensions.Y = MathHelper.Max(maxDimensions.Y, outfitPreview.Dimensions.Y); outfitPreviews.Add(outfitPreview); } return(outfitPreviews); }
private static void LoadItemSets() { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssetViewer.Resources.Assets.ItemSet.xml")) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => new TemplateAsset(s))) { ItemSets.Add(item.ID, item); } } }
protected List <ItemSets <T> > Cluster(double[][] distance_matrix, ItemSets <T> fis, int clusterCount) { if (ClusterMethod != null) { return(ClusterMethod(distance_matrix, fis, clusterCount)); } else { throw new NotImplementedException(); } }
/// <summary> /// Confidence measure [0, infinity] /// </summary> /// <typeparam name="T"></typeparam> /// <param name="A"></param> /// <param name="all"></param> /// <returns></returns> public static double GetConfidence <T>(ItemSet <T> A, ItemSets <T> all) where T : IComparable <T> { double sum_supp = 0; foreach (ItemSet <T> itemset in all) { sum_supp += itemset.Support; } return(A.Support / sum_supp); }
private double GetPatternDistance(ItemSet <T> set1, ItemSet <T> set2, ItemSets <T> fis) { ItemSet <T> intersection_set = GetIntersection(set1, set2, fis); ItemSet <T> union_set = GetUnion(set1, set2, fis); int union_count = union_set != null ? union_set.Count : 0; int intersection_count = intersection_set != null ? intersection_set.Count : 0; if (intersection_count == 0) { return(1); } return(1 - (double)union_count / intersection_count); }
private ItemSet <T> GetIntersection(ItemSet <T> set1, ItemSet <T> set2, ItemSets <T> fis) { if (IsSubsetOf(set1, set2)) { return(set1); } else if (IsSubsetOf(set2, set1)) { return(set2); } HashSet <T> temp1 = new HashSet <T>(); for (int i = 0; i < set1.Count; ++i) { temp1.Add(set1[i]); } HashSet <T> temp2 = new HashSet <T>(); for (int i = 0; i < set2.Count; ++i) { if (temp1.Contains(set2[i])) { temp2.Add(set2[i]); } } List <T> temp = temp2.ToList(); temp.Sort(); ItemSet <T> intersection_set = new ItemSet <T>(); for (int i = 0; i < temp.Count; ++i) { intersection_set.Add(temp[i]); } for (int i = 0; i < fis.Count; ++i) { if (fis[i].Equals(intersection_set)) { return(fis[i]); } } return(null); }
public static void Example() { List <Transaction <char> > database = new List <Transaction <char> >(); database.Add(new Transaction <char>('f', 'a', 'c', 'd', 'g', 'i', 'm', 'p') { ID = 100 }); database.Add(new Transaction <char>('a', 'b', 'c', 'f', 'l', 'm', 'o') { ID = 200 }); database.Add(new Transaction <char>('b', 'f', 'h', 'j', 'o', 'w') { ID = 300 }); database.Add(new Transaction <char>('b', 'c', 'k', 's', 'p') { ID = 400 }); database.Add(new Transaction <char>('a', 'f', 'c', 'e', 'l', 'p', 'm', 'n') { ID = 500 }); Console.WriteLine("Using FPGrowth"); DateTime start_time = DateTime.UtcNow; FPGrowth <char> method = new FPGrowth <char>(); ItemSets <char> fis = method.MinePatterns(database, Transaction <char> .ExtractDomain(database), 0.4); DateTime end_time = DateTime.UtcNow; Show(fis); Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds); Console.WriteLine("Finding Closed Pattern"); Show(method.FindMaxPatterns(database, Transaction <char> .ExtractDomain(database), 0.4)); Console.WriteLine("Using baseline Apriori"); start_time = DateTime.UtcNow; Apriori <char> baseline_method = new Apriori <char>(); fis = method.MinePatterns(database, Transaction <char> .ExtractDomain(database), 0.4); end_time = DateTime.UtcNow; Show(fis); Console.WriteLine("Time Span: {0} ms", (end_time - start_time).TotalMilliseconds); }
public virtual ItemSets <T> MinePatterns(IEnumerable <Transaction <T> > database, GetMinSupportHandle getMinItemSetSupport, IList <T> domain, int partitionCount) { HashSet <ItemSet <T> > candidates = new HashSet <ItemSet <T> >(); for (int i = 0; i < partitionCount; ++i) { List <Transaction <T> > partition = ReadInPartition(i, database); ItemSets <T> fis = GenerateLargeItemSets(partition, getMinItemSetSupport, domain); foreach (ItemSet <T> itemset in fis) { candidates.Add(itemset); } } int dbSize = 0; for (int i = 0; i < partitionCount; ++i) { List <Transaction <T> > partition = ReadInPartition(i, database); dbSize += partition.Count; foreach (ItemSet <T> itemset in candidates) { itemset.TransactionCount += GetCount(partition, itemset); } } foreach (ItemSet <T> itemset in candidates) { itemset.DbSize = dbSize; } ItemSets <T> C = new ItemSets <T>(); foreach (ItemSet <T> itemset in candidates) { if (itemset.Support >= getMinItemSetSupport(itemset)) { C.Add(itemset); } } return(C); }
private ItemSet <T> GetUnion(ItemSet <T> set1, ItemSet <T> set2, ItemSets <T> fis) { if (IsSubsetOf(set1, set2)) { return(set2); } else if (IsSubsetOf(set2, set1)) { return(set1); } HashSet <T> temp = new HashSet <T>(); for (int i = 0; i < set1.Count; ++i) { temp.Add(set1[i]); } for (int i = 0; i < set2.Count; ++i) { temp.Add(set2[i]); } List <T> temp2 = temp.ToList(); temp2.Sort(); ItemSet <T> merged_set = new ItemSet <T>(); for (int i = 0; i < temp2.Count; ++i) { merged_set.Add(temp2[i]); } for (int i = 0; i < fis.Count; ++i) { if (fis[i].Equals(merged_set)) { return(fis[i]); } } return(null); }
public List <ItemSets <T> > Compress(ItemSets <T> fis, int clusterCount) { double[][] distance_matrix = new double[fis.Count][]; for (int i = 0; i < fis.Count; ++i) { distance_matrix[i] = new double[fis.Count]; } for (int i = 0; i < fis.Count - 1; ++i) { for (int j = i + 1; j < fis.Count; ++j) { distance_matrix[i][j] = GetPatternDistance(fis[i], fis[j], fis); distance_matrix[i][j] = distance_matrix[j][i]; } } return(Cluster(distance_matrix, fis, clusterCount)); }
protected ItemSets <T> FindMaxPatterns(ItemSets <T> fis) { for (int i = fis.Count - 1; i >= 0; i--) { ItemSet <T> itemset = fis[i]; bool isSubSet = false; for (int j = 0; j < fis.Count; j++) { if (i == j) { continue; } isSubSet = true; ItemSet <T> itemset2 = fis[j]; if (itemset.Count > itemset2.Count) { isSubSet = false; break; } for (int k = 0; k < itemset.Count; ++k) { if (!itemset2.Contains(itemset[k])) { isSubSet = false; break; } } if (!isSubSet) { break; } } if (isSubSet) { fis.RemoveAt(i); } } return(fis); }
public ItemSets <T> MinePatterns(IEnumerable <Transaction <T> > database, IList <T> domain, GetMinSupportHandle getMinItemSetSupport) { Dictionary <T, int> counts = new Dictionary <T, int>(); for (int i = 0; i < domain.Count; ++i) { counts[domain[i]] = 0; } foreach (Transaction <T> transaction in database) { for (int i = 0; i < domain.Count; ++i) { if (transaction.ContainsItem(domain[i])) { counts[domain[i]]++; } } } List <T> freqItems = new List <T>(); for (int i = 0; i < domain.Count; ++i) { var xxx = getMinItemSetSupport(new ItemSet <T>() { domain[i] }); if (counts[domain[i]] >= getMinItemSetSupport(new ItemSet <T>() { domain[i] })) { freqItems.Add(domain[i]); } } T[] FList = freqItems.ToArray(); Array.Sort(FList, (i1, i2) => { int comp = counts[i1].CompareTo(counts[i2]); return(-comp); }); FPTree <T> fpTree = new FPTree <T>(); int dbSize = 0; foreach (Transaction <T> transaction in database) { dbSize++; List <T> orderedFreqItems = new List <T>(); for (int i = 0; i < FList.Length; ++i) { if (transaction.ContainsItem(FList[i])) { orderedFreqItems.Add(FList[i]); } } fpTree.AddOrderedFreqItems(orderedFreqItems); } fpTree.DbSize = dbSize; ItemSets <T> allItemSets = new ItemSets <T>(); for (int i = FList.Length - 1; i >= 0; i--) { T item = FList[i]; List <ItemSet <T> > fis = fpTree.MinePatternsContaining(item, getMinItemSetSupport(new ItemSet <T>() { item })); fpTree.RemoveFromLeaves(item); allItemSets.AddRange(fis); } return(allItemSets); }
static AssetProvider() { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssetViewer.Resources.Assets.RewardPools.xml")) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => s.FromXElement <Pool>())) { Pools.Add(item.ID, item); } } var items = new[] { "AssetViewer.Resources.Assets.GuildhouseItem.xml", "AssetViewer.Resources.Assets.HarborOfficeItem.xml", "AssetViewer.Resources.Assets.TownhallItem.xml", "AssetViewer.Resources.Assets.VehicleItem.xml", "AssetViewer.Resources.Assets.ShipSpecialist.xml", "AssetViewer.Resources.Assets.CultureItem.xml", "AssetViewer.Resources.Assets.Product.xml", "AssetViewer.Resources.Assets.ItemSpecialAction.xml", "AssetViewer.Resources.Assets.ActiveItem.xml", "AssetViewer.Resources.Assets.ItemSpecialActionVisualEffect.xml", "AssetViewer.Resources.Assets.ItemWithUI.xml", "AssetViewer.Resources.Assets.FluffItem.xml", "AssetViewer.Resources.Assets.QuestItemMagistrate.xml", "AssetViewer.Resources.Assets.StartExpeditionItem.xml", "AssetViewer.Resources.Assets.QuestItem.xml", }; foreach (var str in items) { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(str)) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => new TemplateAsset(s))) { Items.Add(item.ID, item); } } } var buildings = new[] { "AssetViewer.Resources.Assets.BuildPermitBuilding.xml", "AssetViewer.Resources.Assets.BuildPermitModules.xml", "AssetViewer.Resources.Assets.CultureModule.xml", "AssetViewer.Resources.Assets.OrnamentalModule.xml", "AssetViewer.Resources.Assets.BridgeBuilding.xml", "AssetViewer.Resources.Assets.CampaignQuestObject.xml", "AssetViewer.Resources.Assets.CampaignUncleMansion.xml", "AssetViewer.Resources.Assets.CityInstitutionBuilding.xml", "AssetViewer.Resources.Assets.CultureBuilding.xml", "AssetViewer.Resources.Assets.FactoryBuilding7.xml", "AssetViewer.Resources.Assets.FactoryBuilding7_Arctic.xml", "AssetViewer.Resources.Assets.FarmBuilding.xml", "AssetViewer.Resources.Assets.FarmBuilding_Arctic.xml", "AssetViewer.Resources.Assets.Farmfield.xml", "AssetViewer.Resources.Assets.FreeAreaBuilding.xml", "AssetViewer.Resources.Assets.FreeAreaBuilding_Arctic.xml", "AssetViewer.Resources.Assets.Guildhouse.xml", "AssetViewer.Resources.Assets.HarborBuildingAttacker.xml", "AssetViewer.Resources.Assets.HarborDepot.xml", "AssetViewer.Resources.Assets.HarborLandingStage7.xml", "AssetViewer.Resources.Assets.HarborOffice.xml", "AssetViewer.Resources.Assets.HarborPropObject.xml", "AssetViewer.Resources.Assets.HarborWarehouse7.xml", "AssetViewer.Resources.Assets.HarborWarehouseSlot7.xml", "AssetViewer.Resources.Assets.HarborWarehouseStrategic.xml", "AssetViewer.Resources.Assets.Heater_Arctic.xml", "AssetViewer.Resources.Assets.HeavyFactoryBuilding.xml", "AssetViewer.Resources.Assets.HeavyFreeAreaBuilding.xml", "AssetViewer.Resources.Assets.HeavyFreeAreaBuilding_Arctic.xml", "AssetViewer.Resources.Assets.ItemCrafterBuilding.xml", "AssetViewer.Resources.Assets.Market.xml", "AssetViewer.Resources.Assets.Monument.xml", "AssetViewer.Resources.Assets.Monument_with_Shipyard.xml", "AssetViewer.Resources.Assets.OilPumpBuilding.xml", "AssetViewer.Resources.Assets.OrnamentalBuilding.xml", "AssetViewer.Resources.Assets.PowerplantBuilding.xml", "AssetViewer.Resources.Assets.PublicServiceBuilding.xml", "AssetViewer.Resources.Assets.QuestLighthouse.xml", "AssetViewer.Resources.Assets.RepairCrane.xml", "AssetViewer.Resources.Assets.ResidenceBuilding7.xml", "AssetViewer.Resources.Assets.ResidenceBuilding7_Arctic.xml", "AssetViewer.Resources.Assets.Shipyard.xml", "AssetViewer.Resources.Assets.SimpleBuilding.xml", "AssetViewer.Resources.Assets.Slot.xml", "AssetViewer.Resources.Assets.SlotFactoryBuilding7.xml", "AssetViewer.Resources.Assets.SlotFactoryBuilding7_Arctic.xml", "AssetViewer.Resources.Assets.Street.xml", "AssetViewer.Resources.Assets.StreetBuilding.xml", "AssetViewer.Resources.Assets.VisitorPier.xml", "AssetViewer.Resources.Assets.VisualBuilding_NoLogic.xml", "AssetViewer.Resources.Assets.Warehouse.xml", "AssetViewer.Resources.Assets.WorkAreaSlot.xml", "AssetViewer.Resources.Assets.WorkforceConnector.xml", }; foreach (var str in buildings) { using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(str)) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => new TemplateAsset(s))) { Buildings.Add(item.ID, item); } } } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssetViewer.Resources.Assets.ItemSet.xml")) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => new TemplateAsset(s))) { ItemSets.Add(item.ID, item); } } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssetViewer.Resources.Assets.FestivalBuff.xml")) using (var reader = new StreamReader(stream)) { var document = XDocument.Parse(reader.ReadToEnd()).Root; foreach (var item in document.Elements().Select(s => new TemplateAsset(s))) { FestivalBuffs.Add(item.ID, item); } } }
protected ItemSets <T> GenerateLargeItemSets(List <Transaction <T> > partition, GetMinSupportHandle getMinItemSetSupport, IList <T> domain) { ItemSets <T> Fk = new ItemSets <T>(); for (int i = 0; i < domain.Count; ++i) { T item = domain[i]; ItemSet <T> itemset = new ItemSet <T>() { item }; for (int j = 0; j < partition.Count; ++j) { if (partition[j].ContainsItemSet(itemset)) { long tid = partition[j].ID; itemset.TransactionIDList.Add(tid); } } if (itemset.TransactionIDList.Count >= getMinItemSetSupport(itemset) * partition.Count) { Fk.Add(itemset); } } int k = 1; ItemSets <T> allFrequentItemSets = new ItemSets <T>(); allFrequentItemSets.AddRange(Fk); while (Fk.Count > 0) { ItemSets <T> Fkp1 = new ItemSets <T>(); //do self-join for (int i = 0; i < Fk.Count; ++i) { for (int j = 0; j < Fk.Count; ++j) { if (i == j) { continue; } bool canJoin = true; for (int l = 0; l < k - 1; ++l) { if (Fk[i][l].CompareTo(Fk[j][l]) != 0) { canJoin = false; break; } } if (canJoin) { if (CanJoin(Fk[i], Fk[j][k - 1])) { ItemSet <T> c = Union(Fk[i], Fk[j]); if (c.TransactionIDList.Count >= getMinItemSetSupport(c) * partition.Count) { Fkp1.Add(c); } } } } } allFrequentItemSets.AddRange(Fkp1); Fk = Fkp1; k++; } return(allFrequentItemSets); }
public virtual ItemSets <T> MinePatterns(GetCountHandle updateItemSetSupport, GetMinSupportHandle getMinItemSetSupport, IList <T> domain) { ItemSets <T> Fk = new ItemSets <T>(); List <ItemSet <T> > itemsetSup = new List <ItemSet <T> >(); for (int i = 0; i < domain.Count; ++i) { T item = domain[i]; ItemSet <T> itemset = new ItemSet <T>() { item }; itemset.TransactionCount = 0; itemsetSup.Add(itemset); } updateItemSetSupport(itemsetSup); foreach (ItemSet <T> itemset in itemsetSup) { if (itemset.Support >= getMinItemSetSupport(itemset)) { Fk.Add(itemset); } } int k = 1; ItemSets <T> allFrequentItemSets = new ItemSets <T>(); allFrequentItemSets.AddRange(Fk); while (Fk.Count > 0) { ItemSets <T> Fkp1 = new ItemSets <T>(); //do self-join for (int i = 0; i < Fk.Count; ++i) { for (int j = 0; j < Fk.Count; ++j) { if (i == j) { continue; } bool canJoin = true; for (int l = 0; l < k - 1; ++l) { if (Fk[i][l].CompareTo(Fk[j][l]) != 0) { canJoin = false; break; } } if (canJoin) { if (CanJoin(Fk[i], Fk[j][k - 1])) { ItemSet <T> c = Fk[i].Clone(); c.Add(Fk[j][k - 1]); Fkp1.Add(c); } } } } updateItemSetSupport(Fkp1); List <ItemSet <T> > fis = new List <ItemSet <T> >(); foreach (ItemSet <T> itemset in Fkp1) { if (itemset.Support >= getMinItemSetSupport(itemset)) { fis.Add(itemset); } } allFrequentItemSets.AddRange(fis); Fk.Clear(); Fk.AddRange(fis); k++; } return(allFrequentItemSets); }
private void RefreshEquipmentStats() { Weapon = -1; WeaponEffect = 0; Armour = 0; WingEffect = 0; MountType = -1; CurrentWearWeight = 0; CurrentHandWeight = 0; ItemMode = SpecialItemMode.None; FastRun = false; ItemSets.Clear(); MirSet.Clear(); for (int i = 0; i < Equipment.Length; i++) { UserItem temp = Equipment[i]; if (temp == null) { continue; } ItemInfo RealItem = Functions.GetRealItem(temp.Info, Level, Class, GameScene.ItemInfoList); if (RealItem.Type == ItemType.Weapon || RealItem.Type == ItemType.Torch) { CurrentHandWeight = (int)Math.Min(int.MaxValue, CurrentHandWeight + temp.Weight); } else { CurrentWearWeight = (int)Math.Min(int.MaxValue, CurrentWearWeight + temp.Weight); } if (temp.CurrentDura == 0 && RealItem.Durability > 0) { continue; } Stats.Add(RealItem.Stats); Stats.Add(temp.AddedStats); Stats[Stat.MinAC] += temp.Awake.GetAC(); Stats[Stat.MaxAC] += temp.Awake.GetAC(); Stats[Stat.MinMAC] += temp.Awake.GetMAC(); Stats[Stat.MaxMAC] += temp.Awake.GetMAC(); Stats[Stat.MinDC] += temp.Awake.GetDC(); Stats[Stat.MaxDC] += temp.Awake.GetDC(); Stats[Stat.MinMC] += temp.Awake.GetMC(); Stats[Stat.MaxMC] += temp.Awake.GetMC(); Stats[Stat.MinSC] += temp.Awake.GetSC(); Stats[Stat.MaxSC] += temp.Awake.GetSC(); Stats[Stat.HP] += temp.Awake.GetHPMP(); Stats[Stat.MP] += temp.Awake.GetHPMP(); if (RealItem.Light > Light) { Light = RealItem.Light; } if (RealItem.Unique != SpecialItemMode.None) { ItemMode |= RealItem.Unique; } if (RealItem.CanFastRun) { FastRun = true; } RefreshSocketStats(temp); if (RealItem.Type == ItemType.Armour) { Armour = RealItem.Shape; WingEffect = RealItem.Effect; } if (RealItem.Type == ItemType.Weapon) { Weapon = RealItem.Shape; WeaponEffect = RealItem.Effect; } if (RealItem.Type == ItemType.Mount) { MountType = RealItem.Shape; } if (RealItem.Set == ItemSet.None) { continue; } ItemSets itemSet = ItemSets.Where(set => set.Set == RealItem.Set && !set.Type.Contains(RealItem.Type) && !set.SetComplete).FirstOrDefault(); if (itemSet != null) { itemSet.Type.Add(RealItem.Type); itemSet.Count++; } else { ItemSets.Add(new ItemSets { Count = 1, Set = RealItem.Set, Type = new List <ItemType> { RealItem.Type } }); } //Mir Set if (RealItem.Set == ItemSet.Mir) { if (!MirSet.Contains((EquipmentSlot)i)) { MirSet.Add((EquipmentSlot)i); } } } if (ItemMode.HasFlag(SpecialItemMode.Muscle)) { Stats[Stat.BagWeight] = Stats[Stat.BagWeight] * 2; Stats[Stat.WearWeight] = Stats[Stat.WearWeight] * 2; Stats[Stat.HandWeight] = Stats[Stat.HandWeight] * 2; } }
private void RefreshEquipmentStats() { Weapon = -1; WeaponEffect = 0; Armour = 0; WingEffect = 0; MountType = -1; CurrentWearWeight = 0; CurrentHandWeight = 0; HasTeleportRing = false; HasProtectionRing = false; HasMuscleRing = false; HasParalysisRing = false; HasProbeNecklace = false; HasSkillNecklace = false; NoDuraLoss = false; FastRun = false; short Macrate = 0, Acrate = 0, HPrate = 0, MPrate = 0; ItemSets.Clear(); MirSet.Clear(); for (int i = 0; i < Equipment.Length; i++) { UserItem temp = Equipment[i]; if (temp == null) { continue; } ItemInfo RealItem = Functions.GetRealItem(temp.Info, Level, Class, GameScene.ItemInfoList); if (RealItem.Type == ItemType.Weapon || RealItem.Type == ItemType.Torch) { CurrentHandWeight = (ushort)Math.Min(ushort.MaxValue, CurrentHandWeight + temp.Weight); } else { CurrentWearWeight = (ushort)Math.Min(ushort.MaxValue, CurrentWearWeight + temp.Weight); } if (temp.CurrentDura == 0 && RealItem.Durability > 0) { continue; } MinAC = (ushort)Math.Min(ushort.MaxValue, MinAC + RealItem.MinAC + temp.Awake.GetAC()); MaxAC = (ushort)Math.Min(ushort.MaxValue, MaxAC + RealItem.MaxAC + temp.AC + temp.Awake.GetAC()); MinMAC = (ushort)Math.Min(ushort.MaxValue, MinMAC + RealItem.MinMAC + temp.Awake.GetMAC()); MaxMAC = (ushort)Math.Min(ushort.MaxValue, MaxMAC + RealItem.MaxMAC + temp.MAC + temp.Awake.GetMAC()); MinDC = (ushort)Math.Min(ushort.MaxValue, MinDC + RealItem.MinDC + temp.Awake.GetDC()); MaxDC = (ushort)Math.Min(ushort.MaxValue, MaxDC + RealItem.MaxDC + temp.DC + temp.Awake.GetDC()); MinMC = (ushort)Math.Min(ushort.MaxValue, MinMC + RealItem.MinMC + temp.Awake.GetMC()); MaxMC = (ushort)Math.Min(ushort.MaxValue, MaxMC + RealItem.MaxMC + temp.MC + temp.Awake.GetMC()); MinSC = (ushort)Math.Min(ushort.MaxValue, MinSC + RealItem.MinSC + temp.Awake.GetSC()); MaxSC = (ushort)Math.Min(ushort.MaxValue, MaxSC + RealItem.MaxSC + temp.SC + temp.Awake.GetSC()); Accuracy = (byte)Math.Min(byte.MaxValue, Accuracy + RealItem.Accuracy + temp.Accuracy); Agility = (byte)Math.Min(byte.MaxValue, Agility + RealItem.Agility + temp.Agility); MaxHP = (ushort)Math.Min(ushort.MaxValue, MaxHP + RealItem.HP + temp.HP + temp.Awake.GetHPMP()); MaxMP = (ushort)Math.Min(ushort.MaxValue, MaxMP + RealItem.MP + temp.MP + temp.Awake.GetHPMP()); ASpeed = (sbyte)Math.Max(sbyte.MinValue, (Math.Min(sbyte.MaxValue, ASpeed + temp.AttackSpeed + RealItem.AttackSpeed))); Luck = (sbyte)Math.Max(sbyte.MinValue, (Math.Min(sbyte.MaxValue, Luck + temp.Luck + RealItem.Luck))); MaxBagWeight = (ushort)Math.Max(ushort.MinValue, (Math.Min(ushort.MaxValue, MaxBagWeight + RealItem.BagWeight))); MaxWearWeight = (ushort)Math.Max(ushort.MinValue, (Math.Min(ushort.MaxValue, MaxWearWeight + RealItem.WearWeight))); MaxHandWeight = (ushort)Math.Max(ushort.MinValue, (Math.Min(ushort.MaxValue, MaxHandWeight + RealItem.HandWeight))); HPrate = (short)Math.Max(short.MinValue, Math.Min(short.MaxValue, HPrate + RealItem.HPrate)); MPrate = (short)Math.Max(short.MinValue, Math.Min(short.MaxValue, MPrate + RealItem.MPrate)); Acrate = (short)Math.Max(short.MinValue, Math.Min(short.MaxValue, Acrate + RealItem.MaxAcRate)); Macrate = (short)Math.Max(short.MinValue, Math.Min(short.MaxValue, Macrate + RealItem.MaxMacRate)); MagicResist = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, MagicResist + temp.MagicResist + RealItem.MagicResist))); PoisonResist = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, PoisonResist + temp.PoisonResist + RealItem.PoisonResist))); HealthRecovery = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, HealthRecovery + temp.HealthRecovery + RealItem.HealthRecovery))); SpellRecovery = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, SpellRecovery + temp.ManaRecovery + RealItem.SpellRecovery))); PoisonRecovery = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, PoisonRecovery + temp.PoisonRecovery + RealItem.PoisonRecovery))); CriticalRate = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, CriticalRate + temp.CriticalRate + RealItem.CriticalRate))); CriticalDamage = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, CriticalDamage + temp.CriticalDamage + RealItem.CriticalDamage))); Holy = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, Holy + RealItem.Holy))); Freezing = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, Freezing + temp.Freezing + RealItem.Freezing))); PoisonAttack = (byte)Math.Max(byte.MinValue, (Math.Min(byte.MaxValue, PoisonAttack + temp.PoisonAttack + RealItem.PoisonAttack))); HpDrainRate = (byte)Math.Max(100, Math.Min(byte.MaxValue, HpDrainRate + RealItem.HpDrainRate)); if (RealItem.Light > Light) { Light = RealItem.Light; } if (RealItem.Unique != SpecialItemMode.None) { if (RealItem.Unique.HasFlag(SpecialItemMode.Paralize)) { HasParalysisRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Teleport)) { HasTeleportRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Clearring)) { HasClearRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Protection)) { HasProtectionRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Revival)) { HasRevivalRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Muscle)) { HasMuscleRing = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Probe)) { HasProbeNecklace = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.Skill)) { HasSkillNecklace = true; } if (RealItem.Unique.HasFlag(SpecialItemMode.NoDuraLoss)) { NoDuraLoss = true; } } if (RealItem.CanFastRun) { FastRun = true; } if (RealItem.Type == ItemType.Armour) { Armour = RealItem.Shape; WingEffect = RealItem.Effect; } if (RealItem.Type == ItemType.Weapon) { Weapon = RealItem.Shape; WeaponEffect = RealItem.Effect; } if (RealItem.Type == ItemType.Mount) { MountType = RealItem.Shape; } if (RealItem.Set == ItemSet.None) { continue; } ItemSets itemSet = ItemSets.Where(set => set.Set == RealItem.Set && !set.Type.Contains(RealItem.Type) && !set.SetComplete).FirstOrDefault(); if (itemSet != null) { itemSet.Type.Add(RealItem.Type); itemSet.Count++; } else { ItemSets.Add(new ItemSets { Count = 1, Set = RealItem.Set, Type = new List <ItemType> { RealItem.Type } }); } //Mir Set if (RealItem.Set == ItemSet.Mir) { if (!MirSet.Contains((EquipmentSlot)i)) { MirSet.Add((EquipmentSlot)i); } } } MaxHP = (ushort)Math.Min(ushort.MaxValue, (((double)HPrate / 100) + 1) * MaxHP); MaxMP = (ushort)Math.Min(ushort.MaxValue, (((double)MPrate / 100) + 1) * MaxMP); MaxAC = (ushort)Math.Min(ushort.MaxValue, (((double)Acrate / 100) + 1) * MaxAC); MaxMAC = (ushort)Math.Min(ushort.MaxValue, (((double)Macrate / 100) + 1) * MaxMAC); if (HasMuscleRing) { MaxBagWeight = (ushort)(MaxBagWeight * 2); MaxWearWeight = Math.Min(ushort.MaxValue, (ushort)(MaxWearWeight * 2)); MaxHandWeight = Math.Min(ushort.MaxValue, (ushort)(MaxHandWeight * 2)); } }
/// <summary> /// /// </summary> /// <param name="database"></param> /// <param name="domain"></param> /// <param name="epsilon">e.g., epsilon = 0.01</param> /// <returns></returns> public ItemSets <T> FindNegativePatterns(IEnumerable <Transaction <T> > database, IList <T> domain, double epsilon) { ItemSet <T>[] itemsets = new ItemSet <T> [domain.Count]; for (int i = 0; i < domain.Count; ++i) { itemsets[i] = new ItemSet <T>() { domain[i] }; } int dbSize = 0; foreach (Transaction <T> transaction in database) { for (int i = 0; i < domain.Count; ++i) { if (transaction.ContainsItem(domain[i])) { itemsets[i].TransactionCount++; } } dbSize++; } for (int i = 0; i < domain.Count; ++i) { itemsets[i].DbSize = dbSize; } List <ItemSet <T> > patterns = new List <ItemSet <T> >(); for (int i = 0; i < domain.Count; ++i) { for (int j = 0; j < domain.Count; ++j) { if (i == j) { continue; } if (itemsets[i][0].CompareTo(itemsets[j][0]) < 0) { patterns.Add(new ItemSet <T>() { itemsets[i][0], itemsets[j][0] }); } } } foreach (Transaction <T> transaction in database) { for (int i = 0; i < patterns.Count; ++i) { if (transaction.ContainsItemSet(patterns[i])) { patterns[i].TransactionCount++; } } } for (int i = 0; i < patterns.Count; ++i) { patterns[i].DbSize = dbSize; } ItemSets <T> nis = new ItemSets <T>(); for (int i = 0; i < patterns.Count; ++i) { T itemA = patterns[i][0]; T itemB = patterns[i][1]; int indexA = domain.IndexOf(itemA); int indexB = domain.IndexOf(itemB); ItemSet <T> A = itemsets[indexA]; ItemSet <T> B = itemsets[indexB]; double score = Evaluation.Kulczynski(A, B, patterns[i]); if (score < epsilon) { nis.Add(patterns[i]); } } return(nis); }