I'm trying to write simple data format recognition program (that shows "what things does this unknown uncompressed unencrypted file have inside and where that things are located in the file") and it needs algorithm to solve the following thing:
Suppose $A_1, ... , A_n$ are input matrices.
For input matrix $X$ I should find $a_1, ..., a_n$ that brings
$R = X - a_1 A_1 - ... - a_n A_n$ to minimum (for example, using sum of elements as norm).
All involved matrices, including $R$ have only positive elements.
Each $A_i$ is a piece of statistic (256x256 matrix of "what probability of byte $i$ following byte $j$") for predefined sample data and $a_i$ should show how much of $A_i$'s trait there is in $X$'s data block.
Are there any known efficient (maybe approximate) algorithms to do this? Are there any simple (i.e. not a binding to some big mathematical framework) open source software libraries to avoid manual implementation?