Kronecker product {tensorEVD}R Documentation

Kronecker product

Description

Computes the direct Kronecker product between two matrices

Usage

Kronecker(A, B, rows = NULL, cols = NULL, 
          make.dimnames = FALSE, drop = TRUE,
          inplace = FALSE) 

Arguments

A

(numeric) Left numeric matrix

B

(numeric) Right numeric matrix

rows

(integer) Index which rows of the Kronecker are to be returned. They must range from 1 to nrow(A)*nrow(B). Default rows=NULL will return all the rows

cols

(integer) Index which columns of the Kronecker are to be returned. They must range from 1 to ncol(A)*ncol(B). Default cols=NULL return all the columns

drop

Either TRUE or FALSE to whether return a uni-dimensional vector when output is a matrix with either 1 row or 1 column as per the rows and cols arguments

make.dimnames

TRUE or FALSE to whether add rownames and colnames attributes to the output

inplace

TRUE or FALSE to whether operate directly on one input matrix (A or B) when the other one is a scalar. This is possible only when rows=NULL and cols=NULL. When TRUE the output will be overwritten on the same address occupied by the input that is not scalar. Default inplace=FALSE

Details

For any two matrices A={aij} of dimensions m × n and B={bij} of dimensions p × q, the direct Kronecker product between them is a matrix defined as the block matrix

AB = {aijB}

which is of dimensions mp × nq.

Selecting specific rows and columns from the Kronecker can be done by pre- and post- multiplication with incidence matrices

R (AB) C'

where R is an incidence matrix for rows that can be formed by an integer vector rows, and C is an incidence matrix for columns that can be formed by an integer vector cols. This sub-matrix of the Kronecker can be obtained by matrix indexing using rows and cols as

Kronecker(A,B)[rows,cols]

The function computes this sub-matrix of the Kronecker product directly from A and B without forming the whole Kronecker product. This is very useful if a relatively small number of row/columns are to be selected.

Value

Returns the Kronecker product matrix. It can be a sub-matrix of it as per the rows and cols arguments.

Examples

  require(tensorEVD)
  
  # Kronecker product of 2 vectors
  A = rnorm(3)
  B = rnorm(2) 
  (K = Kronecker(A, B))
  # it must equal when using from the R-base package:
  (K0 = kronecker(A, B))
  
  # Kronecker product of 2 matrices
  A = matrix(rnorm(12), ncol=3)
  B = matrix(rnorm(4), ncol=2)
  K = Kronecker(A, B)
  # (it must equal (but faster) to:)
  K0 = kronecker(A, B)
  all.equal(K,K0)
  
  # Subsetting rows/columns from the Kronecker
  A = matrix(rnorm(100*150), ncol=150)
  B = matrix(rnorm(100*120), ncol=120)
  rows = c(1,3,5,7)
  cols = c(10,20,30,50)
  K = Kronecker(A, B, rows=rows, cols=cols)
  # (it must equal (but much faster) to:)
  K0 = kronecker(A, B)[rows,cols]
  all.equal(K,K0)
  


[Package tensorEVD version 0.1.1 Index]