Esempio n. 1
0
 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);
             }
         }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
                    }
                }
        }