canonicalize_pairs {clevr}R Documentation

Canonicalize element pairs

Description

Coerce a collection of element pairs into canonical form. Facilitates testing of equivalence.

Usage

canonicalize_pairs(pairs, ordered = FALSE)

Arguments

pairs

a matrix or data.frame of element pairs where rows correspond to element pairs and columns correspond to element identifiers.

ordered

whether to treat the element pairs as ordered—i.e. whether pair (x, y) is distinct from pair (y, x) for x \neq y. Defaults to FALSE, which is appropriate for clustering, undirected link prediction, record linkage etc.

Value

Returns the element pairs in canonical form, so that:

Examples

messy_pairs <- rbind(c(2,1), c(1,2), c(3,1), c(1,2))
clean_pairs <- canonicalize_pairs(messy_pairs)
all(rbind(c(1,2), c(1,3)) == clean_pairs) # duplicates removed and order fixed


[Package clevr version 0.1.2 Index]