pairwise {comparator} | R Documentation |
Pairwise Similarity/Distance Matrix
Description
Computes pairwise similarities/distances between two collections of objects (strings, vectors, etc.) using the provided comparator.
Usage
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Comparator,ANY,missing'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'CppSeqComparator,list,list'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'CppSeqComparator,list,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'StringComparator,vector,vector'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'StringComparator,vector,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'NumericComparator,matrix,vector'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'NumericComparator,vector,matrix'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Chebyshev,matrix,matrix'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Chebyshev,matrix,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Minkowski,matrix,matrix'
elementwise(comparator, x, y, ...)
## S4 method for signature 'Minkowski,matrix,matrix'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Minkowski,matrix,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'FuzzyTokenSet,list,list'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'FuzzyTokenSet,vector,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'InVocabulary,vector,vector'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'InVocabulary,vector,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Lookup,vector,vector'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'Lookup,vector,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'MongeElkan,list,list'
pairwise(comparator, x, y, return_matrix = FALSE, ...)
## S4 method for signature 'MongeElkan,list,'NULL''
pairwise(comparator, x, y, return_matrix = FALSE, ...)
Arguments
comparator |
a comparator used to compare the objects, which is a
sub-class of |
x , y |
a collection of objects to compare, typically stored as entries
in an atomic vector, rows in a matrix, or entries in a list. The required
format depends on the type of |
return_matrix |
a logical of length 1. If FALSE (default), the pairwise
similarities/distances will be returned as a |
... |
other parameters passed on to other methods. |
Value
If both x
and y
are specified, every object in x
is compared with
every object in y
using the comparator, and the resulting scores are
returned in a size(x)
by size(y)
matrix.
If only x
is specified, then the objects in x
are compared with
themselves using the comparator, and the resulting scores are returned in a
size(x)
by size(y)
matrix.
By default, the matrix is represented as an instance of the
PairwiseMatrix
class, which is more space-efficient for symmetric
comparators when y
is not specified. However, if return_matrix = TRUE
,
the matrix is returned as an ordinary matrix
instead.
Methods (by class)
-
comparator = Comparator,x = ANY,y = missing
: Compute a pairwise comparator wheny
-
comparator = CppSeqComparator,x = list,y = list
: Specialization forCppSeqComparator
wherex
andy
are lists of sequences (vectors) to compare. -
comparator = CppSeqComparator,x = list,y = NULL
: Specialization forCppSeqComparator
wherex
is a list of sequences (vectors) to compare. -
comparator = StringComparator,x = vector,y = vector
: Specialization forStringComparator
wherex
andy
are vectors of strings to compare. -
comparator = StringComparator,x = vector,y = NULL
: Specialization forStringComparator
wherex
is a vector of strings to compare. -
comparator = NumericComparator,x = matrix,y = vector
: Specialization forNumericComparator
wherex
is a matrix of rows (interpreted as vectors) to compare with a vectory
. -
comparator = NumericComparator,x = vector,y = matrix
: Specialization forNumericComparator
wherex
is a vector to compare with a matrixy
of rows (interpreted as vectors). -
comparator = Chebyshev,x = matrix,y = matrix
: Specialization forChebyshev
wherex
andy
matrices of rows (interpreted as vectors) to compare. -
comparator = Chebyshev,x = matrix,y = NULL
: Specialization forMinkowski
wherex
is a matrix of rows (interpreted as vectors) to compare among themselves. -
comparator = Minkowski,x = matrix,y = matrix
: Specialization for aMinkowski
wherex
andy
matrices of rows (interpreted as vectors) to compare. -
comparator = Minkowski,x = matrix,y = matrix
: Specialization for aMinkowski
wherex
andy
matrices of rows (interpreted as vectors) to compare. -
comparator = Minkowski,x = matrix,y = NULL
: Specialization forMinkowski
wherex
is a matrix of rows (interpreted as vectors) to compare among themselves. -
comparator = FuzzyTokenSet,x = list,y = list
: Specialization forFuzzyTokenSet
wherex
andy
are lists of token vectors to compare. -
comparator = FuzzyTokenSet,x = vector,y = NULL
: Specialization forFuzzyTokenSet
wherex
is a list of token vectors to compare among themselves. -
comparator = InVocabulary,x = vector,y = vector
: Specialization forInVocabulary
wherex
andy
are vectors of strings to compare. -
comparator = InVocabulary,x = vector,y = NULL
: Specialization forInVocabulary
wherex
is a vector of strings to compare among themselves. -
comparator = Lookup,x = vector,y = vector
: Specialization for aLookup
wherex
andy
are vectors of strings to compare -
comparator = Lookup,x = vector,y = NULL
: Specialization forLookup
wherex
is a vector of strings to compare among themselves -
comparator = MongeElkan,x = list,y = list
: Specialization forMongeElkan
wherex
andy
are lists of token vectors to compare. -
comparator = MongeElkan,x = list,y = NULL
: Specialization forMongeElkan
wherex
is a list of token vectors to compare among themselves.
Examples
## Computing the distances between a query point y (a 3D numeric vector)
## and a set of reference points x
x <- rbind(c(1,0,1), c(0,0,0), c(-1,2,-1))
y <- c(10, 5, 10)
pairwise(Manhattan(), x, y)
## Computing the pairwise similarities among a set of strings
x <- c("Benjamin", "Ben", "Benny", "Bne", "Benedict", "Benson")
comparator <- DamerauLevenshtein(similarity = TRUE, normalize = TRUE)
pairwise(comparator, x, return_matrix = TRUE) # return an ordinary matrix