Skip to contents

MeanDist() reports the sum of pairwise distances divided by the number of selected elements, $$f(S) = \frac{\displaystyle\sum_{i < j,\, i,j \in S} d_{ij}}{|S|}$$, the objective maximised by MaxMean().

Usage

MeanDist(d, idx)

Arguments

d

Pairwise distance matrix or dist object.

idx

Integer vector of selected row/col indices.

Value

MeanDist() returns a numeric scalar, or NA_real_ if length(idx) < 2.

See also

MaxMean() which maximises this objective; MinDist() for the max-min (MMDP) analogue.

Examples

# The max-mean problem is defined for signed dissimilarities; with these the
# optimal subset has an interior size, chosen to maximise mean dispersion.
set.seed(1)
x <- matrix(runif(100, -5, 5), 10)
d <- (x + t(x)) / 2          # symmetric, signed
selection <- MaxMean(d)
selection                    # 5 of the 10 elements: {2, 5, 6, 8, 10}
#> 5 elements (2 5 6 8 10) selected by MaxMean RLTS, f = 2.714
MeanDist(d, selection)       # 2.714 — equals attr(selection, "score")
#> [1] 2.714473