矩阵相乘结果值范围 [英] matrix multiplication result value range
问题描述
这里是第一个问题: 关于输出值LeGall 5/3小波的范围
Here is the initial question: About the output value range of LeGall 5/3 wavelet
今天我发现实际上变换可以看作是矩阵乘法.容易将小波系数计算为矩阵(为了估计该值,将忽略所有舍入操作,这不会影响最大值的估计.)
Today I found actually the transform can be seen as a matrix multiplication. It is easy to calculate the wavelet coefficients as a matrix (in order to estimate the value, all the Rounded down action is ignored which will not affect the estimation of the max value).
DWT2的第一级有两个步骤,分别在两个方向上执行LeGall 5/3滤波器.如果我们将I作为输入8 * 8矩阵,将A作为小波系数矩阵.
The 1st level of DWT2 has two steps which is to perform the LeGall 5/3 filter on two directions. If we see the I as the input 8*8 matrix and A as the wavelet coefficients matrix.
-
对于水平方向: output1 = I.A
For the horizontal direction: output1 = I.A
然后计算垂直方向: 实际上,它可以表示为output2 = output1'.A(再次使用output1的转置来乘以A),这将得到我们想要的结果的转置.
Then the vertical direction is calculated: In fact, it can be represented as output2 = output1'.A (use the transpose of output1 to multiply A again) which will get the transpose of the result we want.
转置输出2. output_lvl1 = output2'=(output1'.A)'=((IA)'.A)'=(A'.I'.A)'= A'.IA(我在此处详细说明以免出现数学问题符号...)
Transpose the output2. output_lvl1 = output2' = (output1'.A)' = ((I.A)'.A)' = (A'.I'.A)'=A'.I.A (I put details here to make it clear without the math symbol...)
小波的第二级仅在LL区域执行,该区域为output_lvl1(1:4,1:4).基本上,过程是相同的(让系数矩阵表示为B).
And the 2nd level of the wavelet is only performed at the LL area which is the output_lvl1(1:4,1:4). And basically the process is the same (let the coefficients matrix represented as B).
这是根据我的计算得出的矩阵A和B的系数(希望它是正确的...)
Here is the coefficients of the matrix A and B based on my calculation (hope it is correct...)
A = [0.75 -0.125 0 0 -0.5 0 0 0;
0.5 0.25 0 0 1 0 0 0;
-0.25 0.75 -0.125 0 -0.5 -0.5 0 0;
0 0.25 0.25 0 0 1 0 0;
0 -0.125 0.75 -0.125 0 -0.5 -0.5 0
0 0 0.25 0.25 0 0 1 0;
0 0 -0.125 0.625 0 0 -0.5 -1;
0 0 0 0.25 0 0 0 1];
B = [0.75 -0.125 -0.5 0;
0.5 0.25 1 0;
-0.25 0.75 -0.5 -1;
0 0.125 0 1];
现在问题变成了: 1.如果我们知道A,并且Input(matrix I)的范围是-128到+127,那么output_lvl1 = A'.I.A的值范围是什么?
And now the question became: 1. if we know A and the range of Input(matrix I) which is -128 to +127, what is the value range of output_lvl1 = A'.I.A?
- 如果我们将output_lvl1(1:4,1:4)用作输入I2,那么B'.I2.B的值范围是多少?
我真的需要一些数学帮助.预先谢谢你.
I really need some math help here. Thank you in advance.
推荐答案
终于,我找到了解决此问题的方法. SymPy lib 是我真正需要的.
Well finally I found a way to solve this. SymPy lib is what I really need.
因为最大值只有在B'.I2.B的结果中才有可能.因此,程序将执行此操作.
As the max value could only be possible in results of B'.I2.B. So a program will do this.
from sympy import *
def calcu_max(strin):
x=0
strin1 = str(strin).replace('*',' ').replace('+',' ').replace('-',' ')
strin1 = strin1.split(' ')
for ele in strin1:
if '[' in ele or ']' in ele or ele =='':
continue
x = x + float(ele)
return x
DWT1 = Matrix(8, 8, [0.75, -0.125, 0, 0,-0.5, 0, 0, 0, 0.5, 0.25, 0, 0, 1, 0, 0, 0, -0.25, 0.75, -0.125, 0, -0.5, -0.5, 0, 0, 0, 0.25, 0.25, 0, 0, 1, 0, 0, 0,-0.125, 0.75, -0.125, 0, -0.5, -0.5, 0, 0, 0, 0.25, 0.25, 0, 0, 1, 0, 0, 0, -0.125, 0.625, 0, 0, -0.5, -1, 0, 0, 0, 0.25, 0, 0, 0, 1])
Input1 = MatrixSymbol('A',8,8)
DWT1_t = Transpose(DWT1)
output_lvl1_1d = DWT1_t*Input1
output_lvl1_2d = output_lvl1_1d* DWT1
#print 'output_lvl1_2d[0,0]: '
#print simplify(output_lvl1_2d[0,0])
#bulit 2nd lvl input from the lvl1 output (1:4,1:4)
input_lvl2 = output_lvl1_2d[0:4,0:4]
DWT2 = Matrix(4, 4, [0.75, -0.125, -0.5, 0, 0.5, 0.25, 1, 0, -0.25, 0.75, -0.5, -1, 0, 0.125, 0, 1])
DWT2_t = Transpose(DWT2)
output_lvl2_1d = DWT2_t*input_lvl2
output_lvl2_2d = output_lvl2_1d * DWT2
#Lvl 2 calculate max
max_lvl2 = zeros(4,4)
for i in range(4):
for j in range(4):
max_lvl2[i,j]=128.0*calcu_max(simplify(output_lvl2_2d[i,j]))
print str(i)+' '+str(j)+' '+str(max_lvl2[i,j])
#print max_lvl2[i,j]
print max_lvl2
好吧,这是结果(将所有可能的最大值放入一个矩阵,而最小值相应为负):
Well, here is the result (putting all possible max values in one matrix, and min values are correspondingly negative):
[338.000000000000, 266.500000000000, 468.000000000000, 468.000000000000],
[266.500000000000, 210.125000000000, 369.000000000000, 369.000000000000],
[468.000000000000, 369.000000000000, 648.000000000000, 648.000000000000],
[468.000000000000, 369.000000000000, 648.000000000000, 648.000000000000]
然后我要寻找648.
这篇关于矩阵相乘结果值范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!