elementwise {comparator} | R Documentation |
Elementwise Similarity/Distance Vector
Description
Computes elementwise similarities/distances between two collections of objects (strings, vectors, etc.) using the provided comparator.
Usage
elementwise(comparator, x, y, ...)
## S4 method for signature 'CppSeqComparator,list,list'
elementwise(comparator, x, y, ...)
## S4 method for signature 'StringComparator,vector,vector'
elementwise(comparator, x, y, ...)
## S4 method for signature 'NumericComparator,matrix,vector'
elementwise(comparator, x, y, ...)
## S4 method for signature 'NumericComparator,vector,matrix'
elementwise(comparator, x, y, ...)
## S4 method for signature 'NumericComparator,vector,vector'
elementwise(comparator, x, y, ...)
## S4 method for signature 'Chebyshev,matrix,matrix'
elementwise(comparator, x, y, ...)
## S4 method for signature 'FuzzyTokenSet,list,list'
elementwise(comparator, x, y, ...)
## S4 method for signature 'InVocabulary,vector,vector'
elementwise(comparator, x, y, ...)
## S4 method for signature 'Lookup,vector,vector'
elementwise(comparator, x, y, ...)
## S4 method for signature 'MongeElkan,list,list'
elementwise(comparator, x, y, ...)
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 |
... |
other parameters passed on to other methods. |
Value
Every object in x
is compared to every object in y
elementwise
(with recycling) using the given comparator, to produce a numeric vector of
scores of length max{size(x), size(y)}
.
Methods (by class)
-
comparator = CppSeqComparator,x = list,y = list
: Specialization forCppSeqComparator
wherex
andy
are lists of sequences (vectors) to compare. -
comparator = StringComparator,x = vector,y = vector
: Specialization forStringComparator
wherex
andy
are vectors 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 = NumericComparator,x = vector,y = vector
: Specialization forNumericComparator
wherex
andy
are vectors to compare. -
comparator = Chebyshev,x = matrix,y = matrix
: Specialization forChebyshev
wherex
andy
matrices of rows (interpreted as vectors) to compare. Ifx
anyy
do not have the same number of rows, rows are recycled in the smaller matrix. -
comparator = FuzzyTokenSet,x = list,y = list
: Specialization forFuzzyTokenSet
wherex
andy
are lists of token vectors to compare. -
comparator = InVocabulary,x = vector,y = vector
: Specialization forInVocabulary
wherex
andy
are vectors of strings to compare. -
comparator = Lookup,x = vector,y = vector
: Specialization for aLookup
wherex
andy
are vectors of strings to compare -
comparator = MongeElkan,x = list,y = list
: Specialization forMongeElkan
wherex
andy
lists of token vectors to compare.
Note
This function is not strictly necessary, as the comparator
itself is a
function that returns elementwise vectors of scores. In other words,
comparator(x, y, ...)
is equivalent to
elementwise(comparator, x, y, ...)
.
Examples
## Compute the absolute difference between two sets of scalar observations
data("iris")
x <- as.matrix(iris$Sepal.Width)
y <- as.matrix(iris$Sepal.Length)
elementwise(Euclidean(), x, y)
## Compute the edit distance between columns of two linked data.frames
col.1 <- c("Hasna Yuhanna", "Korina Zenovia", "Phyllis Haywood", "Nicky Ellen")
col.2 <- c("Hasna Yuhanna", "Corinna Zenovia", "Phyllis Dorothy Haywood", "Nicole Ellen")
elementwise(Levenshtein(), col.1, col.2)
Levenshtein()(col.1, col.2) # equivalent to above
## Recycling is used if the two collections don't contain the same number of objects
elementwise(Levenshtein(), "Cora Zenovia", col.1)