8.1 Introduction to Tensors

DATA 442/642 · Week 8 · PDF · HTML slides · PDF slides

Multi-way arrays and why flattening loses structure.

These notes walk through the lecture slides. The original deck is unchanged. On the course hub, HTML slides move one page at a time, and the PDF is the same deck.

Figures and notes follow Introduction to Tensor Decompositions and their Applications in Machine Learning.

1. Brief history

Tensors generalize matrices to higher dimensions: multidimensional arrays.

They and their decompositions appear in 1927, then sit unused in computer science until late in the 20th century. Cheaper compute and better multilinear algebra — especially in the last decade — moved them into statistics, data science, and machine learning.


2. Tensor basics

A tensor is a multi-way collection of numbers, usually from ℝ. The simplest high-dimensional case is a three-dimensional array: a data cube. The same notation extends to more modes.

A three-way tensor as a data cube


3. Tensor order

The order of a tensor is the number of dimensions.

Object Order Notation
Scalar 0 x∈ℝ
Vector 1 𝐱∈ℝI1
Matrix 2 𝐗∈ℝI1×I2
Higher-order tensor N 𝒳∈ℝI1×I2×⋯×IN

Each I is the length of that mode.

Scalars, vectors, matrices, and a 3-way tensor


4. Tensor indexing

Fix some indices to get a subarray.

  • Fibers: fix every index but one.
  • Slices (slabs): fix every index but two.

For a third-order tensor, fibers are x:jk=xjk (column), xi:k (row), xij: (tube). Slices are 𝒳::k=𝒳k (frontal), 𝒳:j: (lateral), 𝒳i:: (horizontal).

Fibers and slices of a 3-way tensor


5. Outer and inner product

The vector outer product is the product of the entries, written ⊚. For two length-n vectors 𝐚 and 𝐛,

𝐗=𝐚⊚𝐛=𝐚𝐛⊤.

For N vectors the same product is a tensor:

𝒳=𝐚(1)⊚𝐚(2)⊚⋯⊚𝐚(N),

with xi1i2⋯iN=ai1(1)ai2(2)⋯aiN(N).

The inner product of two length-n vectors is a scalar:

x=⟨𝐚,𝐛⟩=𝐚⊤𝐛=∑i=1naibi.

6. Rank-1 tensors

An N-way tensor is rank-1 if it is exactly the outer product of N vectors. Adding a mode is a new scaling of a sub-tensor.

A rank-1 matrix: 𝐗=𝐚⊚𝐛. A rank-1 3-way tensor: 𝒳=𝐚⊚𝐛⊚𝐜. The N-way form is the product above.

Rank-1 tensor as an outer product of vectors


7. Tensor rank

The rank rank(𝒳)=R is the smallest number of rank-1 tensors that sum to 𝒳:

𝒳=∑r=1Rλr𝐚r(1)⊚𝐚r(2)⊚⋯⊚𝐚r(N).

The factor matrices 𝐀 store those vectors as columns:

𝐀=[𝐚1𝐚2⋯𝐚R].

The weights λr (with λ∈ℝR) often absorb column norms, typically so each column has squared length one.


Practice

  1. A matrix is a 2-way array. What is a tensor adding?

  2. What is a fiber, and what is a slice?

  3. What does rank(𝒳)=R mean in terms of rank-1 tensors?