Matrix chain multiplication

from Wikipedia, the free encyclopedia

Matrix chain multiplication refers to the multiplication of several matrices . Since the matrix multiplication is associative , you can use brackets as you wish. As a result, the number of possible calculation paths increases polynomially with the length of the matrix chain. With the method of dynamic programming , the bracketing of the matrix chain can be optimized so that the total number of arithmetic operations is minimized. The algorithm has a running time of .

The number of possible brackets for matrices can be determined with the Catalan number C n-1 .

Example: Let be a 10 × 30 matrix, a 30 × 5 matrix and a 5 × 60 matrix. Then there are two different ways to clamp the die product:

The number of basic operations is calculated as follows:

algorithm

The algorithm calculates a result matrix using dynamic programming. In the case of a chain of matrices, the input of the algorithm is the sequence of the dimension pairs, whereby the function firstdim or seconddim applied to a matrix or returns.

denotes the partial sequence of s that contains the first two pairs of dimensions. So is .

The algorithm is specified by a matrix recurrence.

initialization

For every two matrices long chains there is only one possibility of bracketing.

Recursion

,

whereby .

The cell contains the minimum number of basic arithmetic operations to multiply the partial sequence of the matrix chain. So the minimum number of operations when multiplying the entire chain is stored in the cell .

To construct the optimal stapling, to the optimal result has led must in the path of the DP matrix by backtracking from be from traced.

Efficiency

The length of the input sequence is denoted by. The algorithm needs a square matrix to store the intermediate results for all partial sequences . So the memory requirement is in .

Each cell has to be optimized via divisions. So the total runtime is in

variants

The optimization algorithm can be used for any sequences of objects which are chained by an associative operation if a cost function exists for the execution of the operation.

The number of brackets in can be calculated by simply modifying the recurrence .

Demarcation

Cormen, 2001 (p. 369), refers to an algorithm by Hu and Shing for the optimization of brackets in matrix chain multiplication, which has a running time of .

literature

swell

  1. Hu Shing, Computation of Matrix Chain Products, Part I, Part II. 1980, Report.