View source: R/parApplyClusterAnalysis.R
| parApplyClusterAnalysis | R Documentation |
Repeatedly applies a clustering method to data or distances. Trials can be executed serially or on a worker cluster from the recommended parallel package. A single input or a list of inputs can be processed. It was used for the benchmarking of clustering algorithms in [Thrun, 2018; Thrun/Ultsch, 2020; Thrun, 2021].
parApplyClusterAnalysis(
DataOrDistances,
FUN,
NumberOfTrials = 1:100,
ClusterNo = NULL,
WorkersOrNo,
SocketType = "PSOCK",
SetSeed = TRUE,
...
)
DataOrDistances |
Data, distances, dissimilarities, or a list of such inputs. A list that is
not a |
FUN |
A function or character string naming a clustering function. The clustering
function should return a list with a unique element named |
NumberOfTrials |
A positive integer count or a vector of positive integer trial identifiers.
If a single value |
ClusterNo |
Number of clusters supplied to |
WorkersOrNo |
Missing, If missing, the function attempts to use one fewer than the number of
detected logical CPU cores. |
SocketType |
Non-empty character scalar passed to the |
SetSeed |
Logical scalar. If |
... |
Further arguments passed to |
Default is the number of cores existing minus 1.
In FCPS default parameters for each clustering algorithm are used automatically if not specified by the user. parApplyClusterAnalysis expects in FUN a function of a clustering algorithm which returns a list of objects of which one is named Cls. If not given the whole output of FUN is returned with a warning.
Cls is a [1:N] numerical vector of of numbers 1:k of the k clusters labeling the data points to the clusters.
For a single input, a list with components:
Cls_Matrix |
Matrix containing one clustering vector per trial. Column names identify
seeds or trial IDs. It is |
ComputationTime |
Named numeric vector containing elapsed computation time in seconds for each trial. |
Seeds |
Named integer vector containing the seeds used for the trials, or
|
CAobjects |
List of complete clustering results. For this generic wrapper, it is
included when |
For multiple inputs, a list containing one result of this form per input is returned. Input names are retained when present.
Michael Thrun
Thrun, M. C.: Projection-Based Clustering through Self-Organization and Swarm Intelligence, Springer, Heidelberg, ISBN: 978-3658205393, 2018.
Thrun, M. C., Ultsch, A.: Swarm Intelligence for Self-Organized Clustering, Artificial Intelligence, Vol. 290, pp. 103237, DOI: 10.1016/j.artint.2020.103237, Elsevier, 2021.
Thrun, M. C.: Distance-Based Clustering Challenges for Unbiased Benchmarking Studies, Nature Scientific Reports, Vol. 11, pp. 18988, DOI: 10.1038/s41598-021-98126-1, 2021.
clusterApply
simple_clustering <- function(Data, ClusterNo = 2, ...) {
fit <- stats::kmeans(Data, centers = ClusterNo)
list(Cls = fit$cluster, Object = fit)
}
DataList=list(
Dataset1=matrix(rnorm(40, 0), ncol = 2),
DataSet2=matrix(rnorm(40, 4), ncol = 2)
)
# Serial example
result <- parApplyClusterAnalysis(
DataOrDistances = DataList,
FUN = simple_clustering,
NumberOfTrials = 2,
ClusterNo = 2,
WorkersOrNo = NULL
)
result$Cls_Matrix
result$ComputationTime
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.