public void AddUnlimitedStack() { var set = new ItemSet(); var item = new Item { Id = "test", ShortDescr = "test", MaxCount = 0 }; item.AddQuantity(10); set.Add(item); Assert.AreEqual(1, set.Count); Assert.AreEqual(10, set.CountItems("test")); var item2 = new Item(item); item2.AddQuantity(7); set.Add(item2); Assert.AreEqual(1, set.Count); Assert.AreEqual(17, set.CountItems("test")); var item3 = new Item(item); item3.AddQuantity(70); set.Add(item3); Assert.AreEqual(1, set.Count); Assert.AreEqual(87, set.CountItems("test")); }
public void RemoveItems() { var set = new ItemSet(); var item1 = new Item { Id = "test", ShortDescr = "Test", MaxCount = 20 }; item1.AddQuantity(10); set.Add(item1); var item2 = new Item(item1); item2.AddQuantity(17); set.Add(item2); var removed1 = set.Remove("test", 1); Assert.AreEqual(1, removed1.Count); Assert.AreEqual(1, removed1.CountItems("test")); Assert.AreEqual(2, set.Count); Assert.AreEqual(26, set.CountItems("test")); var removed2 = set.Remove("test", 9); Assert.AreEqual(1, removed2.Count); Assert.AreEqual(9, removed2.CountItems("test")); Assert.AreEqual(1, set.Count); Assert.AreEqual(17, set.CountItems("test")); var removed3 = set.Remove("test", 200); Assert.AreEqual(1, removed3.Count); Assert.AreEqual(17, removed3.CountItems("test")); Assert.AreEqual(0, set.Count); set.Add(item1); var removed4 = set.Remove("test_new", 1); Assert.AreEqual(1, set.Count); Assert.IsNull(removed4); var itemNoStack = new Item { Id = "test_nostack" }; set.Add(itemNoStack); var removed5 = set.Remove("test_nostack", 100); Assert.AreEqual(1, set.Count); Assert.AreEqual(1, removed5.Count); Assert.IsTrue(removed5.Contains(itemNoStack)); }
/// <summary> /// First step in Apriori algorithm responsible for the generation of candidate k+1 itemset /// starting from k frequent itemset. The generated candidate itemsets could be frequent or not /// hence the term candidate /// </summary> /// <param name="FrequentItemSets">The k generation Frequent ItemSets</param> /// <param name="k">the generation (lenght of current itemsets)</param> /// <returns>Generated list of candidate ItemSets</returns> private List <ItemSet> CandidateGen(Dictionary <ItemSet, bool> FrequentItemSets, int k) { List <ItemSet> NewCandidateSet = new List <ItemSet>(); ItemSet NewCandidate; int ok; //Join Step: a candidate is generated joining two frequent itemsets following a //particular query: //select p.item1,p.item2,. . . ,p.itemk,q.itemk, (k+1 elements) //from Lk p,Lk q //where (p.item1 = q.item1,p.item2 = q.item2,. . . ,p.itemk < q.itemk) foreach (ItemSet itemset in FrequentItemSets.Keys) { foreach (int frequentitem in FrequentItems.Keys) { if (itemset.Items[itemset.ItemsNumber - 1] < frequentitem) { NewCandidate = new ItemSet(); NewCandidate.ItemsSupport = 0; foreach (int item in itemset.Items) { NewCandidate.Add(item); } NewCandidate.Add(frequentitem); //Pruning, based on anti-monotonicity itemset principle (see paper) ok = 0; for (int i = 0; i < k; i++) { ItemSet test = new ItemSet(); for (int j = 0; j < k; j++) { if (j != i) { test.Add(NewCandidate.Items[j]); } } if (FrequentItemSets.ContainsKey(test)) { ok++; // This itemset is contained in the frequent list } else { i = k; // exit from loop this itemset is not contained } } if (ok == k) { NewCandidateSet.Add(NewCandidate); } } } } return(NewCandidateSet); }
/// <summary> /// Efficient optimization in frequent pattern generation when an FPTree present only a single path /// Generated frequent are automatically inserted in result (frequent pattern pool). /// The method enumerates all combinations of node in FPTree fp using efficiently bit operators /// </summary> /// <param name="fp">Single path FPtree </param> /// <param name="given">ItemSet given prefix</param> private void GenerateCombPattern(FPTree fp, ItemSet given) { int bits = fp.Depth; UInt64 enumerator = 1; UInt64 combination; UInt64 max = 1; int index; int[] itemsetArray = new int[fp.Depth]; int[] supportArray = new int[fp.Depth]; int betaSupport; fp.Travel = fp.Root; for (int i = 0; i < fp.Depth; i++) { fp.Travel = fp.Travel.Childs[0]; itemsetArray[i] = fp.Travel.Item; supportArray[i] = fp.Travel.Count; } Array.Reverse(itemsetArray); Array.Reverse(supportArray); //Max represent the overflow condition max = max << bits; //Our enumerator is represented through a 64 bit integer while (enumerator < max) { // Create a new beta result ItemSet beta = new ItemSet(); betaSupport = 0; foreach (int item in given.Items) { beta.Add(item); } index = 0; combination = enumerator; while (combination > 0) { if ((combination % 2) == 1) { beta.Add(itemsetArray[index]); if ((betaSupport > supportArray[index]) || (betaSupport == 0)) { betaSupport = supportArray[index]; } } combination = combination >> 1; index++; } enumerator++; beta.ItemsSupport = betaSupport; result.Add(beta); } }
public CovarianceMaternIso() : base() { Name = ItemName; Description = ItemDescription; Parameters.Add(new OptionalValueParameter<DoubleValue>("InverseLength", "The inverse length parameter of the isometric Matern covariance function.")); Parameters.Add(new OptionalValueParameter<DoubleValue>("Scale", "The scale parameter of the isometric Matern covariance function.")); var validDValues = new ItemSet<IntValue>(); validDValues.Add((IntValue)new IntValue(1).AsReadOnly()); validDValues.Add((IntValue)new IntValue(3).AsReadOnly()); validDValues.Add((IntValue)new IntValue(5).AsReadOnly()); Parameters.Add(new ConstrainedValueParameter<IntValue>("D", "The d parameter (allowed values: 1, 3, or 5) of the isometric Matern covariance function.", validDValues, validDValues.First())); }
public void AddWithItemCount() { var set = new ItemSet(); var itemWithoutStack = new Item { Id = "test_1", ShortDescr = "Test1" }; set.Add(itemWithoutStack, 1); Assert.AreEqual(1, set.CountItems("test_1")); set.Add(itemWithoutStack, 3); Assert.AreEqual(4, set.CountItems("test_1")); var itemWithoutStack2 = new Item { Id = "test_2", ShortDescr = "Test2" }; set.Add(itemWithoutStack2, 2); Assert.AreEqual(2, set.CountItems("test_2")); var itemWithLimitedStack = new Item { Id = "test_3", ShortDescr = "Test3", MaxCount = 5 }; itemWithLimitedStack.AddQuantity(1); set.Add(itemWithLimitedStack, 1); Assert.AreEqual(1, set.CountItems("test_3")); set.Add(itemWithLimitedStack, 1); Assert.AreEqual(2, set.CountItems("test_3")); Assert.AreEqual(1, set.Count(item => item.Id == "test_3")); set.Add(itemWithLimitedStack, 4); Assert.AreEqual(6, set.CountItems("test_3")); Assert.AreEqual(2, set.Count(item => item.Id == "test_3")); set.Add(itemWithLimitedStack, 100); Assert.AreEqual(106, set.CountItems("test_3")); Assert.AreEqual(22, set.Count(item => item.Id == "test_3")); var itemWithUnlimitedStack = new Item { Id = "test_4", ShortDescr = "Test3", MaxCount = 0 }; itemWithUnlimitedStack.AddQuantity(1); set.Add(itemWithUnlimitedStack, 1); Assert.AreEqual(1, set.CountItems("test_4")); set.Add(itemWithUnlimitedStack, 200); Assert.AreEqual(201, set.CountItems("test_4")); }
public CovarianceMaternIso() : base() { Name = ItemName; Description = ItemDescription; Parameters.Add(new OptionalValueParameter <DoubleValue>("InverseLength", "The inverse length parameter of the isometric Matern covariance function.")); Parameters.Add(new OptionalValueParameter <DoubleValue>("Scale", "The scale parameter of the isometric Matern covariance function.")); var validDValues = new ItemSet <IntValue>(); validDValues.Add((IntValue) new IntValue(1).AsReadOnly()); validDValues.Add((IntValue) new IntValue(3).AsReadOnly()); validDValues.Add((IntValue) new IntValue(5).AsReadOnly()); Parameters.Add(new ConstrainedValueParameter <IntValue>("D", "The d parameter (allowed values: 1, 3, or 5) of the isometric Matern covariance function.", validDValues, validDValues.First())); }
private void DiscoverBenchmarks() { var benchmarks = from t in ApplicationManager.Manager.GetTypes(typeof(IBenchmark)) select t; ItemSet <IBenchmark> values = new ItemSet <IBenchmark>(); foreach (var benchmark in benchmarks) { IBenchmark b = (IBenchmark)Activator.CreateInstance(benchmark); values.Add(b); } string paramName = "Benchmark"; if (!Parameters.ContainsKey(paramName)) { if (values.Count > 0) { Parameters.Add(new ConstrainedValueParameter <IBenchmark>(paramName, "The benchmark which should be executed.", values, values.First(a => a is IBenchmark))); } else { Parameters.Add(new ConstrainedValueParameter <IBenchmark>(paramName, "The benchmark which should be executed.", values)); } } }
//???? private ItemSet SubSet(ItemSet set, int t) { ItemSet subSet = new ItemSet(); ItemSet itemSet = new ItemSet(); //???2n?? int num = 1 << set.Count; int bit; int mask = 0;; for (int i = 0; i < num; i++) { itemSet = new ItemSet(); for (int j = 0; j < set.Count; j++) { //mask?i?????????? mask = 1 << j; bit = i & mask; if (bit > 0) { itemSet.Add((DataItem)set.arr[j]); } } if (itemSet.Count == t) { subSet.Add(itemSet); } } return(subSet); }
protected ItemSet <T> Union(ItemSet <T> is1, ItemSet <T> is2) { ItemSet <T> c = is1.Clone(); c.Add(is2[is2.Count - 1]); foreach (long id2 in is2.TransactionIDList) { bool isFound = false; foreach (long id1 in is1.TransactionIDList) { if (id1 == id2) { isFound = true; break; } } if (isFound) { c.TransactionIDList.Add(id2); } } return(c); }
public void RemoveOneItem() { var set = new ItemSet(); var item = new Item { Id = "test", ShortDescr = "test", MaxCount = 20 }; item.AddQuantity(10); set.Add(item); Assert.IsTrue(set.Remove(item)); Assert.AreEqual(0, set.Count); Assert.AreEqual(0, set.CountItems("test")); set.Add(item); set.Add(item); Assert.AreEqual(1, set.Count); Assert.AreEqual(20, set.CountItems("test")); }
public void AddOneItem() { var set = new ItemSet(); var item = new Item { Id = "test", ShortDescr = "test" }; set.Add(item); Assert.AreEqual(1, set.Count); }
public ItemSet Read(string file) { StreamReader csvfile = new StreamReader(file); ItemSet General = new ItemSet(); ItemSet items = new ItemSet(); DataItem set = new DataItem(); string Line = ""; string temp = ""; int start = 0; int id = 0; int tcn = 0; Line = csvfile.ReadLine(); while (!csvfile.EndOfStream) { Line = csvfile.ReadLine(); tcn++; items = new ItemSet(); while (Line.IndexOf(",") != -1) { set = new DataItem(); temp = Line.Substring(0, Line.IndexOf(",")); Line = Line.Substring(Line.IndexOf(",") + 1); set.Add(temp, id); items.Add(set); id++; start = Line.IndexOf(","); } temp = Line; set.Add(temp, id); items.Add(set); id = 0; temp = ""; start = 0; General.Add(items); } //General.Add(items); Console.WriteLine("Total count" + General.Count); return(General); }
private ItemSet FindOneColSet(ItemSet data, double support) { ItemSet cur = null; ItemSet result = new ItemSet(); ItemSet set = null; ItemSet newset = null; DataItem cd = null; DataItem td = null; bool flag = true; for (int i = 0; i < data.Count; i++) { cur = (ItemSet)data.arr[i]; for (int j = 0; j < cur.Count; j++) { cd = (DataItem)cur.arr[j]; for (int n = 0; n < result.Count; n++) { set = (ItemSet)result.arr[n]; td = (DataItem)set.arr[0]; Console.WriteLine(cd.ItemName + " " + td.ItemName); if (cd.Id == td.Id) { set.ICount++; flag = false; break; } flag = true; } if (flag) { newset = new ItemSet(); newset.Add(cd); result.Add(newset); newset.ICount = 1; } } } ItemSet finalResult = new ItemSet(); for (int i = 0; i < result.Count; i++) { ItemSet con = (ItemSet)result.arr[i]; if (con.ICount >= support) { finalResult.Add(con); } } //finalResult.Sort(); return(finalResult); }
/// <summary> /// Method invoked for building the first FPTree representation of the /// original database /// </summary> /// <param name="startdb">The list of database transactions</param> public void BuildFirstTree(List <ItemSet> startdb) { // Counting the frequency of single items FrequencyItemCounter = new Dictionary <int, int>(); FrequencyItemCounter = CountFrequencyItem(startdb); // Evaluate header table dimension int HTsize = 0; foreach (int item in FrequencyItemCounter.Keys) { if (FrequencyItemCounter[item] >= _minSup) { HTsize++; } } ht = new HeaderTable(HTsize); // Add every frequent single itemset to header table foreach (KeyValuePair <int, int> coppia in FrequencyItemCounter) { if (coppia.Value >= _minSup) { ht.addRecord(coppia.Key, coppia.Value); } } // Removal of non frequent items, sorting and final insertion in the FPTreee ItemSet SortedList = new ItemSet(); foreach (ItemSet itemset in startdb) { SortedList.Items.Clear(); for (int i = 0; i < itemset.ItemsNumber; i++) { if (FrequencyItemCounter[itemset.Items[i]] >= _minSup) { SortedList.Add(itemset.Items[i]); } } if (SortedList.ItemsNumber > 0) { SortedList.Items.Sort(new ItemSortingStrategy(FrequencyItemCounter)); if (_depth < SortedList.ItemsNumber) { _depth = SortedList.ItemsNumber; } AddItemSetTree(SortedList, Root); } } startdb = null; }
public void RemoveItemsUnlimitedStack() { var set = new ItemSet(); var item = new Item { Id = "test", ShortDescr = "test", MaxCount = 0 }; item.AddQuantity(10); set.Add(item); var item2 = new Item(item); item2.AddQuantity(17); set.Add(item2); var removed1 = set.Remove("test", 100); Assert.AreEqual(1, removed1.Count); Assert.AreEqual(27, removed1.CountItems("test")); Assert.AreEqual(0, set.Count); }
public static ItemSet Go(this ItemSet itemset,char c) { ItemSet set=new ItemSet(); foreach (Item i in itemset) { if (i.Index < i.Production.Right.Length && i.Production.Right[i.Index] == c) { Item item = new Item(i.Production, i.Index + 1, i.Symbol); set.Add(item); } } return set; }
public void EvaluateAndLoadAssignment(int[] assignment) { if (assignment == null || assignment.Length == 0) { return; } var vector = new Permutation(PermutationTypes.Absolute, assignment); var result = QAPEvaluator.Apply(vector, Weights, Distances); BestKnownQuality = new DoubleValue(result); BestKnownSolution = vector; BestKnownSolutions = new ItemSet <Permutation>(); BestKnownSolutions.Add((Permutation)vector.Clone()); }
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 ItemSet <T> GetPath() { ItemSet <T> path = new ItemSet <T>(); FPTreeNode <T> x = this; while (x != null) { if (!x.IsRoot) { path.Add(x.Item); } x = x.Parent; } return(path); }
public async Task <bool> AddProduction(long?customerId, long productId) { var product = await DbContext.Set <Product>().FindAsync(productId); if (product != null && product.Quantity > 0) { ItemSet.Add(new Cart() { UserId = customerId, ProductId = productId }); --product.Quantity; DbContext.Set <Product>().Update(product); return(await DbContext.SaveChangesAsync() > 0); } return(false); }
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); }
/// <summary> /// Iterative rules generating method /// </summary> /// <param name="itemset">Frequent pattern ItemSet from which we generate rules</param> /// <param name="LookupRules">LookUp association rule list</param> private void GenRule(ItemSet itemset, List <AssociationRule> LookupRules) { int bits = itemset.ItemsNumber; UInt64 enumerator = 1; UInt64 combination; UInt64 max = 1; int index; // max represent "overflow" condition max = max << bits; while (enumerator < max) { index = 0; combination = enumerator; // left side creation LHR (am_1) ItemSet am_1 = new ItemSet(); while (combination > 0) { if ((combination % 2) == 1) { am_1.Add(itemset.Items[index]); } combination = combination >> 1; index++; } // Current rule creation AssociationRule rule = new AssociationRule(); rule.LeftSide = am_1; rule.RightSide = itemset - am_1; rule.LeftSide.ItemsSupport = 0; rule.RightSide.ItemsSupport = 0; rule.Support = itemset.ItemsSupport; if (!((rule.LeftSide.ItemsNumber == 0) || (rule.RightSide.ItemsNumber == 0))) { LookupRules.Add(rule); } enumerator++; } }
public DocumentOrderNodeIterator(XPath2NodeIterator baseIter) { bool?isNode = null; itemSet = new ItemSet(); while (baseIter.MoveNext()) { if (!isNode.HasValue) { isNode = baseIter.Current.IsNode; } else if (baseIter.Current.IsNode != isNode) { throw new XPath2Exception("XPTY0018", Resources.XPTY0018, baseIter.Current.Value); } itemSet.Add(baseIter.Current.Clone()); } if (isNode.HasValue && isNode.Value) { itemSet.Sort(); } }
private void results_Closed(object sender, EventArgs e) { OptimizerResults results = sender as OptimizerResults; if (results.DialogResult.GetValueOrDefault()) { if (results.WeWantToStoreIt) { ItemSet newItemSet = new ItemSet() { Name = string.Format("Optimized GearSet {0}", character.GetNumItemSetsFromOptimizer() + 1) }; foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { newItemSet.Add(results.BestCharacter[cs]); } character.AddToItemSetList(newItemSet); } else { character.IsLoading = true; character.SetItems(results.BestCharacter); character.ActiveBuffs = results.BestCharacter.ActiveBuffs; if (CK_Talents_Points.IsChecked.GetValueOrDefault()) { character.CurrentTalents = results.BestCharacter.CurrentTalents; MainPage.Instance.TalentPicker.RefreshSpec(); } character.IsLoading = false; character.OnCalculationsInvalidated(); } DialogResult = true; } else { ControlsEnabled(true); } }
public Item GetSample(Item item) { if (!samples.Contains(item)) { Item sample; if (item.IsFungible()) { sample = item.Copy(); sample.Quantity = 1; sample.transform.SetParent(transform); } else { sample = item; } samples.Add(sample); } return(samples.Get(item)); }
/// <summary> /// Main frequent pattern extraction method that implement Apriori logic /// </summary> /// <param name="AllTrans">Total list of input transaction</param> /// <returns>Frequent ItemSets</returns> public List <ItemSet> ExtractFrequentPattern(List <Transaction> AllTrans) { // compute absolute support = relative support * # of transactions absMinSup = (int)System.Math.Ceiling(AllTrans.Count * _minSup); // Sort item inside every database transaction (itemset sorting) foreach (Transaction trans in AllTrans) { trans.sort(); } // Compute support for 1-itemset and store in FrequentItems dictionary foreach (Transaction trans in AllTrans) { foreach (int product in trans.Itemset.Items) { if (FrequentItems.ContainsKey(product)) { FrequentItems[product]++; } else { FrequentItems.Add(product, 1); } } } // Evaluate those 1-itemset whose support is greater than minimum support // and add them to both frequent 1-itemset and final frequent itemsets result foreach (int product in FrequentItems.Keys) { if (FrequentItems[product] >= absMinSup) { ItemSet frequent = new ItemSet(); frequent.Add(product); frequent.ItemsSupport = FrequentItems[product]; FrequentItemSets.Add(frequent, true); Result.Add(frequent); } } //Build Look Up frequent items table FrequentItems.Clear(); foreach (ItemSet itemset in FrequentItemSets.Keys) { FrequentItems.Add(itemset.Items[0], 0); } // Remove unfrequent item from transactions list foreach (Transaction trans in AllTrans) { Transaction ReducedTrans = new Transaction(); foreach (int item in trans.Itemset.Items) { if (FrequentItems.ContainsKey(item)) { ReducedTrans.addItem(item); } } if (ReducedTrans.Itemset.Items.Count > 0) { FlaggedDB.Add(ReducedTrans); } } AllTrans = FlaggedDB; // Apriori main loop, we already computed frequent (k=1) itemset for (k = 2; FrequentItemSets.Count > 0; k++) { // Candidate generation CandidateItemSets = CandidateGen(FrequentItemSets, k); // Evalute support for the generated frequent candidate CalcSupport(AllTrans, CandidateItemSets); FrequentItemSets.Clear(); // Check if every candidate itemset is a frequent or not and if it is, // add it to final result foreach (ItemSet itemset in CandidateItemSets) { if (itemset.ItemsSupport >= absMinSup) { FrequentItemSets.Add(itemset, true); Result.Add(itemset); } } } return(Result); }
protected bool AddOperator(IOperator @operator) { return(encodingOperators.Add(@operator)); }
/// <summary> /// Frequent pattern extraction method that implement FPGrowth logic using an /// iterative pattern growth approach /// </summary> /// <param name="allTrans">Total list of input transaction</param> /// <returns>Frequent ItemSets</returns> public List <ItemSet> ExtractFrequentPattern(List <Transaction> allTrans) { // compute absolute support = relative support * # of transactions absMinSup = (int)System.Math.Ceiling(allTrans.Count * _minSup); result = new List <ItemSet>(); //We could have used two stacks instead of these lists!!! List <FPTree> FPTreeList = new List <FPTree>(); List <FPTree> FPTreeListNext = new List <FPTree>(); List <ItemSet> GivenListNow = new List <ItemSet>(); List <ItemSet> GivenListNext = new List <ItemSet>(); FPTree Next; ItemSet Given; ItemSet Beta; List <ItemSet> wholeTransToItemSet = new List <ItemSet>(); foreach (Transaction trans in allTrans) { wholeTransToItemSet.Add(trans.Itemset); } FPTree StartFPtree = new FPTree(); StartFPtree.SetMinSup(absMinSup); //Build the first tree on the whole transaction database list StartFPtree.BuildFirstTree(wholeTransToItemSet); //Add the first tree to the list of the fptree to process FPTreeList.Add(StartFPtree); //Here our given prefix is null GivenListNow.Add(new ItemSet()); //Looping on each fptree until there are ones to process while (FPTreeList.Count > 0) { for (int j = 0; j < FPTreeList.Count; j++) { Next = FPTreeList[j]; Given = GivenListNow[j]; if (!Next.isEmpty()) { // If the FPTree we are examining is composed of a single path // we use an optimization based on path node combination which // arrest current iteration if (Next.HasSinglePath) { GenerateCombPattern(Next, Given); } else { // Header table sorting Next.SortHeaderTable(); //Loop on each header table entry for (int i = 0; i < Next.GetHTSize(); i++) { //New beta ItemSet representing a frequent pattern Beta = new ItemSet(); //Concatenate with items present in the given ItemSet foreach (int item in Given.Items) { Beta.Add(item); } Beta.Add(Next.GetHTItem(i)); Beta.ItemsSupport = Next.GetHTFreq(i); // Add beta to frequent pattern result result.Add(Beta); // Here we generate the so called Conditional FPTree using a projection // of the original database called Conditional Pattern Base FPTreeListNext.Add(Next.CreateFPtree(i)); // Insert current beta in next given list GivenListNext.Add(Beta); } FPTreeList[j] = null; GivenListNow[j] = null; } } } FPTreeList.Clear(); GivenListNow.Clear(); for (int j = 0; j < GivenListNext.Count; j++) { FPTreeList.Add(FPTreeListNext[j]); GivenListNow.Add(GivenListNext[j]); GivenListNext[j] = null; FPTreeListNext[j] = null; } GivenListNext.Clear(); FPTreeListNext.Clear(); } return(result); }
/// <summary> /// Thread for training the decisition tree /// </summary> private void TrainingThread() { System.Console.WriteLine("Inside the training!!!!!!!!!!!!"); List <FlowFeature> trainingFeatures; // List<FlowFeature> trainingFeatures; //MySqlDao dao = null; try { //dao = new MySqlDao(); // set data table //Flow.SetLabelTable(dao.GetFlowLabels()); string traceFile = _openTrainingSetDlg.FileName; System.Console.WriteLine("the training file is:" + traceFile); if (File.Exists(traceFile) == false) { throw new FileNotFoundException("Trace file " + traceFile + " doesn't exist."); } NMParser parser = new NMParser(); IEnumerable <FlowFeature> allFeatures = GetFlowFeaturesFromTraceFile(parser, traceFile, -1); trainingFeatures = allFeatures.ToList(); List <Attribute> attributes = new List <Attribute>(); attributes.Add(new NumericalAttribute("PX")); attributes.Add(new NumericalAttribute("APL")); attributes.Add(new NumericalAttribute("PV")); attributes.Add(new NumericalAttribute("DPL")); attributes.Add(new NumericalAttribute("PPS")); attributes.Add(new IdSymbolicAttribute("Protocol", new List <string>() { "TCP", "UDP", "Mixed" })); attributes.Add(new NumericalAttribute("FPS")); attributes.Add(new NumericalAttribute("AB")); attributes.Add(new NumericalAttribute("TBT")); attributes.Add(new NumericalAttribute("BS")); attributes.Add(new NumericalAttribute("PS")); attributes.Add(new NumericalAttribute("NNP")); attributes.Add(new NumericalAttribute("NSP")); attributes.Add(new NumericalAttribute("PSP")); attributes.Add(new NumericalAttribute("Duration")); attributes.Add(new NumericalAttribute("AIT")); attributes.Add(new NumericalAttribute("IOPR")); attributes.Add(new NumericalAttribute("Reconnect")); attributes.Add(new IdSymbolicAttribute("Type", Flow2.GetFlowTypeNames())); // System.Diagnostics.Debug.WriteLine("TrainingThread1"); AttributeSet attrSet = new AttributeSet(attributes); ItemSet itemSet = new ItemSet(attrSet); Dictionary <int, int> maliciousFlowCounter = new Dictionary <int, int>(); int value; foreach (FlowFeature feature in trainingFeatures) { List <AttributeValue> attrVals = new List <AttributeValue>(); attrVals.Add(new KnownNumericalValue(feature.PX)); attrVals.Add(new KnownNumericalValue(feature.APL)); attrVals.Add(new KnownNumericalValue(feature.PV)); attrVals.Add(new KnownNumericalValue(feature.DPL)); attrVals.Add(new KnownNumericalValue(feature.PPS)); attrVals.Add(new KnownSymbolicValue((int)feature.Protocol)); attrVals.Add(new KnownNumericalValue(feature.FPS)); attrVals.Add(new KnownNumericalValue(feature.AB)); attrVals.Add(new KnownNumericalValue(feature.TBT)); attrVals.Add(new KnownNumericalValue(feature.BS)); attrVals.Add(new KnownNumericalValue(feature.PS)); attrVals.Add(new KnownNumericalValue(feature.NNP)); attrVals.Add(new KnownNumericalValue(feature.NSP)); attrVals.Add(new KnownNumericalValue(feature.PSP)); attrVals.Add(new KnownNumericalValue(feature.Duration)); attrVals.Add(new KnownNumericalValue(feature.AIT)); attrVals.Add(new KnownNumericalValue(feature.IOPR)); attrVals.Add(new KnownNumericalValue(feature.Reconnect)); attrVals.Add(new KnownSymbolicValue(feature.Type)); // System.Diagnostics.Debug.WriteLine("TrainingThread2"); // attrVals.Add(new ((DateTime)feature.DetectionTimeStamp)); Item it = new Item(attrVals.ToArray()); if (feature.Type > 0) // if the flow is not normal, count { if (!maliciousFlowCounter.TryGetValue(feature.Type, out value)) { maliciousFlowCounter.Add(feature.Type, 1); } else { maliciousFlowCounter[feature.Type]++; } } itemSet.Add(it); } foreach (int index in maliciousFlowCounter.Keys) { System.Diagnostics.Debug.WriteLine("Number of Malicious Flows for type: " + Flow2.GetFlowTypeName(index) + " is: " + maliciousFlowCounter[index].ToString()); } SymbolicAttribute goalAttribute = attrSet.FindByName("Type") as SymbolicAttribute; List <Attribute> testAttributes = new List <Attribute>(); testAttributes.Add(attrSet.FindByName("PX")); testAttributes.Add(attrSet.FindByName("APL")); testAttributes.Add(attrSet.FindByName("PV")); testAttributes.Add(attrSet.FindByName("DPL")); testAttributes.Add(attrSet.FindByName("PPS")); testAttributes.Add(attrSet.FindByName("Protocol")); testAttributes.Add(attrSet.FindByName("FPS")); // testAttributes.Add(attrSet.FindByName("Type")); testAttributes.Add(attrSet.FindByName("AB")); testAttributes.Add(attrSet.FindByName("TBT")); testAttributes.Add(attrSet.FindByName("BS")); testAttributes.Add(attrSet.FindByName("PS")); testAttributes.Add(attrSet.FindByName("NNP")); testAttributes.Add(attrSet.FindByName("NSP")); testAttributes.Add(attrSet.FindByName("PSP")); testAttributes.Add(attrSet.FindByName("Duration")); testAttributes.Add(attrSet.FindByName("AIT")); testAttributes.Add(attrSet.FindByName("IOPR")); testAttributes.Add(attrSet.FindByName("Reconnect")); // System.Diagnostics.Debug.WriteLine("TrainingThread3"); SimpleDecisionTreeBuilder builder = new SimpleDecisionTreeBuilder( /// create tree hear! new WeightedItemSet(itemSet), new AttributeSet(testAttributes), goalAttribute); builder.ScoreThreshold = 0.0001d; // 0.0001 * itemSet.Size(); System.Diagnostics.Debug.WriteLine("DT ScoreThreshold is " + builder.ScoreThreshold.ToString()); LearningDecisionTree dt = builder.Build(); TestDecisionTree tdt = new TestDecisionTree(dt); StoreDecisionTree(tdt); } catch (ThreadInterruptedException) { ; } catch (ThreadAbortException) { ; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } finally { menuTraining.Text = Properties.Resources.StartTrainingText; } }
private void SaveItemSet_Click(object sender, RoutedEventArgs e) { // This generates a list of all your equipped items, as they are // We'll use this list to make a comparison chart ItemSet newItemSet = new ItemSet(); foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { newItemSet.Add(Character[cs]); } DG_ItemSetName.ShowDialog(Character, newItemSet, SaveItemSet_Confirmation); }
public void SpeedTest2() { ItemSet seta = new ItemSet(); seta.SetUp(10); for (int i = 0; i < 100000; ++i) { MyList<MyPoint> set1 = new MyList<MyPoint>(); set1.Add(new MyPoint(1, 6)); set1.Add(new MyPoint(2, 6)); set1.Add(new MyPoint(5, 6)); set1.Add(new MyPoint(3, 6)); set1.Add(new MyPoint(2, 5)); set1.Add(new MyPoint(3, 5)); set1.Add(new MyPoint(5, 5)); set1.Add(new MyPoint(3, 4)); set1.Add(new MyPoint(3, 7)); set1.Add(new MyPoint(6, 4)); ItemSet workSet = seta.Clone(); ItemSet currentLine = new ItemSet(); currentLine.Add(0); currentLine.Add(1); LineParams par = new LineParams(set1[0], set1[1]); workSet.RemoveAt(0); workSet.RemoveAt(1); for (int k = 0; k < workSet.Count; ++k) { int id = workSet.GetItemIndex(k); if (par.IsCollinear(set1[id])) { currentLine.Add(id); workSet.RemoveAt(id); } } } }
public void TestPointSet() { ItemSet pSet = new ItemSet(); uint expected = 0; for (int i = 0; i < 16; i++) { expected += (uint)Math.Pow(2.0, i); pSet.Add(i); Assert.True(expected == pSet.GetIndices()); } pSet.RemoveAt(3); expected -= 8; Assert.AreEqual(15, pSet.CountBits(), "Array size 1"); Assert.True(expected == pSet.GetIndices()); MyList<MyPoint> set1 = new MyList<MyPoint>(); set1.Add(new MyPoint(0, 0)); set1.Add(new MyPoint(1, 1)); set1.Add(new MyPoint(2, 2)); set1.Add(new MyPoint(5, 0)); set1.Add(new MyPoint(6, 1)); set1.Add(new MyPoint(7, 2)); set1.Add(new MyPoint(8, 5)); pSet.Reset(); pSet.Add(0); pSet.Add(3); pSet.Add(4); pSet.Add(6); Assert.AreEqual(4, pSet.CountBits(), "Array size 2"); pSet.GetItem(set1, 0); pSet.GetItem(set1, 1); pSet.GetItem(set1, 2); pSet.GetItem(set1, 3); Assert.True(set1[0] == pSet.GetItem(set1, 0), "Check 0"); Assert.True(set1[3] == pSet.GetItem(set1, 1), "Check 1"); Assert.True(set1[4] == pSet.GetItem(set1, 2), "Check 2"); Assert.True(set1[6] == pSet.GetItem(set1, 3), "Check 3"); }
private ItemSet AprioriGenerate(ItemSet li, int k, double support) { ItemSet curList = null; ItemSet durList = null; ItemSet candi = null; ItemSet result = new ItemSet(); for (int i = 0; i < li.Count; i++) { for (int j = 0; j < li.Count; j++) { bool flag = true; curList = (ItemSet)li.arr[i]; durList = (ItemSet)li.arr[j]; for (int n = 2; n < k; n++) { if (((DataItem)curList.arr[n - 2]).Id == ((DataItem)durList.arr[n - 2]).Id) { flag = true; } else { flag = false; break; } } if (flag && ((DataItem)curList.arr[k - 1]).Id < ((DataItem)durList.arr[k - 1]).Id) { flag = true; } else { flag = false; } if (flag) { candi = new ItemSet(); for (int m = 0; m < k; m++) { candi.Add((DataItem)durList.arr[m]); } candi.Add((DataItem)curList.arr[k - 1]); if (HasInFrequentSubset(candi, li, k)) { candi.Clear(); } else { result.Add(candi); } } } } return(result); }
private ItemSet apriori(ItemSet data, double support) { ItemSet result = new ItemSet(); ItemSet li = new ItemSet(); ItemSet conList = new ItemSet(); ItemSet subConList = new ItemSet(); ItemSet subDataList = new ItemSet(); ItemSet CurList = null; ItemSet subList = null; int k = 2; li.Add(new ItemSet()); li.Add(this.FindOneColSet(data, support)); while (((ItemSet)li.arr[k - 1]).Count != 0) { Console.WriteLine(k - 1); conList = AprioriGenerate((ItemSet)li.arr[k - 1], k - 1, support); for (int i = 0; i < data.Count; i++) { subDataList = SubSet((ItemSet)data.arr[i], k); for (int j = 0; j < subDataList.Count; j++) { subList = (ItemSet)subDataList.arr[j]; for (int n = 0; n < conList.Count; n++) { ((ItemSet)subDataList.arr[j]).Sort(); ((ItemSet)conList.arr[n]).Sort(); CurList = (ItemSet)conList.arr[n]; if (subList.Equals(CurList)) { ((ItemSet)conList.arr[n]).ICount++; } } } } li.Add(new ItemSet()); for (int i = 0; i < conList.Count; i++) { ItemSet con = (ItemSet)conList.arr[i]; if (con.ICount >= support) { ((ItemSet)li.arr[k]).Add(con); } } k++; } //for (int j = 0; j < li.Count; j++) //{ // for (int h = 0; h < li.Count; h++) // { // if (((ItemSet)li.arr[j]).Equals((ItemSet)li.arr[h])) // { // li.arr.RemoveAt(j); // li.Count = li.arr.Count; // } // } //} for (int i = 0; i < li.Count; i++) { result.Add((ItemSet)li.arr[i]); } return(result); }
public void TestResultSet() { List<MyPoint> set1 = new List<MyPoint>(); set1.Add(new MyPoint(0, 0)); set1.Add(new MyPoint(1, 1)); set1.Add(new MyPoint(2, 2)); set1.Add(new MyPoint(5, 0)); set1.Add(new MyPoint(6, 1)); set1.Add(new MyPoint(7, 2)); ItemSet iSet1 = new ItemSet(); ItemSet iSet2 = new ItemSet(); iSet1.Add(0); iSet1.Add(2); iSet1.Add(4); iSet2.Add(1); iSet2.Add(3); iSet2.Add(5); Results2 r2 = new Results2(); r2.AddResult(iSet1.GetIndices()); Results2 r3 = r2.Clone(); r3.AddResult(iSet2.GetIndices()); Assert.AreEqual(2, r3.Count); Assert.AreEqual(1, r2.Count); ItemSet iSet3 = iSet1.Clone(); iSet3.Add(1); iSet3.Add(3); iSet3.Add(5); Assert.AreEqual(3, iSet1.Count); Assert.AreEqual(6, iSet3.Count); }
private void DiscoverBenchmarks() { var benchmarks = from t in ApplicationManager.Manager.GetTypes(typeof(IBenchmark)) select t; ItemSet<IBenchmark> values = new ItemSet<IBenchmark>(); foreach (var benchmark in benchmarks) { IBenchmark b = (IBenchmark)Activator.CreateInstance(benchmark); values.Add(b); } string paramName = "Benchmark"; if (!Parameters.ContainsKey(paramName)) { if (values.Count > 0) { Parameters.Add(new ConstrainedValueParameter<IBenchmark>(paramName, "The benchmark which should be executed.", values, values.First(a => a is IBenchmark))); } else { Parameters.Add(new ConstrainedValueParameter<IBenchmark>(paramName, "The benchmark which should be executed.", values)); } } }
/// <summary>Warning! Retuns NULL when it can't find the set</summary> public ItemSet GetItemSetByName(String name) { if (name == "Current") { ItemSet current = new ItemSet(); foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { current.Add(this[cs]); } current.Name = "Current"; return current; } if (itemSetList == null || itemSetList.Count <= 0) { return null; } if (ItemSetListContainsItemSetByName(name)) { foreach (ItemSet ISs in itemSetList) { if (ISs.Name.Equals(name)) { return ISs; } } } return null; }
private void UpdateGraphItemSets(string subgraph) { SetGraphControl(ComparisonGraph); CGL_Legend.LegendItems = Calculations.SubPointNameColors; ComparisonGraph.LegendItems = Calculations.SubPointNameColors; ComparisonGraph.Mode = ComparisonGraph.DisplayMode.Subpoints; List<ComparisonCalculationBase> setCalculations = new List<ComparisonCalculationBase>(); ItemSet newItemSetNaked = new ItemSet() { Name = "Naked", }; foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { newItemSetNaked.Add(null); } if (!Character.ItemSetListContainsItemSet(newItemSetNaked)) { setCalculations.Add(Calculations.GetItemSetCalculations(newItemSetNaked, Character)); } ItemSet newItemSetCurrent = new ItemSet() { Name = "Current", }; foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { newItemSetCurrent.Add(Character[cs]); } if (!Character.ItemSetListContainsItemSet(newItemSetCurrent)) { setCalculations.Add(Calculations.GetItemSetCalculations(newItemSetCurrent, Character)); } foreach (ItemSet IS in Character.GetItemSetList()) { if (IS == null) { continue; } setCalculations.Add(Calculations.GetItemSetCalculations(IS, Character)); } // Now Push the results to the screen ComparisonGraph.DisplayCalcs(_itemSetCalculations = setCalculations.ToArray()); }
private void results_Closed(object sender, EventArgs e) { OptimizerResults results = sender as OptimizerResults; if (results.DialogResult.GetValueOrDefault()) { if (results.WeWantToStoreIt) { ItemSet newItemSet = new ItemSet() { Name = string.Format("Optimized GearSet {0}", character.GetNumItemSetsFromOptimizer()+1) }; foreach (CharacterSlot cs in Character.EquippableCharacterSlots) { newItemSet.Add(results.BestCharacter[cs]); } character.AddToItemSetList(newItemSet); } else { character.IsLoading = true; character.SetItems(results.BestCharacter); character.ActiveBuffs = results.BestCharacter.ActiveBuffs; if (CK_Talents_Points.IsChecked.GetValueOrDefault()) { character.CurrentTalents = results.BestCharacter.CurrentTalents; MainPage.Instance.TalentPicker.RefreshSpec(); } character.IsLoading = false; character.OnCalculationsInvalidated(); } DialogResult = true; } else ControlsEnabled(true); }