View source: R/parApplyDistanceBasedCA.R
| parApplyDistanceBasedCA | R Documentation |
Repeatedly applies a distance-based clustering function to one distance or dissimilarity input, or to a collection of such inputs. Trials may run serially or on a parallel worker cluster.
parApplyDistanceBasedCA(
Distances,
FUN,
NumberOfTrials = 1:100,
ClusterNo = NULL,
WorkersOrNo,
SocketType = "PSOCK",
SetSeed = TRUE,
...
)
Distances |
Distance or dissimilarity representation accepted by |
FUN |
Function or character string naming a distance-based clustering method.
The result should normally be a list containing a unique element named
|
NumberOfTrials |
Positive integer count or vector of positive integer trial identifiers.
A scalar |
ClusterNo |
Number of clusters passed to |
WorkersOrNo |
Missing, |
SocketType |
Character scalar passed to |
SetSeed |
Logical scalar. If |
... |
Further arguments passed to |
The distance input is passed preferentially to a formal argument named
DataOrDistances, Distances, Distance, or
Dissimilarities. If none is present, the first inspectable non-dots
argument is used.
An internally created worker cluster is stopped when the function exits. An externally supplied cluster remains under the caller's control.
For one input, a list containing:
Cls_Matrix |
Matrix of clustering assignments, one column per trial, or |
ComputationTime |
Named numeric vector containing elapsed trial times. |
Seeds |
Named integer vector containing trial seeds, or |
CAobjects |
Named list containing the complete clustering results. |
For a collection of inputs, returns a named list containing one result per distance or dissimilarity input.
The default PSOCK backend is suitable for Windows and is also portable to macOS and Unix-like systems. Use serial execution during package examples and most CRAN tests to avoid platform-dependent worker startup behavior.
Michael Thrun
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.
parApplyClusterAnalysis,
parApplyDataBasedCA,
parLapply
distance_clustering <- function(Distances, ClusterNo = 2) {
fit <- stats::hclust(Distances)
cls <- stats::cutree(fit, k = ClusterNo)
list(Cls = cls, Object = fit)
}
set.seed(3)
Data <- matrix(rnorm(40), ncol = 2)
Distances <- stats::dist(Data)
result <- parApplyDistanceBasedCA(
Distances = Distances,
FUN = distance_clustering,
NumberOfTrials = 2,
ClusterNo = 2,
WorkersOrNo = NULL
)
result$Cls_Matrix
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.