-
Notifications
You must be signed in to change notification settings - Fork 2
2. Example Usage of parallised ART 2 A clustering in single machine precision.
To illustrate the library, an example of the application of paralellised clustering with simple machine precision is presented step by step
- The first step is to import a float data matrix. The data matrix contains the inputs that need to be clustered.
- Initialisation of an ExecutorService that can use up to 9 threads concurrently.
- This is followed by the initialisation of 9 cluster tasks with different vigilance parameters.
- All 9 tasks are received and executed in the thread pool.
- The result of the invokeAll() call is stored in the variable tmpFuturesList. This is a list of futures objects representing the status and result of each task.
- Finally, the result of each Future object can be accessed.
float[][] tmpTestDataMatrix = FileUtil.importFloatDataMatrixFromTextFile(
"src/test/resources/de/unijena/cheminf/clustering/art2a/Bit_Fingerprints.txt", ','); ExecutorService tmpExecutorService = Executors.newFixedThreadPool(9); // number of tasks List tmpClusteringTask = new LinkedList<>(); for (float tmpVigilanceParameter = 0.1f; tmpVigilanceParameter < 1.0f; tmpVigilanceParameter += 0.1f) { Art2aClusteringTask tmpART2aFloatClusteringTask = new Art2aClusteringTask( tmpVigilanceParameter, tmpTestDataMatrix, 100, true); tmpClusteringTask.add(tmpART2aFloatClusteringTask); } List<Future> tmpFuturesList; tmpFuturesList = tmpExecutorService.invokeAll(tmpClusteringTask); for (Future tmpFuture : tmpFuturesList) { IArt2aClusteringResult tmpClusteringResult = tmpFuture.get(); System.out.println("Vigilance parameter: " + tmpClusteringResult.getVigilanceParameter()); System.out.println("Number of detected clusters: " + tmpClusteringResult.getNumberOfDetectedClusters()); System.out.println("Get cluster indices in cluster 0: " + tmpClusteringResult.getClusterIndices(2)); System.out.println("Get cluster representatives for cluster 0: " + tmpClusteringResult.getClusterRepresentatives(2)); }
Output:
Vigilance parameter: 0.1
Number of detected clusters: 6
Get cluster indices in cluster 0: {4, 6, 7, 9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.2
Number of detected clusters: 6
Get cluster indices in cluster 0: {4, 6, 7, 9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.3
Number of detected clusters: 6
Get cluster indices in cluster 0: {4, 6, 7, 9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.4
Number of detected clusters: 8
Get cluster indices in cluster 0: {6, 9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.5
Number of detected clusters: 9
Get cluster indices in cluster 0: {9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.6
Number of detected clusters: 10
Get cluster indices in cluster 0: {9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.7
Number of detected clusters: 10
Get cluster indices in cluster 0: {9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.8
Number of detected clusters: 10
Get cluster indices in cluster 0: {9}
Get cluster representatives for cluster 0: 9
Vigilance parameter: 0.9
Number of detected clusters: 10
Get cluster indices in cluster 0: {9}
Get cluster representatives for cluster 0: 9
INFORMATION: Paralellised clustering is also possible with double machine precision.