public void TestMethodAlgorithms() { List <double> supports = new List <double>(new double[] { 0.001, 0.002, 0.003, 0.004, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2 }); string stringResult = ""; foreach (double support in supports) { var start = DateTime.Now; var transactions = new TransactionDatabase(@"\\small.txt"); var apriori = new Apriori(transactions, 0.2); apriori.Run(); var end = DateTime.Now; var result = end - start; stringResult += $"APRIORI Support:{support} Total Time (ms): {result.TotalMilliseconds}" + Environment.NewLine; } foreach (double support in supports) { var start = DateTime.Now; var transactions = new TransactionDatabase(@"\\small.txt"); var eclat = new Eclat(transactions, 0.2); eclat.Run(); var end = DateTime.Now; var result = end - start; stringResult += $"ECLAT Support:{support} Total Time (ms): {result.TotalMilliseconds}" + Environment.NewLine; System.IO.File.WriteAllText(@"PerformanceResultsAuto.csv", stringResult); } }
private void performanceTestToolStripMenuItem_Click(object sender, EventArgs e) { List <double> supports = new List <double>(new double[] { 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5 }); string stringResult = ""; string readfile = File.ReadAllText(comboBoxTestDataSet.Text); foreach (double support in supports) { var start = DateTime.Now; var transactions = new TransactionDatabase(comboBoxTestDataSet.Text); var apriori = new Apriori(transactions, support); apriori.Run(); var end = DateTime.Now; var result = end - start; var resultMem = GC.GetTotalMemory(true); stringResult += $"APRIORI Support:{support} Total Time (ms): {result.TotalMilliseconds} Memory Usage (bytes): {resultMem}" + Environment.NewLine; } foreach (double support in supports) { var start = DateTime.Now; var transactions = new TransactionDatabase(comboBoxTestDataSet.Text); var eclat = new Eclat(transactions, support); eclat.Run(); var end = DateTime.Now; var result = end - start; var resultMem = GC.GetTotalMemory(true); stringResult += $"ECLAT Support:{support} Total Time (ms): {result.TotalMilliseconds} Memory Usage (bytes): {resultMem}" + Environment.NewLine; System.IO.File.WriteAllText(@"PerformanceResults.txt", stringResult); } }
private void eCLATAlgorithmToolStripMenuItem_Click(object sender, EventArgs e) { var transactions = new TransactionDatabase(comboBoxTestDataSet.Text); var eclat = new Eclat(transactions, double.Parse(textBoxMinimumSupport.Text)); eclat.Run(); textBoxOutput.AppendText(eclat.ToString()); csvString = eclat.ToCSV(); }
public void Eclat_Calcuates_Transactions_Support_Right() { var transactions = new TransactionDatabase(); transactions.AddTransaction(new Transaction("A,B,C,D")); transactions.AddTransaction(new Transaction("A,B,C,A")); transactions.AddTransaction(new Transaction("A,B")); transactions.AddTransaction(new Transaction("A,B,C")); transactions.AddTransaction(new Transaction("D")); transactions.AddTransaction(new Transaction("E")); var eclat = new Eclat(transactions); eclat.Run(); Assert.IsTrue(eclat.IsTransactionSupported(new Transaction("A,B")), "Apriori algorithm did not works right as new Transaction(\"A,B\") is not included in Supported Transactions List"); Assert.IsFalse(eclat.IsTransactionSupported(new Transaction("D,E")), "Apriori algorithm did not works right as new Transaction(\"D,E\") is included in Supported Transactions List"); }
public void Eclat_Creation_Default_Constructor_Name() { var transactions = new TransactionDatabase(); transactions.AddTransaction(new Transaction("A,B,C,D")); transactions.AddTransaction(new Transaction("A,B,C,A")); transactions.AddTransaction(new Transaction("A,B")); transactions.AddTransaction(new Transaction("A,B,C")); transactions.AddTransaction(new Transaction("D")); transactions.AddTransaction(new Transaction("E")); var eclat = new Eclat(transactions, 0.2); eclat.Run(); Assert.AreEqual(8, eclat.TransactionCountWithSupport(), "Apriori Algorithm results wrong amount of transaction."); eclat = new Eclat(transactions); eclat.Run(); Assert.AreEqual(16, eclat.TransactionCountWithSupport(), "Apriori Algorithm results wrong amount of transaction."); Assert.IsTrue(eclat.IsTransactionSupported(new Transaction("A,B")), "Apriori algorithm did not works right as new Transaction(\"A,B\") is not included in Supported Transactions List"); }
public void Process(string input) { input = input.Trim(); if (input == "") { return; } else if (input.ToLower() == "listdatasets") { if (ApplicationConfiguration.DataFiles.Count == 0) { Output.AppendText("------------------" + Environment.NewLine); Output.AppendText("List of Currently Availabe Data Files Are:" + Environment.NewLine); } else { Output.AppendText("------------------" + Environment.NewLine); Output.AppendText("List of Currently Availabe Data Files Are:" + Environment.NewLine); for (var i = 1; i <= ApplicationConfiguration.DataFiles.Count; i++) { Output.AppendText(i + ". " + ApplicationConfiguration.DataFiles[i - 1] + Environment.NewLine); } } } else if (input.ToLower().Substring(0, 8) == "listfile") { var fileName = input.ToLower().Substring(9, input.Length - 10); var fullFileName = Application.StartupPath + "\\" + fileName; Output.AppendText("------------------" + Environment.NewLine); if (File.Exists(fullFileName)) { Output.AppendText("The contents of the file " + fileName + " are" + Environment.NewLine); Output.AppendText(File.ReadAllText(fullFileName) + Environment.NewLine); } else { Output.AppendText("File " + fileName + " cannot be found" + Environment.NewLine); } Output.AppendText("------------------" + Environment.NewLine); } else if (input.ToLower().Substring(0, 11) == "listdataset") { var datasetNumber = input.ToLower().Substring(12, input.Length - 13); int intDataSetNumber; bool isNumeric = int.TryParse(datasetNumber, out intDataSetNumber); Output.AppendText("------------------" + Environment.NewLine); if (isNumeric) { if (intDataSetNumber <= ApplicationConfiguration.DataFiles.Count) { var fullFileName = Application.StartupPath + "\\" + ApplicationConfiguration.DataFiles[intDataSetNumber - 1]; if (File.Exists(fullFileName)) { Output.AppendText("The contents of the dataset " + ApplicationConfiguration.DataFiles[intDataSetNumber - 1] + " are" + Environment.NewLine); Output.AppendText(File.ReadAllText(fullFileName) + Environment.NewLine); } else { Output.AppendText("The contents of the dataset cannot be found!" + Environment.NewLine); } } else { Output.AppendText("Dataset with " + intDataSetNumber + " cannot be found" + Environment.NewLine); } } else { Output.AppendText(datasetNumber + " is not numeric" + Environment.NewLine); Output.AppendText("------------------" + Environment.NewLine); } } else if (input.ToLower().Substring(0, 7) == "apriori") { var parameters = Regex.Match(input.ToLower(), @"\(([^)]*)\)").Groups[1].Value; var dataSet = parameters.Substring(0, parameters.LastIndexOf(",")); double support = double.Parse(parameters.Substring(parameters.LastIndexOf(",") + 1, parameters.Length - parameters.LastIndexOf(",") - 1)); int intDataSetNumber; bool isNumeric = int.TryParse(dataSet, out intDataSetNumber); string fileName; if (isNumeric) { fileName = ApplicationConfiguration.DataFiles[intDataSetNumber - 1]; } else { fileName = Regex.Match(parameters, @"\""([^)]*)\""").Groups[1].Value; } Output.AppendText("------------------" + Environment.NewLine); if (intDataSetNumber <= ApplicationConfiguration.DataFiles.Count) { var fullFileName = Application.StartupPath + "\\" + fileName; if (File.Exists(fullFileName)) { Output.AppendText("The result of the dataset " + fileName + " are" + Environment.NewLine); var transactions = new TransactionDatabase(fileName); var apriori = new Apriori(transactions, support); apriori.Run(); Output.AppendText(apriori.ToString()); } else { Output.AppendText("The contents of the dataset cannot be found!" + Environment.NewLine); } } else { Output.AppendText("Dataset with " + intDataSetNumber + " cannot be found" + Environment.NewLine); } } else if (input.ToLower().Substring(0, 5) == "eclat") { var parameters = Regex.Match(input.ToLower(), @"\(([^)]*)\)").Groups[1].Value; var dataSet = parameters.Substring(0, parameters.LastIndexOf(",")); double support = double.Parse(parameters.Substring(parameters.LastIndexOf(",") + 1, parameters.Length - parameters.LastIndexOf(",") - 1)); int intDataSetNumber; bool isNumeric = int.TryParse(dataSet, out intDataSetNumber); string fileName; if (isNumeric) { fileName = ApplicationConfiguration.DataFiles[intDataSetNumber - 1]; } else { fileName = Regex.Match(parameters, @"\""([^)]*)\""").Groups[1].Value; } Output.AppendText("------------------" + Environment.NewLine); if (intDataSetNumber <= ApplicationConfiguration.DataFiles.Count) { var fullFileName = Application.StartupPath + "\\" + fileName; if (File.Exists(fullFileName)) { Output.AppendText("The result of the dataset " + fileName + " are" + Environment.NewLine); var transactions = new TransactionDatabase(fileName); var eclat = new Eclat(transactions, support); eclat.Run(); Output.AppendText(eclat.ToString()); } else { Output.AppendText("The contents of the dataset cannot be found!" + Environment.NewLine); } } else { Output.AppendText("Dataset with " + intDataSetNumber + " cannot be found" + Environment.NewLine); } } else { Output.AppendText("------------------" + Environment.NewLine); Output.AppendText("Unknown Command" + Environment.NewLine); Output.AppendText("------------------" + Environment.NewLine); } }
}//DMForm //Methods ************************************************************* //Events ************************************************************** private void btnExecute_Click(object sender, EventArgs e) { if (cmbAlgorithm.SelectedItem == null) { MessageBox.Show("Please select an algorithm."); return; }//if no algorithm string algorithm = cmbAlgorithm.SelectedItem.ToString(); if (algorithm.Equals("Apriori")) { rtbResults.Text = ""; List <ItemSetDto> results = new List <ItemSetDto>(); DateTime timer = DateTime.Now; if (cmbSource.SelectedItem == null) { MessageBox.Show("Please select a data source."); return; }//if if (txtMinSupport.Text.Equals("")) { MessageBox.Show("Please enter a Minimum Support"); return; }//if double minSupport = Convert.ToDouble(txtMinSupport.Text); string datasource = cmbSource.SelectedItem.ToString(); DataSourceBLL dsBLL = new DataSourceBLL(); Apriori ap = new Apriori(); List <TransactionDto> transactions = dsBLL.process(datasource); if (transactions == null) { return; } results = ap.Process(transactions, null, minSupport); StringBuilder sb = new StringBuilder(); foreach (ItemSetDto isd in results) { sb.AppendLine(isd.toString()); } rtbResults.AppendText(sb.ToString() + "\nTime to Complete: " + (DateTime.Now - timer).ToString()); }//if "Apriori" else if (algorithm.Equals("FPGrowth")) { if (txtMinSupport.Text.Equals("")) { MessageBox.Show("Please enter a Minimum Support"); return; }//if double minSupport = Convert.ToDouble(txtMinSupport.Text); string datasource = cmbSource.SelectedItem.ToString(); DataSourceBLL dsBLL = new DataSourceBLL(); List <TransactionDto> dtos = dsBLL.process(datasource); if (dtos == null) { return; } rtbResults.Text = ""; DateTime timer = DateTime.Now; FPGrowth fpg = new FPGrowth(dtos, minSupport); List <FrequentPattern> fp = fpg.mine(); StringBuilder sb = new StringBuilder(); foreach (FrequentPattern f in fp) { sb.AppendLine(f.ToString()); } rtbResults.AppendText(sb.ToString() + "\nTime to Complete: " + (DateTime.Now - timer).ToString()); }//if "FPGrowth" else if (algorithm.Equals("Eclat")) { rtbResults.Text = ""; List <VerticalItemSetDto> results = new List <VerticalItemSetDto>(); DateTime timer = DateTime.Now; if (cmbSource.SelectedItem == null) { MessageBox.Show("Please select a data source."); return; }//if if (txtMinSupport.Text.Equals("")) { MessageBox.Show("Please enter a Minimum Support"); return; }//if double minSupport = Convert.ToDouble(txtMinSupport.Text); string datasource = cmbSource.SelectedItem.ToString(); DataSourceBLL dsBLL = new DataSourceBLL(); Eclat ec = new Eclat(); List <TransactionDto> transactions = dsBLL.process(datasource); if (transactions == null) { return; } results = ec.Process(transactions, null, minSupport); StringBuilder sb = new StringBuilder(); foreach (VerticalItemSetDto isd in results) { sb.AppendLine(isd.toString()); } rtbResults.AppendText(sb.ToString() + "\nTime to Complete: " + (DateTime.Now - timer).ToString()); } //if "Eclat" } //btnExecute_Click
public void EX_Rules(double support, double confidence, double max_confidence, double negsupport, double negconfidence, double negmax_confidence) { List <Transaction> data = new List <Transaction>(); List <Rule> eclat_rules = new List <Rule>(); List <Itemset> eclat_Litemsets = new List <Itemset>(); List <Rule> negeclat_rules = new List <Rule>(); List <Itemset> negeclat_Litemsets = new List <Itemset>(); data = list2mat(tr_messages, "train"); Eclat eclat = new Eclat(data, labels, support, confidence); eclat = eclat.Run(support, confidence); eclat_rules = eclat.eclat_rules; eclat_Litemsets = eclat.L_itemsets; //Pruning Rules for (int i = 0; i < eclat_Litemsets.Count; i++) { var item = eclat_Litemsets[i]; if (item.confidence >= max_confidence) { List <string> temp2 = item.items; for (int jj = i + 1; jj < eclat_Litemsets.Count; jj++) { List <string> temp1 = eclat_Litemsets[jj].items; bool flag = true; foreach (string s in temp2) { if (!temp1.Contains(s)) { flag = false; break; } } if (flag) { eclat_Litemsets.RemoveAt(jj); } } } } //Negative Rules int[] neglabels = new int[labels.Length]; for (int i = 0; i < labels.Length; i++) { if (labels[i] == 0) { neglabels[i] = 1; } } Eclat negeclat = new Eclat(data, neglabels, negsupport, negconfidence); negeclat = negeclat.Run(negsupport, negconfidence); negeclat_rules = negeclat.eclat_rules; negeclat_Litemsets = negeclat.L_itemsets; //Pruning Rules for (int i = 0; i < negeclat_Litemsets.Count; i++) { var item = negeclat_Litemsets[i]; if (item.confidence >= negmax_confidence) { List <string> temp2 = item.items; for (int jj = i + 1; jj < negeclat_Litemsets.Count; jj++) { List <string> temp1 = negeclat_Litemsets[jj].items; bool flag = true; foreach (string s in temp2) { if (!temp1.Contains(s)) { flag = false; break; } } if (flag) { negeclat_Litemsets.RemoveAt(jj); } } } } //write model System.IO.File.Delete("AR.model"); string[] row = new string[negeclat_Litemsets.Count + eclat_Litemsets.Count]; for (int i = 0; i < eclat_Litemsets.Count; i++) { var item = eclat_Litemsets[i]; row[i] = "Pos&" + "{" + string.Join(",", item.items) + "}&" + item.support.ToString() + "&" + item.confidence.ToString("0.0000"); } for (int i = 0; i < negeclat_Litemsets.Count; i++) { var item = negeclat_Litemsets[i]; row[eclat_Litemsets.Count + i] = "Neg&" + "{" + string.Join(",", item.items) + "}&" + item.support.ToString() + "&" + item.confidence.ToString("0.0000"); } System.IO.File.WriteAllLines("AR.model", row); eclatlitems = eclat_Litemsets; foreach (var rule in negeclat_Litemsets) { eclatlitems.Add(new Itemset(rule.items, rule.support, -rule.confidence)); } //return eclatlitems; docRule = calculate_docrule(data); //classification_train(docRule, labels, algoritm); }