R: Khatri-Rao Matrix Product

KhatriRao {Matrix} | R Documentation

## Khatri-Rao Matrix Product

### Description

Computes Khatri-Rao products for any kind of matrices.

The Khatri-Rao product is a column-wise Kronecker product. Originally introduced by Khatri and Rao (1968), it has many different applications, see Liu and Trenkler (2008) for a survey. Notably, it is used in higher-dimensional tensor decompositions, see Bader and Kolda (2008).

### Usage

    KhatriRao(X, Y = X, FUN = "*", make.dimnames = FALSE)

### Arguments

`X,Y` | matrices of with the same number of columns.
`FUN` | the (name of the) `function` to be used for the column-wise Kronecker products, see `kronecker`, defaulting to the usual multiplication.
`make.dimnames` | logical indicating if the result should inherit `dimnames` from `X` and `Y` in a simple way.

### Value

a `"CsparseMatrix"`, say `R`, the Khatri-Rao product of `X` (n x k) and `Y` (m x k), is of dimension (n*m) x k, where the j-th column, `R[,j]` is the kronecker product `kronecker(X[,j], Y[,j])`.

### Note

The current implementation is efficient for large sparse matrices.

### Author(s)

Michael Cysouw, Univ. Marburg; minor tweaks by Martin Maechler.

### References

Khatri, C. G., and Rao, C. Radhakrishna (1968) Solutions to Some Functional Equations and Their Applications to Characterization of Probability Distributions. Sankhya: Indian J. Statistics, Series A 30, 167–180.

Liu, Shuangzhe, and Gõtz Trenkler (2008) Hadamard, Khatri-Rao, Kronecker and Other Matrix Products. International J. Information and Systems Sciences 4, 160–177.

Bader, Brett W, and Tamara G Kolda (2008) Efficient MATLAB Computations with Sparse and Factored Tensors. SIAM J. Scientific Computing 30, 205–231.

### See Also

`kronecker`.

### Examples

    ## Example with very small matrices:
    m <- matrix(1:12,3,4)
    d <- diag(1:4)
    KhatriRao(m,d)
    KhatriRao(d,m)
    dimnames(m) <- list(LETTERS[1:3], letters[1:4])
    KhatriRao(m,d, make.dimnames=TRUE)
    KhatriRao(d,m, make.dimnames=TRUE)
    dimnames(d) <- list(NULL, paste0("D", 1:4))
    KhatriRao(m,d, make.dimnames=TRUE)
    KhatriRao(d,m, make.dimnames=TRUE)
    dimnames(d) <- list(paste0("d", 10*1:4), paste0("D", 1:4))
    KhatriRao(m,d, make.dimnames=TRUE)
    KhatriRao(d,m, make.dimnames=TRUE)

    nm <- as(m,"nMatrix")
    nd <- as(d,"nMatrix")
    KhatriRao(nm,nd, make.dimnames=TRUE)
    KhatriRao(nd,nm, make.dimnames=TRUE)

    stopifnot(dim(KhatriRao(m,d)) == c(nrow(m)*nrow(d), ncol(d)))

[Package Matrix version 1.1-4 Index]