private Dendrogram CreateClassesDendrogram(int class_number = 1, int class_count = 3) { ArrayList ClassList = CreateClassList(class_number); if (ClassList.Count == 0) { return(CreateClassesDendrogram(class_number + 1)); } Dendrogram local_dendrogram = new Dendrogram(); local_dendrogram.HasValue = false; if (ClassList.Count == 1) { local_dendrogram.left.HasValue = true; local_dendrogram.left.value = (int)ClassList[0]; } else { local_dendrogram.left = CreateClassDendrogram(ClassList); } if (class_count - class_number + 1 == 2) { ClassList = CreateClassList(class_number + 1); local_dendrogram.right = CreateClassDendrogram(ClassList); } else { local_dendrogram.right = CreateClassesDendrogram(class_number + 1); } return(local_dendrogram); }
private ArrayList CreateClusterElements(Dendrogram dendrogram, int cluster_number, int clusters_order) { ArrayList ClassElements = CreateClassElements(cluster_number, clusters_order); double compliance_degree = ComplianceDegree(dendrogram, ClassElements); if (dendrogram.HasValue) { return(CreateDendrogramElements(dendrogram)); } double left_compliance_degree = ComplianceDegree(dendrogram.left, ClassElements); double right_compliance_degree = ComplianceDegree(dendrogram.right, ClassElements); if (compliance_degree > left_compliance_degree) { if (compliance_degree > right_compliance_degree) { return(CreateDendrogramElements(dendrogram)); } else { return(CreateClusterElements(dendrogram.right, cluster_number, clusters_order)); } } else { if (left_compliance_degree > right_compliance_degree) { return(CreateClusterElements(dendrogram.left, cluster_number, clusters_order)); } else { return(CreateClusterElements(dendrogram.right, cluster_number, clusters_order)); } } }
public DendrogramForm(Dendrogram dendrogram) { InitializeComponent(); this.dendrogram = dendrogram; bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); gr = Graphics.FromImage(bitmap); }
private void CreateClustersList(Dendrogram local_dendrogram, ref ArrayList ClustersList) { ClustersList.Add(ElementsList(local_dendrogram)); if (!local_dendrogram.HasValue) { CreateClustersList(local_dendrogram.left, ref ClustersList); CreateClustersList(local_dendrogram.right, ref ClustersList); } }
private void ClusterButton_Click(object sender, EventArgs e) { isHierarchicalClustering = false; TestClusteringForm form = new TestClusteringForm(points, ClassInfo, LowerBorders, UpperBorders); form.ShowDialog(); if (!form.isClustered) { return; } if (form.isHierarchicalClustering) { dendrogram = form.getDendrogram(); isHierarchicalClustering = true; } else if (form.isFuzzyClustering) { ClusterInfo = new ArrayList(); ArrayList MembershipMatrix = form.getMemebershipMatrix(); double eps = 0.1; for (int i = 0; i < points.Count; i++) { double max = 0; for (int j = 0; j < ((ArrayList)MembershipMatrix[i]).Count; j++) { if ((double)((ArrayList)MembershipMatrix[i])[j] > max) { max = (double)((ArrayList)MembershipMatrix[i])[j]; } } ArrayList row = new ArrayList(); for (int j = 0; j < ((ArrayList)MembershipMatrix[i]).Count; j++) { double membership = (double)((ArrayList)MembershipMatrix[i])[j]; if (max - membership < eps) { row.Add(j + 1); } } ClusterInfo.Add(row); } } else { ClusterInfo = new ArrayList(); for (int i = 0; i < points.Count; i++) { ArrayList row = new ArrayList(); row.Add(((Point)points[i]).cluster_numbers[0]); ClusterInfo.Add(row); } points = form.getPoints(); } }
private void DrawDendrogram(Dendrogram dendrogram, int left_x, int y, int width, Pen pen, SolidBrush brush) { if (dendrogram.HasValue) { gr.DrawString(dendrogram.value.ToString(), new Font("Arial", 8), brush, left_x + width / 2 - 5, y); return; } gr.DrawLine(pen, left_x, y, left_x + width, y); gr.DrawLine(pen, left_x, y, left_x, y + 50); gr.DrawLine(pen, left_x + width, y, left_x + width, y + 50); DrawDendrogram(dendrogram.left, left_x - width / 4, y + 50, width / 2, pen, brush); DrawDendrogram(dendrogram.right, left_x + width - width / 4, y + 50, width / 2, pen, brush); }
private double ComplianceDegree(Dendrogram dendrogram, ArrayList ClassElements) { ArrayList DendrogramElements = CreateDendrogramElements(dendrogram); int coincidences_count = 0; for (int i = 0; i < ClassElements.Count; i++) { for (int j = 0; j < DendrogramElements.Count; j++) { if ((int)ClassElements[i] == (int)DendrogramElements[j]) { coincidences_count++; break; } } } return(((double)Math.Pow(coincidences_count, 2)) / (DendrogramElements.Count * ClassElements.Count)); }
private void CreateRandomDendrogram() { ArrayList cur_clusters_list = new ArrayList(); for (int i = 0; i < points.Count; i++) { ArrayList row = new ArrayList(); row.Add(i); cur_clusters_list.Add(row); } ArrayList dendrogram_parts_list = new ArrayList(); while (cur_clusters_list.Count != 1) { ConsolidateClusters(ref cur_clusters_list, ref dendrogram_parts_list); } dendrogram = (Dendrogram)dendrogram_parts_list[0]; }
private ArrayList CreateDendrogramElements(Dendrogram dendrogram) { ArrayList result = new ArrayList(); if (dendrogram.HasValue) { result.Add(dendrogram.value); return(result); } ArrayList left_elements = CreateDendrogramElements(dendrogram.left); ArrayList right_elements = CreateDendrogramElements(dendrogram.right); result = left_elements; for (int i = 0; i < right_elements.Count; i++) { result.Add(right_elements[i]); } return(result); }
private ArrayList ElementsList(Dendrogram local_dendrogram) { ArrayList result; if (local_dendrogram.HasValue) { result = new ArrayList(); result.Add(local_dendrogram.value); return(result); } result = ElementsList(local_dendrogram.left); ArrayList right = ElementsList(local_dendrogram.right); for (int i = 0; i < right.Count; i++) { result.Add((int)right[i]); } return(result); }
private Dendrogram CreateClassDendrogram(ArrayList ClassList, int element_number = 0) { Dendrogram local_dendrogram = new Dendrogram(); local_dendrogram.HasValue = false; local_dendrogram.left = new Dendrogram(); local_dendrogram.left.HasValue = true; local_dendrogram.left.value = (int)ClassList[element_number]; if (ClassList.Count - element_number == 2) { local_dendrogram.right = new Dendrogram(); local_dendrogram.right.HasValue = true; local_dendrogram.right.value = (int)ClassList[element_number + 1]; } else { local_dendrogram.right = CreateClassDendrogram(ClassList, element_number + 1); } return(local_dendrogram); }
private void Run_clustering_buttun_Click(object sender, EventArgs e) { if (k_means_rb.Checked) { K_Means algorithm = new K_Means(points, LowerBorders, UpperBorders); points = algorithm.Cluster(); } else if (DBSCAN_rb.Checked) { DBSCAN algorithm; if (isForExperiment) { algorithm = new DBSCAN(points, 1, 3); } else { algorithm = new DBSCAN(points); } points = algorithm.Cluster(); } else if (neighbor_method_rb.Checked) { isHierarchicalClustering = true; ClosestNeighborMethod algorithm = new ClosestNeighborMethod(points); dendrogram = algorithm.Cluster(); } else if (c_means_rb.Checked) { isFuzzyClustering = true; C_Means algorithm = new C_Means(points); MembershipMatrix = algorithm.Cluster(); } else if (EM_algorithm_rb.Checked) { EM_Clustering algorithm = new EM_Clustering(points); points = algorithm.Cluster(); } isClustered = true; this.Close(); }
private void clustering_button_Click(object sender, EventArgs e) { ArrayList LowerBorders = new ArrayList(); LowerBorders.Add(0.0); LowerBorders.Add(0.0); ArrayList UpperBorders = new ArrayList(); UpperBorders.Add((double)pictureBox.Width); UpperBorders.Add((double)pictureBox.Height); ClusteringForm form = new ClusteringForm(points, LowerBorders, UpperBorders); form.ShowDialog(); if (form.isClustered) { if (form.isHierarchicalClustering) { isHierarchicalClustering = true; isFuzzyClustering = false; dendrogram = form.getDendrogram(); DendrogramForm dendrogram_form = new DendrogramForm(dendrogram); dendrogram_form.Show(); } else if (form.isFuzzyClustering) { isHierarchicalClustering = false; isFuzzyClustering = true; MembershipMatrix = form.getMemebershipMatrix(); ColorizeFuzzyClusters(); } else { isHierarchicalClustering = false; isFuzzyClustering = false; points = form.getPoints(); ColorizeClusters(); } } }
public HierarchicalAdjustedMutualInformation(Dendrogram ClusterInfo, ArrayList ClassInfo) { this.ClusterInfo = ClusterInfo; this.ClassInfo = ClassInfo; }
public Hierarchical_F1_meassure(Dendrogram ClusterInfo, ArrayList ClassInfo) { this.ClusterInfo = ClusterInfo; this.ClassInfo = ClassInfo; }
private void ChangeDendrogramParts(ref ArrayList dendrogram_parts_list, ArrayList clusters_list, int min_i, int min_j) { Dendrogram root = new Dendrogram(); root.HasValue = false; if (((ArrayList)clusters_list[min_i]).Count == 1) { Dendrogram left = new Dendrogram(); left.left = new Dendrogram(); left.left.HasValue = false; left.right = new Dendrogram(); left.right.HasValue = false; left.HasValue = true; left.value = (int)((ArrayList)clusters_list[min_i])[0]; root.left = left; } else { Dendrogram cur_dendrogram = (Dendrogram)dendrogram_parts_list[0]; int cur_dendrogram_index = 0; for (int i = 0; i < dendrogram_parts_list.Count; i++) { cur_dendrogram = (Dendrogram)dendrogram_parts_list[i]; Dendrogram cur_left = cur_dendrogram; while (!cur_left.HasValue) { cur_left = cur_left.left; } bool isLeftDendrogramFound = false; for (int j = 0; j < ((ArrayList)clusters_list[min_i]).Count; j++) { if ((int)((ArrayList)clusters_list[min_i])[j] == cur_left.value) { isLeftDendrogramFound = true; break; } } if (isLeftDendrogramFound) { cur_dendrogram_index = i; break; } } root.left = cur_dendrogram; dendrogram_parts_list.RemoveAt(cur_dendrogram_index); } if (((ArrayList)clusters_list[min_j]).Count == 1) { Dendrogram right = new Dendrogram(); right.left = new Dendrogram(); right.left.HasValue = false; right.right = new Dendrogram(); right.right.HasValue = false; right.HasValue = true; right.value = (int)((ArrayList)clusters_list[min_j])[0]; root.right = right; } else { Dendrogram cur_dendrogram = (Dendrogram)dendrogram_parts_list[0]; int cur_dendrogram_index = 0; for (int i = 0; i < dendrogram_parts_list.Count; i++) { cur_dendrogram = (Dendrogram)dendrogram_parts_list[i]; Dendrogram cur_left = cur_dendrogram; while (!cur_left.HasValue) { cur_left = cur_left.left; } bool isRightDendrogramFound = false; for (int j = 0; j < ((ArrayList)clusters_list[min_j]).Count; j++) { if ((int)((ArrayList)clusters_list[min_j])[j] == cur_left.value) { isRightDendrogramFound = true; break; } } if (isRightDendrogramFound) { cur_dendrogram_index = i; break; } } root.right = cur_dendrogram; dendrogram_parts_list.RemoveAt(cur_dendrogram_index); } dendrogram_parts_list.Add(root); }
public Hierarchical_Rand_Jaccard_FM(Dendrogram ClusterInfo, ArrayList ClassInfo) { this.ClusterInfo = ClusterInfo; this.ClassInfo = ClassInfo; }
private void Cluster_button_Click(object sender, EventArgs e) { isFuzzyClustering = false; isHierarchicalClustering = false; for (int i = 0; i < points.Count; i++) { ((Point)points[i]).cluster_numbers.Clear(); } if (LikeClassInfo_rb.Checked) { GenerationTypes form = new GenerationTypes(); form.ShowDialog(); if (form.isForHierarchicalClustering) { isHierarchicalClustering = true; dendrogram = CreateClassesDendrogram(); } else if (form.isForFuzzyClustering) { isFuzzyClustering = true; CreateClassesMembershipMatrix(); } else { for (int i = 0; i < points.Count; i++) { ((Point)points[i]).cluster_numbers.Add((int)((ArrayList)ClassInfo[i])[0]); } } } else if (ClusteringAlgorithms_rb.Checked) { ClusteringForm form = new ClusteringForm(points, LowerBorders, UpperBorders, true); form.ShowDialog(); if (form.isHierarchicalClustering) { isHierarchicalClustering = true; dendrogram = form.getDendrogram(); } else if (form.isFuzzyClustering) { isFuzzyClustering = true; MembershipMatrix = form.getMemebershipMatrix(); } else { points = form.getPoints(); } } else if (Random_rb.Checked) { GenerationTypes form = new GenerationTypes(); form.ShowDialog(); if (form.isWithoutNoise) { CreateRandomClustersWithoutNoise(); } else if (form.isWithNoise) { CreateRandomClustersWithNoise(); } else if (form.isForHierarchicalClustering) { isHierarchicalClustering = true; CreateRandomDendrogram(); } else if (form.isForFuzzyClustering) { isFuzzyClustering = true; CreateRandomMembershipMatrix(); } } isClustered = true; Close(); }
public QualityForm(Dendrogram ClusterInfo, ArrayList ClassInfo) { InitializeComponent(); dendrogram = ClusterInfo; this.ClassInfo = ClassInfo; }