Implementation of Holographic Reduced Representations

Description

Specific functions for creating and working with Holographic Reduced Representations. Supplies functions for all standard algebraic VSA operations on vectors: multiplication, addition, superposition, scaling, powers (including inverses), approximate inverse, and similarity. These work in functional and operator form (e.g., add(x, y) and x * y both call the add method for class realhrr.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## S3 method for class 'realhrr'
newVec(what = c("rand", "I", "1", "0", "NA"), len = options("vsalen")[[1]],
        elts = NULL, cnorm = getOption("vsacnorm", TRUE), opnorm = getOption("vsaopnorm", FALSE),
        vsatype = getOption("vsatype"))
## S3 method for class 'realhrr'
vsaprod(e1, e2, method = c("fft", "outer"))
## S3 method for class 'realhrr'
appinv(e1)


## S3 method for class 'realhrr'
add(e1, ...)
## S3 method for class 'realhrr'
vnorm(e1)
## S3 method for class 'realhrr'
dot(e1, e2)
## S3 method for class 'realhrr'
equiv(e1, e2, tol)
## S3 method for class 'realhrr'
cosine(e1, e2, mag1, mag2)
## S3 method for class 'realhrr'
mag(e1, actual)
## S3 method for class 'realhrr'
vsapower(e1, e2)
## S3 method for class 'realhrr'
vsascale(e1, e2)
addnorm(...)

Arguments

what

the type of vector wanted: one of rand, I, 1, 0, NA:

  • rand is a vector filled with random samples from a Gaussian distribution with mean 0 and standard deviation 1/len

  • I and 1 mean the same thing and return the identity vector (i.e., the vector satisfying x * I = x for all non-zero x)

  • 0 is the zero vector, i.e., the vector satisfying x * 0 = 0 and x + 0 = x for all vectors x

  • NA is a vector filled with NA values.

what is ignored if elts is supplied.

len

the number of elements in the vector

elts

the raw elements for the vector

cnorm

a logical value (TRUE or FALSE) - controls whether the new vectors is created to have a magnitude of 1

opnorm

a logical value (TRUE or FALSE) - controls whether the result of a vsa operation is normalized to have a magnitude of 1

vsatype

ignored for newVec.realhrr (as with all methods of newVec)

e1

a vsa vector – a subclass of vsa

e2

a vsa vector for vsaprod, dot, equiv, cosine, and add, or a scalar (a numeric vector of length 1) for vsapower and vsascale

mag1,mag2

precomputed magnitudes for e1 and e2

actual

work with data values from this object (in this mode of invocation e1 is a template holding the class)

method

computational method for convolution (vsaprod)

tol

numerical tolerance for equiv

...

addtional vsa vectors for add

Details

These functions provide implementations of VSA operations for real-valued Holographic Reduced Representations (in the "spatial" domain). All of these functions take as arguments one or more realhrr VSA vectors, and possibily a scalar. The result is a realhrr VSA vector, or a scalar with class simval. To catch some errors due to misunderstanding of R's precedence, a simval scalar cannot be supplied as the argument of one of these functions (to do, remove the simval class using the function scalar).

  • mag computes the magnitude of a vector (scalar value) as the L2 norm (sum(e1^2))

  • vnorm normalizes a vector so that its magnitude is 1 (vector value)

  • vsaprod and its synonym * compute the circular (wrapped) convolution of two vectors (vector value)

  • appinv and its synonym ! computes an approximate inverse of a vector, which for realhrr is e1[c(1,seq(len(e1), 2)]. The expression x / y where x and y are vectors computes x * appinv(y). (vector value)

  • vsascale and its synonym * multiple a vector elementwise by a scalar (vector value).

  • add computes the vector superposition of a collection of vectors (supplied as arguments). For realhrrs this is simply the elementwise sum of its arguments. x + y is a synonym for add(x, y). x - y is a synonym for add(x, vsascale(y, -1)). (vector value)

  • addnorm computes the vector superposition of a collection of vectors (supplied as arguments) and normalizes the result.

  • vsapower and its synonym ^ compute the power of a vector. Negative powers are allowed (vector value)

  • equiv compares two vectors for approximate relative equality (to a quite strict tolerance) (logical value)

  • cosine and its synonym %cos% compute the normalized similarity of two vectors (normalized dot product) (scalar value with class simval). For realhrrs, the normalized similarity is the cosine of the angle between the two vectors.

  • dot and its synonym %.% compute the un-normalized similarity of two vectors (scalar value with class simval). For realhrrs, the unnormalized similarity is the dot-product of the two vectors.

Value

vsaprod, appinv, add, vnorm, vsapower, vsascale return a vsa object of the same class as their argument.

mag, dot and cosine return a scalar value with class simval

Author(s)

Tony Plate tplate@acm.org

References

http://www.d-reps.org

See Also

vsa, vsa.mem, for operator precedence: Syntax

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(vsa)
a <- newVec()
a
b <- newVec()
b
dot(a, b)
a 
elts(a)[1:10]
x <- a * b
(!a)
(!a * x) 
((!a) * x) 
(appinv(a) * x) 
(x / a) 
c <- newVec()
d <- newVec()
e <- newVec()
f <- newVec()
x <- vnorm(a * b + c * d + e * f)
mem <- vsamem(a, b, c, d, e, f)
cosmem(mem, a)
dotmem(mem, x / b)
cosmem(mem, x / b)
cosmem(mem, x / c)
cosmem(mem, x / f)
bestmatch(mem, x / b, cos=TRUE)
bestmatch(mem, x / b, cos=FALSE)