private HashSet <Rule> GenerateRules(ItemsDictionary allFrequentItems) { var rulesList = new HashSet <Rule>(); foreach (var item in allFrequentItems) { var data = item.Name.Split(separator); if (data.Length > 1) { IEnumerable <string> subsetsList = GenerateSubsets(data); foreach (var subset in subsetsList) { var subsetData = subset.Split(separator); string[] remaining = GetRemaining(subsetData, data); Rule rule = new Rule(subset, ConvertStringArrayToString(remaining), 0); if (!rulesList.Contains(rule)) { rulesList.Add(rule); } } } } return(rulesList); }
public void GetItemParentsTest() { //Arrange string child = "a"; int index = 1; ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "e", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act Dictionary <string, double> actual = _target.GetItemParents(child, index, allFrequentItems); //Assert Assert.AreEqual(1, actual.Count); Assert.AreEqual(2, actual["ac"]); }
private double GetConfidence(string X, string XY, ItemsDictionary allFrequentItems) { var supportX = allFrequentItems[X].Support; var supportXY = allFrequentItems[XY].Support; return(supportXY / supportX); }
public void CheckIsClosed_ClosedItemTest() { //Arrange string child = "c"; Dictionary <string, double> parents = new Dictionary <string, double>(); parents.Add("ac", 2); parents.Add("bc", 2); parents.Add("ce", 2); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "c", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); //Act bool actual = _target.CheckIsClosed(child, parents, allFrequentItems); //Assert Assert.IsTrue(actual); }
public Products DispenseProduct(string slotLocation) { if (!ItemsDictionary.ContainsKey(slotLocation)) { throw new Exception("This item does not exist"); } Products selectedProduct = ItemsDictionary[slotLocation]; if (selectedProduct.Quantity == 0) { throw new Exception("Item is out of stock"); } else { if (Balance < selectedProduct.Price) { throw new Exception("Balance insufficient for selected item"); } else { Balance -= selectedProduct.Price; //TotalAmountDue += selectedProduct.Price; selectedProduct.Quantity--; Console.WriteLine(selectedProduct.Message); //TODO: Create Audit StreamWriter for Log.txt } } return(selectedProduct); //TODO: This needs more, what do we want to happen/be said when the product dispenses }
public void GenerateRulesTest() { //Arrange ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act HashSet <Rule> actual = _target.GenerateRules(allFrequentItems); //Assert Assert.AreEqual(7, actual.Count); }
private HashSet <Rule> GenerateRules(ItemsDictionary allFrequentItems) { var rulesList = new HashSet <Rule>(); foreach (var item in allFrequentItems) { if (item.Name.Length <= 1) { continue; } IEnumerable <string> subsetsList = GenerateSubsets(item.Name); foreach (var subset in subsetsList) { string remaining = GetRemaining(subset, item.Name); Rule rule = new Rule(subset, remaining, 0); if (!rulesList.Contains(rule)) { rulesList.Add(rule); } } } return(rulesList); }
public void GetStrongRulesTest() { //Arrange double minConfidence = .8; HashSet <Rule> rules = new HashSet <Rule>(); rules.Add(new Rule("a", "c", 0)); rules.Add(new Rule("b", "c", 0)); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "a", Support = 2 }); allFrequentItems.Add(new Item { Name = "b", Support = 3 }); allFrequentItems.Add(new Item { Name = "c", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); //Act IList <Rule> actual = _target.GetStrongRules(minConfidence, rules, allFrequentItems); //Assert Assert.AreEqual(1, actual.Count); }
private double GetLift(double XYConfidence, string[] Y, ItemsDictionary allFrequentItems) { var Ystring = string.Join("", Y.OrderBy(x => x)); var supportY = allFrequentItems.FirstOrDefault(x => string.Join("", x.Names.OrderBy(k => k)) == Ystring)?.Support ?? 999999999; return(XYConfidence / (supportY / this.transactionsCount)); }
Output IApriori.ProcessTransaction(float minSupport, float minConfidence, float minLift, IEnumerable <string> items, string[][] transactions, string[] itemsD = null) { this.minSupport = minSupport; this.minConfidence = minConfidence; this.transactionsCount = transactions.Length; this.minLift = minLift; IList <Item> frequentItems = GetL1FrequentItems(items, transactions); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.ConcatItems(frequentItems); var candidates = new Dictionary <string[], double>(); double transactionsCount = transactions.Count(); do { candidates = GenerateCandidates(frequentItems, transactions, itemsD); frequentItems = GetFrequentItems(candidates, transactionsCount); allFrequentItems.ConcatItems(frequentItems); } while (candidates.Count != 0); HashSet <Rule> rules = GenerateRules(allFrequentItems); IList <Rule> strongRules = GetStrongRules(minConfidence, rules, allFrequentItems); return(new Output { StrongRules = strongRules, FrequentItems = allFrequentItems }); }
Output IApriori.ProcessTransaction(double minSupport, double minConfidence, IEnumerable<string> items, string[] transactions) { IList<Item> frequentItems = GetL1FrequentItems(minSupport, items, transactions); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.ConcatItems(frequentItems); IDictionary<string, double> candidates = new Dictionary<string, double>(); double transactionsCount = transactions.Count(); do { candidates = GenerateCandidates(frequentItems, transactions); frequentItems = GetFrequentItems(candidates, minSupport, transactionsCount); allFrequentItems.ConcatItems(frequentItems); } while (candidates.Count != 0); HashSet<Rule> rules = GenerateRules(allFrequentItems); IList<Rule> strongRules = GetStrongRules(minConfidence, rules, allFrequentItems); Dictionary<string, Dictionary<string, double>> closedItemSets = GetClosedItemSets(allFrequentItems); IList<string> maximalItemSets = GetMaximalItemSets(closedItemSets); return new Output { StrongRules = strongRules, MaximalItemSets = maximalItemSets, ClosedItemSets = closedItemSets, FrequentItems = allFrequentItems }; }
Output IApriori.ProcessTransaction(double minSupport, double minConfidence, IEnumerable<string> items, string[][] transactions, string[] itemsD = null) { IList<Item> frequentItems = GetL1FrequentItems(minSupport, items, transactions); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.ConcatItems(frequentItems); var candidates = new Dictionary<string[], double>(); double transactionsCount = transactions.Count(); do { candidates = GenerateCandidates(frequentItems, transactions, itemsD); frequentItems = GetFrequentItems(candidates, minSupport, transactionsCount); allFrequentItems.ConcatItems(frequentItems); } while (candidates.Count != 0); HashSet<Rule> rules = GenerateRules(allFrequentItems); IList<Rule> strongRules = GetStrongRules(minConfidence, rules, allFrequentItems); //Dictionary<string, Dictionary<string, double>> closedItemSets = GetClosedItemSets(allFrequentItems); // IList<string> maximalItemSets = GetMaximalItemSets(closedItemSets); return new Output { StrongRules = strongRules, MaximalItemSets = null, ClosedItemSets = null, FrequentItems = allFrequentItems }; }
public Output ProcessTransaction(double minSupport, double minConfidence, IEnumerable <string> items, string[] transactions) { Console.WriteLine("Computing frequentItems"); var frequentItems = GetFirstListOfFrequentItems(minSupport, items, transactions); var allFrequentItems = new ItemsDictionary(); allFrequentItems.ConcatItems(frequentItems); IDictionary <string, double> candidates; double transactionsCount = transactions.Length; do { candidates = GenerateCandidates(frequentItems, transactions); Console.WriteLine(candidates.Count + " candidates."); frequentItems = GetFrequentItems(candidates, minSupport, transactionsCount); allFrequentItems.ConcatItems(frequentItems); }while (candidates.Count != 0); Console.WriteLine("Computing output:..."); return(ComputeOutput(minConfidence, allFrequentItems)); }
public void AddItems(ItemsDictionary items) { foreach (var item in items) { AddItems(item.Key, item.Value); } }
public RequestBodyWithDeviceList(IEnumerable <DeviceRequest> devices) { this.Devices = new ItemsDictionary <DeviceRequest>(); foreach (var d in devices) { this.Devices.Add(d.Id, d); } }
public void GenerateItemList(Inventory _inventory, Inventory _buyersInventory, ItemsDictionary tradeItemsWithPrices) { inventory = _inventory; buyerInventory = _buyersInventory; itemsWithPricesFilter = tradeItemsWithPrices; Refresh(); }
private double GetConfidence(string[] X, string[] XY, ItemsDictionary allFrequentItems) { var XYstring= string.Join("", XY.OrderBy(x => x)); var Xstring = string.Join("", X.OrderBy(x => x)); var supportX = allFrequentItems.FirstOrDefault(x => string.Join("", x.Names.OrderBy(k => k)) == Xstring).Support; var supportXY = allFrequentItems.FirstOrDefault(x => string.Join("", x.Names.OrderBy(k => k)) == XYstring).Support; return supportXY / supportX; }
public void Setup(uint _maxCapacity) { maxCapacity = _maxCapacity; if (itemsDictionary == null) { itemsDictionary = new ItemsDictionary(); } }
public void Setup(uint _maxCapacity, ItemsDictionary startingItems) { Setup(_maxCapacity); foreach (KeyValuePair <ItemName, uint> item in startingItems) { AddItems(item.Key, item.Value); } }
public void GetEnumerator_ShouldResolveWithoutNullReferenceException() { // Arrange var dict = new ItemsDictionary(); // Act and Assert IEnumerable en = (IEnumerable)dict; Assert.NotNull(en.GetEnumerator()); }
public void CopyTo_ShouldCopyItemsWithoutNullReferenceException() { // Arrange var dict = new ItemsDictionary(); var pairs = new KeyValuePair <object, object>[] { new KeyValuePair <object, object>("first", "value") }; // Act and Assert ICollection <KeyValuePair <object, object> > cl = (ICollection <KeyValuePair <object, object> >)dict; cl.CopyTo(pairs, 0); }
public RequestBodyWithDeviceList(IEnumerable <string> deviceIds) { this.Devices = new ItemsDictionary <DeviceRequest>(); foreach (var id in deviceIds) { if (id != null) { this.Devices.Add(id, new DeviceRequest()); } } }
public TValue GetValue(TKey key) { int idx; if (ItemsDictionary.TryGetValue(key, out idx)) { return(Items[idx]); } UnityEngine.Debug.LogError($"Can't find key string {key.ToString()}"); return(null); }
public bool TryGetValue(TKey key, out TValue value) { int idx; if (ItemsDictionary.TryGetValue(key, out idx)) { value = Items[idx]; return(true); } value = null; return(false); }
private bool CheckIsClosed(string child, Dictionary<string, double> parents, ItemsDictionary allFrequentItems) { foreach (string parent in parents.Keys) { if (allFrequentItems[child].Support == allFrequentItems[parent].Support) { return false; } } return true; }
private IList<Rule> GetStrongRules(double minConfidence, HashSet<Rule> rules, ItemsDictionary allFrequentItems) { var strongRules = new List<Rule>(); foreach (Rule rule in rules) { var xy = rule.X.Concat(rule.Y).ToArray(); AddStrongRule(rule, xy, strongRules, minConfidence, allFrequentItems); } //strongRules.Sort(); return strongRules; }
protected ItemsDictionary Load() { // ... initialize data in the test database ... Console.WriteLine("INFO: JsonSeededFacetContextFixture"); var reader = new JsonReaderService(new IgnoreJsonAttributesResolver()); var items = new ItemsDictionary(); foreach (var type in Types) { var entities = reader.Deserialize(type, Folder).ToArray(); items.Add(type, entities); } return(items); }
private static void WriteFrequent(ItemsDictionary frequentItems) { var orderByDescending = frequentItems.OrderByDescending(x => x.Support); using (var file = new StreamWriter(@"D:\\Disertatie\\Git\\AprioriResults\\frequentItems.txt")) { foreach (var rule in orderByDescending) { var line = rule.Name + " " + rule.Support; file.Write(line); file.Write(Environment.NewLine); } } }
private Output ComputeOutput(double minConfidence, ItemsDictionary allFrequentItems) { var rules = GenerateRules(allFrequentItems); var strongRules = GetStrongRules(minConfidence, rules, allFrequentItems); var closedItemSets = GetClosedItemSets(allFrequentItems); var maximalItemSets = GetMaximalItemSets(closedItemSets); return(new Output { StrongRules = strongRules, MaximalItemSets = maximalItemSets, ClosedItemSets = closedItemSets, FrequentItems = allFrequentItems }); }
public void CheckIsClosed_OpenItemTest() { //Arrange string child = "a"; Dictionary<string, double> parents = new Dictionary<string, double>(); parents.Add("ac", 2); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "a", Support = 2 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); //Act bool actual = _target.CheckIsClosed(child, parents, allFrequentItems); //Assert Assert.IsFalse(actual); }
void Start() { IsConsumingFood = true; gameController = GameController.Instance; sails = GetComponentInChildren <Sails> (); rudder = GetComponentInChildren <Rudder> (); ItemsDictionary dict = new ItemsDictionary(); for (int i = 0; i < StartingItems.Length; i++) { dict.Add(StartingItems [i].name, StartingItems [i].quantity); } SetupInventory(1000, dict); }
private Dictionary <string, Dictionary <string, double> > GetClosedItemSets(ItemsDictionary allFrequentItems) { var closedItemSets = new Dictionary <string, Dictionary <string, double> >(); int i = 0; foreach (var item in allFrequentItems) { Dictionary <string, double> parents = GetItemParents(item.Name, ++i, allFrequentItems); if (CheckIsClosed(item.Name, parents, allFrequentItems)) { closedItemSets.Add(item.Name, parents); } } return(closedItemSets); }
private void AddStrongRule(Rule rule, string XY, List<Rule> strongRules, double minConfidence, ItemsDictionary allFrequentItems) { double confidence = GetConfidence(rule.X, XY, allFrequentItems); if (confidence >= minConfidence) { Rule newRule = new Rule(rule.X, rule.Y, confidence); strongRules.Add(newRule); } confidence = GetConfidence(rule.Y, XY, allFrequentItems); if (confidence >= minConfidence) { Rule newRule = new Rule(rule.Y, rule.X, confidence); strongRules.Add(newRule); } }
public void GetClosedItemSetsTest() { //Arrange ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "a", Support = 2 }); allFrequentItems.Add(new Item { Name = "b", Support = 3 }); allFrequentItems.Add(new Item { Name = "c", Support = 3 }); allFrequentItems.Add(new Item { Name = "e", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act Dictionary <string, Dictionary <string, double> > actual = _target.GetClosedItemSets(allFrequentItems); //Assert Assert.AreEqual(4, actual.Count, "ClosedItemSets calculation is wrong"); Assert.IsTrue(actual.ContainsKey("c")); Assert.IsTrue(actual.ContainsKey("be")); Assert.IsTrue(actual.ContainsKey("ac")); Assert.IsTrue(actual.ContainsKey("bce")); }
private Dictionary<string, Dictionary<string, double>> GetClosedItemSets(ItemsDictionary allFrequentItems) { var closedItemSets = new Dictionary<string, Dictionary<string, double>>(); int i = 0; foreach (var item in allFrequentItems) { Dictionary<string, double> parents = GetItemParents(item.Name, ++i, allFrequentItems); if (CheckIsClosed(item.Name, parents, allFrequentItems)) { closedItemSets.Add(item.Name, parents); } } return closedItemSets; }
public void GetItemParentsTest() { //Arrange string child = "a"; int index = 1; ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "e", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act Dictionary<string, double> actual = _target.GetItemParents(child, index, allFrequentItems); //Assert Assert.AreEqual(1, actual.Count); Assert.AreEqual(2, actual["ac"]); }
public void GetStrongRulesTest() { //Arrange double minConfidence = .8; HashSet<Rule> rules = new HashSet<Rule>(); rules.Add(new Rule("a", "c", 0)); rules.Add(new Rule("b", "c", 0)); ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "a", Support = 2 }); allFrequentItems.Add(new Item { Name = "b", Support = 3 }); allFrequentItems.Add(new Item { Name = "c", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); //Act IList<Rule> actual = _target.GetStrongRules(minConfidence, rules, allFrequentItems); //Assert Assert.AreEqual(1, actual.Count); }
public void GenerateRulesTest() { //Arrange ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act HashSet<Rule> actual = _target.GenerateRules(allFrequentItems); //Assert Assert.AreEqual(7, actual.Count); }
public void GetClosedItemSetsTest() { //Arrange ItemsDictionary allFrequentItems = new ItemsDictionary(); allFrequentItems.Add(new Item { Name = "a", Support = 2 }); allFrequentItems.Add(new Item { Name = "b", Support = 3 }); allFrequentItems.Add(new Item { Name = "c", Support = 3 }); allFrequentItems.Add(new Item { Name = "e", Support = 3 }); allFrequentItems.Add(new Item { Name = "ac", Support = 2 }); allFrequentItems.Add(new Item { Name = "bc", Support = 2 }); allFrequentItems.Add(new Item { Name = "be", Support = 3 }); allFrequentItems.Add(new Item { Name = "ce", Support = 2 }); allFrequentItems.Add(new Item { Name = "bce", Support = 2 }); //Act Dictionary<string, Dictionary<string, double>> actual = _target.GetClosedItemSets(allFrequentItems); //Assert Assert.AreEqual(4, actual.Count, "ClosedItemSets calculation is wrong"); Assert.IsTrue(actual.ContainsKey("c")); Assert.IsTrue(actual.ContainsKey("be")); Assert.IsTrue(actual.ContainsKey("ac")); Assert.IsTrue(actual.ContainsKey("bce")); }
public ItemsFeature() { Items = new ItemsDictionary(); }
private IList<Rule> GetStrongRules(double minConfidence, HashSet<Rule> rules, ItemsDictionary allFrequentItems) { var strongRules = new List<Rule>(); foreach (Rule rule in rules) { string xy = _sorter.Sort(rule.X + rule.Y); AddStrongRule(rule, xy, strongRules, minConfidence, allFrequentItems); } strongRules.Sort(); return strongRules; }
private HashSet<Rule> GenerateRules(ItemsDictionary allFrequentItems) { var rulesList = new HashSet<Rule>(); foreach (var item in allFrequentItems) { if (item.Name.Length > 1) { IEnumerable<string> subsetsList = GenerateSubsets(item.Name); foreach (var subset in subsetsList) { string remaining = GetRemaining(subset, item.Name); Rule rule = new Rule(subset, remaining, 0); if (!rulesList.Contains(rule)) { rulesList.Add(rule); } } } } return rulesList; }
private Dictionary<string, double> GetItemParents(string child, int index, ItemsDictionary allFrequentItems) { var parents = new Dictionary<string, double>(); for (int j = index; j < allFrequentItems.Count; j++) { string parent = allFrequentItems[j].Name; if (parent.Length == child.Length + 1) { if (CheckIsSubset(child, parent)) { parents.Add(parent, allFrequentItems[parent].Support); } } } return parents; }
private double GetConfidence(string X, string XY, ItemsDictionary allFrequentItems) { double supportX = allFrequentItems[X].Support; double supportXY = allFrequentItems[XY].Support; return supportXY / supportX; }