Title: | Usual Operations for Distance Matrices in R |
---|---|
Description: | It provides the subset operator for dist objects and a function to compute medoid(s) that are fully parallelized leveraging the 'RcppParallel' package. It also provides functions for package developers to easily implement their own parallelized dist() function using a custom 'C++'-based distance function. |
Authors: | Aymeric Stamm [aut, cre] |
Maintainer: | Aymeric Stamm <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-10-25 05:32:51 UTC |
Source: | https://github.com/lmjl-alea/distops |
It provides the subset operator for dist objects and a function to compute medoid(s) that are fully parallelized leveraging the 'RcppParallel' package. It also provides functions for package developers to easily implement their own parallelized dist() function using a custom 'C++'-based distance function.
Maintainer: Aymeric Stamm [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/lmjl-alea/distops/issues
Subset operator for the distance matrix stored as an object of
class stats::dist
.
## S3 method for class 'dist' x[i, j, drop = TRUE, ...]
## S3 method for class 'dist' x[i, j, drop = TRUE, ...]
x |
An object of class |
i |
An integer vector of row indices. Values must be either all positive in which case they indicate the rows to select, or all negative in which case they indicate the rows to omit. |
j |
An integer vector of column indices. Values must be either all positive in which case they indicate the columns to select, or all negative in which case they indicate the columns to omit. |
drop |
A logical value indicating whether the result should be coerced to a vector or matrix if possible. |
... |
Additional arguments passed to |
A numeric matrix storing the pairwise distances between the requested observations.
D <- stats::dist(iris[, 1:4]) D[2:3, 7:12]
D <- stats::dist(iris[, 1:4]) D[2:3, 7:12]
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.
find_medoids(D, memberships = NULL)
find_medoids(D, memberships = NULL)
D |
An object of class |
memberships |
A factor specifying the cluster memberships of the objects. |
A named integer vector specifying the indices of the medoids.
D <- stats::dist(iris[, 1:4]) find_medoids(D) memberships <- as.factor(rep(1:3, each = 50L)) find_medoids(D, memberships)
D <- stats::dist(iris[, 1:4]) find_medoids(D) memberships <- as.factor(rep(1:3, each = 50L)) find_medoids(D, memberships)
This function adds a distance function to the package. It first
creates the R/{distance_name}Distance.R
file with the R wrapper function
for the distance function. It then creates the
src/{distance_name}Distance.cpp
file with the C++ implementation of the
distance function. It finally opens the latter file in the default editor.
The user will be able to implement the desired distance function in a way
compatible with the RcppParallel workflow.
use_distance(distance_name)
use_distance(distance_name)
distance_name |
A character string specifying the name of the distance that the user aims at implementing. |
Nothing.
use_distance("euclidean")
use_distance("euclidean")
This function setups the package to use the distops package.
It first creates the DESCRIPTION
file adding the Rcpp and
RcppParallel packages to both the Imports:
and LinkingTo:
fields
and the distops package to the LinkingTo:
field. It also adds the
SystemRequirements: GNU make
field. It then creates the NAMESPACE
file
adding the importFrom()
directives for the Rcpp and RcppParallel
packages and the useDynLib()
directive for packages with compiled code.
It finally creates the src/Makevars
and src/Makevars.win
files with the
appropriate compilation flags.
use_distops()
use_distops()
Nothing.
use_distops()
use_distops()