Se eu tiver duas matrizes e , das dimensões e , respectivamente, e quiser calcular , é mais eficiente reescrever a expressão como e só então avaliar numericamente, porque é da dimensão mas é da dimensão .
Eu quero resolver uma versão generalizada deste problema. Existe um algoritmo razoavelmente eficiente (não força bruta) para otimizar uma expressão que contém:
- Variáveis matriciais livres de dimensões conhecidas
- Produtos de subexpressões arbitrárias
- Subexpressões arbitrárias aumentadas para energia natural
... para que seja necessário o mínimo de trabalho para avaliar numericamente, depois de substituir as variáveis da matriz livre por valores da matriz concreta?
O problema da multiplicação da cadeia da matriz é um caso especial do meu problema.
Editar:
Esta é uma resposta provisória. Parece intuitivamente correto para mim, mas não tenho provas de que esteja correto. Se estiver correto, ainda estou interessado na prova. (Se não estiver correto, é claro, me corrija.)
Para cada produto elevado a uma potência, digamos , considere toda permutação cíclica dos fatores:
- ...
... recursively. Each power is to be calculated using exponentiation by squaring (obviously), and all other products are to be calculated using the optimal order returned by the matrix chain multiplication algorithm.
Edit:
The idea outlined in my previous edit is still somewhat nonoptimal. The exponentiation by squaring algorithm actually evaluates expressions of the form or , where isn't necessarily the identity matrix. But my algorithm doesn't consider the possibility of using the exponentiation by squaring algorithm with not equal to the identity matrix.
Respostas:
Disclaimer: The following method has not been rigorously proven to be optimal. An informal proof is provided.
The problem reduces to finding the most efficient ordering when considering the square of the product.
For example, when looking at e.g.(ABC)50 , we only need to optimally solve (ABC)2 since this expands to ABCABC . No useful ordering information is added by concatenating ABC again. The intuition here is that since the problem of optimal ordering can be solved bottom-up, higher orderings consisting of more elements using the same matrices are irrelevant.
Finding the best ordering ofABCABC reduces to the Matrix Chain Multiplication problem. After finding an optimal ordering, apply exponentiation to the triplet (n-tuple generally) in the ordering.
As an e.g., if the optimal ordering for the square isA(B(CA))BC , the solution to the initial problem is A(B(CA))49BC .
In summary:(A1A2⋯An)m is to solve (A1A2⋯An)2 .(A1A2⋯An)2 is best approached as an instance of the Matrix Chain Multiplication problem.G from the solution in (2) will give us the solution to (1) as some flavor of A1⋅A2⋅Gm−1⋅An (note that any other groupings from solving (2) should be applied as well).
1) The first step in solving
2) Solving
3) Using the n-tuple ordering
Informal proof(AB)n , we note that A and B have dimension X×Y and Y×X respectively. Any product using A and B has one of the following dimensions:
Considering the simplest case using two matrices,
We have eitherX<Y or Y≤X .
Assumption 1a):X<Y
AB has dimension X×X , and this ordering is guaranteed to be optimal from a bottom-up approach. Any other configuration of A and B is either equally good, or worse. Thus, the problem is optimally solved as (AB)n .
Assumption 1b):Y≤X
BA has dimension Y×Y . This is the optimal ordering for all products involving A and B . Thus, the solution is optimally found as A(BA)n−1B .
This concludes the proof, and we have only looked at the two orderings found inABAB , the square problem.
Using more matrices, the argument is similar. Perhaps an inductive proof is possible? The general idea is that solving the MCM for the square will find the optimal size for the operations with all involved matrices considered.
Case study:
fonte
If you want to calculate the product of n matricesA1 to An in the best possible time, you can easily calculate how many operations are needed to calculate the product of Ai to Aj for all 1 ≤ i ≤ j ≤ n in O(n3) steps.
fonte