farthest_point_sampling: Farthest point sampling

Description Usage Arguments Examples

View source: R/farthest_point_sampling.R

Description

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.

Usage

1
2
3
4
5
6
7
farthest_point_sampling(
  mat,
  metric = "precomputed",
  k = nrow(mat),
  initial_point_index = 1L,
  return_clusters = FALSE
)

Arguments

mat

Original distance matrix

metric

Distance metric to use (either "precomputed" or a metric from rdist)

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?

Examples

 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]

rdist documentation built on May 4, 2020, 5:13 p.m.