0% found this document useful (0 votes)
43 views4 pages

Agg Lomer at Ive

This document describes an agglomerative clustering program written in Java. The program takes input data representing the distances between data points, iteratively finds the closest points and merges them into clusters, and outputs the sequence of merges showing which points form clusters together at each step. It uses a distance matrix and stores cluster assignments and maximum distances in additional arrays as it performs the hierarchical clustering algorithm.

Uploaded by

chirusagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Agg Lomer at Ive

This document describes an agglomerative clustering program written in Java. The program takes input data representing the distances between data points, iteratively finds the closest points and merges them into clusters, and outputs the sequence of merges showing which points form clusters together at each step. It uses a distance matrix and stores cluster assignments and maximum distances in additional arrays as it performs the hierarchical clustering algorithm.

Uploaded by

chirusagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

AGGLOMERATIVE CLUSTERING PROGRAM

package agglomative; import java.util.Collections; import java.util.Scanner; /** * * @author admin */ public class Agglomative { Scanner scanner = new Scanner(System.in); int row, col; int a[][]; int max; int temp; int result[]; public void readata() { System.out.println("enter the number of rows"); row = Integer.parseInt(scanner.next()); col = row; a = new int[row][col]; result = new int[row]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (i != j) { System.out.println("enter " + i + "," + j + " element"); a[i][j] = Integer.parseInt(scanner.next()); } else { a[i][j] = -1; } } } int k = 0; result[0] = k + 1; do { max = a[0][1];

temp = 1; for (int i = 0; i < col; i++) { if (a[0][i] > max) { max = a[0][i]; temp = i; } } for (int i = 0; i < row; i++) { if (a[i][temp] > a[i][0] && i != 0) { a[i][0] = a[i][temp]; } } for (int j = 0; j < col; j++) { if (a[temp][j] > a[0][j] && j != 0) { a[0][j] = a[temp][j]; } } for (int i = 0; i < row; i++) { a[temp][i] = -1; a[i][temp] = -1; } k = k + 1; result[k] = temp + 1; for (int i = 0; i < k; i++) { System.out.print("x" + i + ","); } System.out.print("and x" + k + " "); System.out.println("form cluster at" + max); } while (k != row - 1); } public static void main(String args[]) { Agglomative agglomative = new Agglomative(); agglomative.readata(); } }

OUTPUT run: enter the number of rows 5 enter 0,1 element 9 enter 0,2 element 2 enter 0,3 element 4 enter 0,4 element 6 enter 1,0 element 9 enter 1,2 element 11 enter 1,3 element 5 enter 1,4 element 15 enter 2,0 element 2 enter 2,1 element 11 enter 2,3 element 6 enter 2,4 element 4 enter 3,0 element 4 enter 3,1 element 5 enter 3,2 element 6 enter 3,4 element 10 enter 4,0 element 6 enter 4,1 element 15 enter 4,2 element 4 enter 4,3 element

10 x0,and x1 form cluster at9 x0,x1,and x2 form cluster at15 x0,x1,x2,and x3 form cluster at11 x0,x1,x2,x3,and x4 form cluster at10 BUILD SUCCESSFUL (total time: 51 seconds)

You might also like