Sample Problem of a large block matrix:
I want to find the lowest eigenvalue of a blockdiagonal matrix h[x]
for a range of values of x
- To save the time, I do so by finding the lowest eigenvalue of each block individually and then lowest out of them but
Individual block diagonalizations take more time than single diagonalization of block matrix h[x]
for a range of values of x
.
b0 = RandomReal[{-1, 1}, {16, 16}]; c0 = RandomReal[{-1, 1}, {64, 64}]; d0 = RandomReal[{-1, 1}, {128, 128}]; e0 = RandomReal[{-1, 1}, {32, 32}];
b = b0 + Transpose[b0];
c = c0 + Transpose[c0];
d = d0 + Transpose[d0];
e = e0 + Transpose[e0];
h[x_] := x*SparseArray[Band[{1, 1}] -> {b, c, d, e}];
AbsoluteTiming[ParallelTable[-Eigenvalues[-h[x], 1, Method -> {"Arnoldi", "Criteria" -> "RealPart"}][[1]], {x, 0.1,5., 0.1}];][[1]]
blocks[x_] :=ConnectedComponents@AdjacencyGraph@Unitize@h[x]
eigbloc0[x_, bl_] := -Eigenvalues[-h[x][[#, #]], 1, Method -> {"Arnoldi", "Criteria" -> "RealPart"}][[1]] & /@ {blocks[x][[bl]]}
eigbloc1[x_] := Table[eigbloc0[x, bl], {bl, 1, 4, 1}]
AbsoluteTiming[ParallelTable[Min[Flatten[{eigbloc1[x]}]], {x, 0.1, 5., 0.1}];][[1]]
Output:
7.98266
11.7006
I was expecting lower time for individual block diagonalization, Could anyone suggest me the resolution ?
eigbloc0
callsh
. Ideally, you know the blocks already independently of the construction of the matrix -- because you know how to construct the matrix. $\endgroup$h[x=1.0]
, Individual digonalization procedure is faster. Could you please tell me how to avoid the repetitive computations in above program ? $\endgroup$ClearAll[blocks]; blocks = Range[#1 + 1, #2] & @@@ Partition[Accumulate[{0, 16, 64, 128, 32}], 2, 1]; eig[x_] := Module[{A}, A = -h[x]; Min@Table[ -Eigenvalues[A[[block, block]], 1, Method -> {"Arnoldi", "Criteria" -> "RealPart"}], {block, blocks} ] ];
$\endgroup$