0% found this document useful (0 votes)
141 views

Kolda - Tensors in MATLAB

This document provides an introduction to working with tensors in MATLAB. It discusses tensor notation, basic operations like multiplying tensors by matrices and vectors, converting tensors to and from matrix form, and representing tensors in factored forms like the CP and Tucker decompositions. Operations are illustrated through examples and properties are summarized. The document also describes how MATLAB classes can be used to implement tensor functionality and provide examples of algorithms for generating factored tensor representations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Kolda - Tensors in MATLAB

This document provides an introduction to working with tensors in MATLAB. It discusses tensor notation, basic operations like multiplying tensors by matrices and vectors, converting tensors to and from matrix form, and representing tensors in factored forms like the CP and Tucker decompositions. Operations are illustrated through examples and properties are summarized. The document also describes how MATLAB classes can be used to implement tensor functionality and provide examples of algorithms for generating factored tensor representations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Tensors in MATLAB

Brett Bader & Tammy Kolda


Sandia National Labs
Outline

lIntroduction & Notation


lTensor Operations
¡Multiplying times a Matrix
¡Multiplying times a Vector
¡Multiplying times another Tensor
¡Matricization
lStoring Tensors in Factored Form
lExample Algorithms for Generating
Factored Tensors
Introduction & Notation
Basic Notation
l Indices: n = 1, …, N
Tensor A of size
l Vector: a of size I1 I1 £ I2 £ I3
l Matrix: A of size I1 £ I2
l Tensor: A of size I1 £ I2 £ L £ IN

i1 = 1, …, I1
l The order of A is N
¡ “Higher-order” means N > 2
l The nth mode of A is of

3
,I

dimension In

,
=1
¡ mode = dimension or way i2 = 1, …, I2

i3
Operations on Tensors

l Element-wise: add, subtract, etc.


l Multiply
¡ Times a vector or sequence of vectors
¡ Times a matrix or sequence of matrices
¡ Times another tensor

l Convert to / from a matrix


l Decompose
¼
Tensor Operations
Tensors in MATLAB
l MATLAB is a high-level computing environment
l Higher-order tensors can be stored as multidimensional
array (MDA) objects
l But operations on MDAs are limited
¡ E.g., no matrix multiplication
l MATLAB’s class functionality enables users to create
their own objects
l The tensor class extends the MDA capabilities to
include multiplication and more
¡ Will show examples at the end of the talk
n-Mode Multiplication (with a Matrix)

l Let A be a tensor of size I1 £ I2 £ L £ IN


l Let U be a matrix of size Jn £ In
l Result size: I1 £ L £ In-1 £ Jn £ In+1 £ L £ IN
Matrix Interpretation

lA of size m £ n, U of size m £ k, V of size


n £ k, Σ of size k £ k
Property
Multiplication with a Sequence of Matrices

lLet A be a tensor of size I1 £ I2 £ L £ IN


lLet each U(n) be a matrix of size Jn £ In

lB is a tensor of size J1 £ J2 £ L £ JN
lNew notation
Multiplication with all but one of a
Sequence of Matrices
l Let A be a tensor of size I1 £ I2 £ L £ IN
l Let each U(n) be a matrix of size Jn £ In

l B of size J1 £ L £ Jn-1 £ In £ Jn+1 £ L £ JN


l New notation
Tensor Multiplication with a Vector
Bar over
operator
indicates
contracted
l Let A be a tensor of size I1 £ I2 £ L £ IN product.
l Let u be a vector of size In
l Result size: I1 £ L £ In-1 £ In+1 £ L £ IN (order N-1)
Matrix Interpretation

lA of size m £ n, u of size m, v of size n


Order Matters in Vector Case
Multiplication with a Sequence of Vectors

lLet A be a tensor of size I1 £ I2 £ L £ IN


lLet each u(n) be a vector of size In

l β is a scalar
lNew notation
Multiplication with all but one of a
Sequence of Vectors
l Let A be a tensor of size I1 £ I2 £ L £ IN
l Let each u(n) be a matrix of size In

l Result is vector b of size In


l New notation
Multiplying two Tensors
l Let A and B be tensors of size I1 £ I2 £ L £ IN

l Result is a scalar
l Frobenius norm is just k A k 2 = < A, A >
Multiplying two Tensors
l Let A be of size I1 £ L £ IM £ J1 £ L £ JN
l Let B be of size I1 £ L £ IM £ K1 £ L £ KP

l Result is of size J1 £ L £ JN £ K1 £ L £ KP
Matricize: Converting a Tensor to a Matrix

Key Point: Order of the


i1 = 1, …, I1

columns doesn’t matter so


long as it is consistent.
3
,I

i2 = 1
,

i2 = 2 i2 = I2
=1

i2 = 1, …, I2
i3

i1 = 1, …, I1

A(1) =
i3 = 1, …, I3 i3 = 1, …, I3 i3 = 1, …, I3
Matricize: Converting a Tensor to a Matrix
i1 = 1, …, I1

3
,I

i3 = 1 i3 = 2 i3 = I3
,
=1

i2 = 1, …, I2
i3

i2 = 1, …, I2

A(2) =
i1 = 1, …, I1 i1 = 1, …, I1 i1 = 1, …, I1
Matricize: Converting a Tensor to a Matrix
i1 = 1, …, I1

3
,I

i1 = 1 i1 = 2 i1 = I1
,
=1

i2 = 1, …, I2
i3

i3 = 1, …, I3

A(3) =
i2 = 1, …, I2 i2 = 1, …, I2 i2 = 1, …, I2
Inverse Matricize

lOne may also take a matrix and convert it


into a tensor

Need to know the size of


the tensor as well as the
mode (and type) of
matricization
Matricization & Mode-n Multiplication
Summary on Tensor Operations
Tensor times Matrix Tensor times Vector

Tensor times Tensor Matricization


Factored Tensors
Rank-1 Tensor

= λ
CP Model
l “CP” is shorthand for CANDECOMP (Carrol and Chang,
1970) and PARAFAC (Harshman, 1970) – identical
models that were developed independently

l λ is a K-vector
l Each U(n) is an In £ K matrix
l Tensor A is size I1 £ I2 £ L £ IN
CP Model

¼
Tucker Model

l Tucker, 1966

l λ is a tensor of size K1 £ K2 £ L £ KN
¡“Core Tensor” or “Core Array”
l Each U(n) is an In £ Kn matrix
l Tensor A is size I1 £ I2 £ L £ IN
Tucker Model

¼
Higher Order Power Method
De Lathauwer, De Moor, Vandewalle
lCompute a rank-1 approximation to a
given tensor
lIn: A of size I1 £ I2 £ L £ IN
lOut: B = λ u(1) ? u(2) ? L ? u(N) is a rank-
one tensor of size I1 £ I2 £ L £ IN that
estimates A
HO Power Method
MATLAB Classes Examples
Note: MATLAB class does not
replace Bro’s N-Way Toolbox

You might also like