R: Farthest point sampling

farthest_point_sampling {rdist} | R Documentation

## Farthest point sampling

### 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

    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

    # 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]

[Package rdist version 0.0.5 Index]