public void TestClusterization() { const int W = 16; var img = ImageHelper.LoadImageAsInt(TestResources._1); Normalizer.Normalize(100, 500, img); var info = RidgeFrequencyGenerator.GenerateBlocksInfo(img); var centers = new ClustersGenerator.ClusterPoint[6]; img = ImageHelper.LoadImageAsInt(TestResources._1); Normalizer.Normalize(100, 500, img); info.AddRange(RidgeFrequencyGenerator.GenerateBlocksInfo(img)); img = ImageHelper.LoadImageAsInt(TestResources._2); Normalizer.Normalize(100, 500, img); info.AddRange(RidgeFrequencyGenerator.GenerateBlocksInfo(img)); img = ImageHelper.LoadImageAsInt(TestResources._3); Normalizer.Normalize(100, 500, img); info.AddRange(RidgeFrequencyGenerator.GenerateBlocksInfo(img)); img = ImageHelper.LoadImageAsInt(TestResources._4); Normalizer.Normalize(100, 500, img); info.AddRange(RidgeFrequencyGenerator.GenerateBlocksInfo(img)); img = ImageHelper.LoadImageAsInt(TestResources._5); Normalizer.Normalize(100, 500, img); var middle = new ClustersGenerator.ClusterPoint(0, 0, 0); foreach (var bl in info) { middle.Amplitude += bl.Amplitude; middle.Frequency += bl.Frequency; middle.Variance += bl.Variance; } middle.Amplitude /= info.Count; middle.Frequency /= info.Count; middle.Variance /= info.Count; Random rand = new Random(); for (int i = 0; i < 6; i++) { centers[i] = info[rand.Next(0, info.Count)]; } var centroids = ClustersGenerator.Clusterization(info, centers); // Writing result to file var path = ClustersGenerator.ClusterPath; using (StreamWriter file = new StreamWriter(path)) { for (int i = 0; i < centers.Length; i++) { file.WriteLine(i); file.WriteLine(centroids[i].Amplitude); file.WriteLine(centroids[i].Frequency); file.WriteLine(centroids[i].Variance); file.WriteLine(); } } Process.Start(path); img = ImageHelper.LoadImageAsInt(TestResources._1); ShowClusters(img, centroids, W); img = ImageHelper.LoadImageAsInt(TestResources._2); ShowClusters(img, centroids, W); img = ImageHelper.LoadImageAsInt(TestResources._3); ShowClusters(img, centroids, W); img = ImageHelper.LoadImageAsInt(TestResources._4); ShowClusters(img, centroids, W); img = ImageHelper.LoadImageAsInt(TestResources._5); ShowClusters(img, centroids, W); }
static void Main(string[] args) { //Console.WriteLine(); //Console.ReadLine(); try { Console.WriteLine("Ingrese minSupport :"); double minSupport = 0.005;//Convert.ToDouble(Console.ReadLine()) / 100; Console.WriteLine("Ingrese minConfidence :"); double minConfidence = Convert.ToDouble(Console.ReadLine()) / 100; Data data = new Data(false); FIGeneration fIGeneration = new FIGeneration(); fIGeneration.minSupport = minSupport; RuleGenerator ruleGenerator = new RuleGenerator(); ruleGenerator.minConfidence = minConfidence; ClustersGenerator clustersGenerator = new ClustersGenerator(); clustersGenerator.minPertencia = 0.60; data.LoadTransactions(); data.LoadClientes(); Console.WriteLine("--> " + data.transactions.Count); data.PodarTransacciones(0.003); Console.WriteLine("--> " + data.transactions.Count); data.PodarClientes(); Console.WriteLine("Clientes -> " + data.clientes.Count); data.PodarArticulos(); Console.WriteLine("Items Podados.- " + data.items.Count); data.PodarItemsPorSupport(minSupport); fIGeneration.AprioriFrequentItemGeneration(3, data); List <ItemSet> fi = fIGeneration.candidates.Where(x => x.items.Count > 1).ToList(); List <ItemSet> fiTotales = fIGeneration.candidates.ToList(); Console.WriteLine("Itemsets totales: " + fi.Count); Console.WriteLine("---------------------------------------- \n Frequents ItemSe Generados... \n Creando Reglas de asociacion ..."); //Generando Reglas ruleGenerator.GenerarReglas(fi, fIGeneration); Console.WriteLine(ruleGenerator.associationRules.Count + "++++++++"); foreach (Rule rule in ruleGenerator.associationRules) { Console.WriteLine(rule.antecedente.ToStringItems() + " ->" + rule.consecuente.ToStringItems() + " " + rule.confidence); } //Generando CLusters clustersGenerator.GenerarClusters(data.transactions, data.clientes, fi); /* * Analyzer analyzer = new Analyzer(); * analyzer.minPertenencia = 0.75; * analyzer.minPertenencia = 0.75; * analyzer.minSupport = 0.01; * analyzer.LoadData(); * analyzer.PodarDatos(0.1/100); * //analyzer.data.PodarItemsPorSupport(0.1); * * analyzer.GenerarFrequentItemSets(2); * Console.WriteLine(analyzer.fIGeneration.candidates.Count);*/ foreach (ItemSet itemset in fIGeneration.candidates) { String cods = ""; itemset.items.ToList().ForEach(x => cods += x.Value.cod + " "); Console.WriteLine("Conjunto frecuente -> Support: " + itemset.support + " Conjunto: " + cods); } // List<ItemSet> fi = fIGeneration.candidates.Where(x => x.items.Count > 1).ToList(); // clustersGenerator.GenerarClusters(data.transactions, data.clientes, fi); foreach (Cluster c in clustersGenerator.clusters) { Console.WriteLine("Cluster: " + c.agrupador.ToStringItems()); foreach (Elemento e in c.elementos) { Console.WriteLine("Elemento: " + e.id + " pertenece un " + e.pertenencia + " al cluster"); } } Console.WriteLine(" Clusters final " + clustersGenerator.clusters.Count); Console.WriteLine("Terminó!"); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Error main: " + e.Message + "\n" + e.StackTrace); Console.ReadLine(); } }