-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified subsetting operator and adds find_medoids() function.
- Loading branch information
Showing
12 changed files
with
326 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Finds the medoids from a distance matrix | ||
#' | ||
#' @description This function finds the medoids from a distance matrix. The | ||
#' medoid is the object that minimizes the sum of distances to all other | ||
#' objects. This function takes advantage of the **RcppParallel** package to | ||
#' compute the medoids in parallel. | ||
#' | ||
#' @param D An object of class [`stats::dist`]. | ||
#' @param memberships A factor specifying the cluster memberships of the | ||
#' objects. | ||
#' | ||
#' @return A named integer vector specifying the indices of the medoids. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' D <- stats::dist(iris[, 1:4]) | ||
#' find_medoids(D) | ||
#' memberships <- as.factor(rep(1:3, each = 50L)) | ||
#' find_medoids(D, memberships) | ||
find_medoids <- function(D, memberships = NULL) { | ||
if (!inherits(D, "dist")) | ||
cli::cli_abort("The input argument {.arg D} must be of class {.cls dist}.") | ||
if (is.null(memberships)) | ||
return(GetMedoid(D)) | ||
if (!is.factor(memberships)) | ||
cli::cli_abort("The input argument {.arg memberships} must be of class {.cls factor}.") | ||
out <- GetMedoids(D, as.numeric(memberships)) | ||
names(out) <- levels(memberships) | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.