Description Usage Arguments Examples
View source: R/farthest_point_sampling.R
Farthest point sampling returns a reordering of the metric space P = p_1, ..., p_k, such that each p_i is the farthest point from the first i-1 points.
1 2 3 4 5 6 7 | farthest_point_sampling(
mat,
metric = "precomputed",
k = nrow(mat),
initial_point_index = 1L,
return_clusters = FALSE
)
|
mat |
Original distance matrix |
metric |
Distance metric to use (either "precomputed" or a metric from |
k |
Number of points to sample |
initial_point_index |
Index of p_1 |
return_clusters |
Should the indices of the closest farthest points be returned? |
1 2 3 4 5 6 7 8 9 10 | # generate data
df <- matrix(runif(200), ncol = 2)
dist_mat <- pdist(df)
# farthest point sampling
fps <- farthest_point_sampling(dist_mat)
fps2 <- farthest_point_sampling(df, metric = "euclidean")
all.equal(fps, fps2)
# have a look at the fps distance matrix
rdist(df[fps[1:5], ])
dist_mat[fps, fps][1:5, 1:5]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.