Title: | Efficient Initials for Computing the Maximal Eigenpair |
---|---|
Description: | An implementation for using efficient initials to compute the maximal eigenpair in R. It provides three algorithms to find the efficient initials under two cases: the tridiagonal matrix case and the general matrix case. Besides, it also provides two algorithms for the next to the maximal eigenpair under these two cases. |
Authors: | Mu-Fa Chen <[email protected]> |
Maintainer: | Xiao-Jun Mao <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-11 06:30:47 UTC |
Source: | https://github.com/mxjki/efficientmaxeigenpair |
Calculate the maximal eigenpair for the general matrix.
eff.ini.maxeig.general(A, v0_tilde = NULL, z0 = NULL, z0numeric, xi = 1, digit.thresh = 6)
eff.ini.maxeig.general(A, v0_tilde = NULL, z0 = NULL, z0numeric, xi = 1, digit.thresh = 6)
A |
The input general matrix. |
v0_tilde |
The unnormalized initial vector |
z0 |
The type of initial |
z0numeric |
The numerical value assigned to initial |
xi |
The coefficient used to form the convex combination of |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
eff.ini.maxeig.tri
for the tridiagonal matrix maximal
eigenpair by rayleigh quotient iteration algorithm.
eff.ini.maxeig.shift.inv.tri
for the tridiagonal matrix
maximal eigenpair by shifted inverse iteration algorithm.
A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'fixed') A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'Auto') ##Symmetrizing A converge to second largest eigenvalue A = matrix(c(1, 3, 9, 5, 2, 14, 10, 6, 0, 11, 11, 7, 0, 0, 1, 8), 4, 4) S = (t(A) + A)/2 N = dim(S)[1] a = diag(S[-1, -N]) b = diag(S[-N, -1]) c = rep(NA, N) c[1] = -diag(S)[1] - b[1] c[2:(N - 1)] = -diag(S)[2:(N - 1)] - b[2:(N - 1)] - a[1:(N - 2)] c[N] = -diag(S)[N] - a[N - 1] z0ini = eff.ini.maxeig.tri(a, b, c, xi = 7/8)$z[1] eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'numeric', z0numeric = 28 - z0ini)
A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'fixed') A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'Auto') ##Symmetrizing A converge to second largest eigenvalue A = matrix(c(1, 3, 9, 5, 2, 14, 10, 6, 0, 11, 11, 7, 0, 0, 1, 8), 4, 4) S = (t(A) + A)/2 N = dim(S)[1] a = diag(S[-1, -N]) b = diag(S[-N, -1]) c = rep(NA, N) c[1] = -diag(S)[1] - b[1] c[2:(N - 1)] = -diag(S)[2:(N - 1)] - b[2:(N - 1)] - a[1:(N - 2)] c[N] = -diag(S)[N] - a[N - 1] z0ini = eff.ini.maxeig.tri(a, b, c, xi = 7/8)$z[1] eff.ini.maxeig.general(A, v0_tilde = rep(1, dim(A)[1]), z0 = 'numeric', z0numeric = 28 - z0ini)
Calculate the maximal eigenpair for the tridiagonal matrix by shifted inverse iteration algorithm.
eff.ini.maxeig.shift.inv.tri(a, b, c, xi = 1, digit.thresh = 6)
eff.ini.maxeig.shift.inv.tri(a, b, c, xi = 1, digit.thresh = 6)
a |
The lower diagonal vector. |
b |
The upper diagonal vector. |
c |
The shifted main diagonal vector. The corresponding unshift diagonal vector is -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1]) where N+1 is the dimension of matrix. |
xi |
The coefficient used to form the convex combination of |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
eff.ini.maxeig.tri
for the tridiagonal matrix maximal
eigenpair by rayleigh quotient iteration algorithm.
eff.ini.maxeig.general
for the general matrix maximal eigenpair.
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 eff.ini.maxeig.shift.inv.tri(a, b, c, xi = 1)
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 eff.ini.maxeig.shift.inv.tri(a, b, c, xi = 1)
Calculate the maximal eigenpair for the tridiagonal matrix by rayleigh quotient iteration algorithm.
eff.ini.maxeig.tri(a, b, c, xi = 1, digit.thresh = 6)
eff.ini.maxeig.tri(a, b, c, xi = 1, digit.thresh = 6)
a |
The lower diagonal vector. |
b |
The upper diagonal vector. |
c |
The shifted main diagonal vector. The corresponding unshift diagonal vector is -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1]) where N+1 is the dimension of matrix. |
xi |
The coefficient used to form the convex combination of |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
eff.ini.maxeig.shift.inv.tri
for the tridiagonal matrix
maximal eigenpair by shifted inverse iteration algorithm.
eff.ini.maxeig.general
for the general matrix maximal eigenpair.
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 eff.ini.maxeig.tri(a, b, c, xi = 1)
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 eff.ini.maxeig.tri(a, b, c, xi = 1)
Calculate the next to maximal eigenpair for the general conservative matrix.
eff.ini.seceig.general(Q, z0 = NULL, c1 = 1000, digit.thresh = 6)
eff.ini.seceig.general(Q, z0 = NULL, c1 = 1000, digit.thresh = 6)
Q |
The input general matrix. |
z0 |
The type of initial |
c1 |
A large constant. |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
The conservativity of matrix means that the sums of each row of
matrix
are all 0.
eff.ini.seceig.tri
for the tridiagonal matrix next to the maximal eigenpair.
Q = matrix(c(-30, 1/5, 11/28, 55/3291, 30, -17, 275/42, 330/1097, 0, 84/5, -20, 588/1097, 0, 0, 1097/84, -2809/3291), 4, 4) eff.ini.seceig.general(Q, z0 = 'Auto', digit.thresh = 5) eff.ini.seceig.general(Q, z0 = 'fixed', digit.thresh = 5)
Q = matrix(c(-30, 1/5, 11/28, 55/3291, 30, -17, 275/42, 330/1097, 0, 84/5, -20, 588/1097, 0, 0, 1097/84, -2809/3291), 4, 4) eff.ini.seceig.general(Q, z0 = 'Auto', digit.thresh = 5) eff.ini.seceig.general(Q, z0 = 'fixed', digit.thresh = 5)
Calculate the next to maximal eigenpair for the tridiagonal matrix whose sums of each row should be 0.
eff.ini.seceig.tri(a, b, xi = 1, digit.thresh = 6)
eff.ini.seceig.tri(a, b, xi = 1, digit.thresh = 6)
a |
The lower diagonal vector. |
b |
The upper diagonal vector. |
xi |
The coefficient used in the improved initials to form
the convex combination of |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
The sums of each row of the input tridiagonal matrix should be 0.
eff.ini.seceig.general
for the general conservative matrix next to the maximal eigenpair.
a = c(1:7)^2 b = c(1:7)^2 eff.ini.seceig.tri(a, b, xi = 0) eff.ini.seceig.tri(a, b, xi = 1) eff.ini.seceig.tri(a, b, xi = 2/5)
a = c(1:7)^2 b = c(1:7)^2 eff.ini.seceig.tri(a, b, xi = 0) eff.ini.seceig.tri(a, b, xi = 1) eff.ini.seceig.tri(a, b, xi = 2/5)
The EfficientMaxEigenpair package provides some auxillary functions and
five categories of important functions:
tridiag
, tri.sol
, find_deltak
,
ray.quot.tri
, shift.inv.tri
,
ray.quot.seceig.tri
, ray.quot.general
, ray.quot.seceig.general
,
eff.ini.maxeig.tri
, eff.ini.maxeig.shift.inv.tri
,
eff.ini.maxeig.general
, eff.ini.seceig.tri
and eff.ini.seceig.general
.
tridiag
: generate tridiagonal matrix Q based on three input vectors.
tri.sol
: construct the solution of linear equation (-Q-zI)w=v.
find_deltak
: compute for given vector
and matrix
.
ray.quot.tri
: rayleigh quotient iteration algorithm to computing the maximal eigenpair of
tridiagonal matrix .
shift.inv.tri
: shifted inverse iteration algorithm to computing the maximal eigenpair of
tridiagonal matrix .
ray.quot.seceig.tri
: rayleigh quotient iteration algorithm to computing the next to
maximal eigenpair of tridiagonal matrix .
ray.quot.general
: rayleigh quotient iteration algorithm to computing the maximal eigenpair of
general matrix .
ray.quot.seceig.general
: rayleigh quotient iteration algorithm to computing the next to maximal eigenpair of
general matrix .
eff.ini.maxeig.tri
: calculate the maximal eigenpair for the tridiagonal matrix by
rayleigh quotient iteration algorithm.
eff.ini.maxeig.shift.inv.tri
: calculate the maximal eigenpair for the tridiagonal matrix by
shifted inverse iteration algorithm.
eff.ini.maxeig.general
: calculate the maximal eigenpair for the general matrix.
eff.ini.seceig.tri
: calculate the next to maximal eigenpair for the tridiagonal matrix whose sums of each row should be 0.
eff.ini.seceig.general
: calculate the next to maximal eigenpair for the general conservative matrix.
Compute for given vector
and matrix
.
find_deltak(Q, v)
find_deltak(Q, v)
Q |
The given tridiagonal matrix. |
v |
The column vector on the right hand of equation. |
A list of for given vector
and matrix
.
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) find_deltak(Q, v=rep(1,dim(Q)[1]))
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) find_deltak(Q, v=rep(1,dim(Q)[1]))
Rayleigh quotient iteration algorithm to computing the maximal eigenpair of
general matrix .
ray.quot.general(A, mu, v0_tilde, zstart, digit.thresh = 6)
ray.quot.general(A, mu, v0_tilde, zstart, digit.thresh = 6)
A |
The input matrix to find the maximal eigenpair. |
mu |
A vector. |
v0_tilde |
The unnormalized initial vector |
zstart |
The initial |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) ray.quot.general(A, mu=rep(1,dim(A)[1]), v0_tilde=rep(1,dim(A)[1]), zstart=6, digit.thresh = 6)
A = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) ray.quot.general(A, mu=rep(1,dim(A)[1]), v0_tilde=rep(1,dim(A)[1]), zstart=6, digit.thresh = 6)
Rayleigh quotient iteration algorithm to computing the maximal eigenpair of matrix Q.
ray.quot.seceig.general(Q, mu, v0_tilde, zstart, digit.thresh = 6)
ray.quot.seceig.general(Q, mu, v0_tilde, zstart, digit.thresh = 6)
Q |
The input matrix to find the maximal eigenpair. |
mu |
A vector. |
v0_tilde |
The unnormalized initial vector |
zstart |
The initial |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating sequence of the corresponding eigenvector. |
iter |
The number of iterations. |
Q = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) ray.quot.seceig.general(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
Q = matrix(c(1, 1, 3, 2, 2, 2, 3, 1, 1), 3, 3) ray.quot.seceig.general(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
Rayleigh quotient iteration algorithm to computing the next to maximal eigenpair of tridiagonal matrix Q.
ray.quot.seceig.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
ray.quot.seceig.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
Q |
The input matrix to find the maximal eigenpair. |
mu |
A vector. |
v0_tilde |
The unnormalized initial vector |
zstart |
The initial |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) ray.quot.seceig.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) ray.quot.seceig.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
Rayleigh quotient iteration algorithm to computing the maximal eigenpair of tridiagonal matrix Q.
ray.quot.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
ray.quot.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
Q |
The input matrix to find the maximal eigenpair. |
mu |
A vector. |
v0_tilde |
The unnormalized initial vector |
zstart |
The initial |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) ray.quot.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) ray.quot.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
Shifted inverse iteration algorithm algorithm to computing the maximal eigenpair of
tridiagonal matrix .
shift.inv.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
shift.inv.tri(Q, mu, v0_tilde, zstart, digit.thresh = 6)
Q |
The input matrix to find the maximal eigenpair. |
mu |
A vector. |
v0_tilde |
The unnormalized initial vector |
zstart |
The initial |
digit.thresh |
The precise level of output results. |
A list of eigenpair object are returned, with components ,
and
.
z |
The approximating sequence of the maximal eigenvalue. |
v |
The approximating eigenfunction of the corresponding eigenvector. |
iter |
The number of iterations. |
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) shift.inv.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) shift.inv.tri(Q, mu=rep(1,dim(Q)[1]), v0_tilde=rep(1,dim(Q)[1]), zstart=6, digit.thresh = 6)
Construct the solution of linear equation (-Q-zI)w=v.
tri.sol(Q, z, v)
tri.sol(Q, z, v)
Q |
The given tridiagonal matrix. |
z |
The Rayleigh shift. |
v |
The column vector on the right hand of equation. |
A solution sequence to the equation (-Q-zI)w=v.
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) zstart = 6 Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) tri.sol(Q, z=zstart, v=rep(1,dim(Q)[1]))
a = c(1:7)^2 b = c(1:7)^2 c = rep(0, length(a) + 1) c[length(a) + 1] = 8^2 N = length(a) zstart = 6 Q = tridiag(b, a, -c(b[1] + c[1], a[1:N - 1] + b[2:N] + c[2:N], a[N] + c[N + 1])) tri.sol(Q, z=zstart, v=rep(1,dim(Q)[1]))
Generate tridiagonal matrix Q based on three input vectors.
tridiag(upper, lower, main)
tridiag(upper, lower, main)
upper |
The upper diagonal vector. |
lower |
The lower diagonal vector. |
main |
The main diagonal vector. |
A tridiagonal matrix is returned.
a = c(1:7)^2 b = c(1:7)^2 c = -c(1:8)^2 tridiag(b, a, c)
a = c(1:7)^2 b = c(1:7)^2 c = -c(1:8)^2 tridiag(b, a, c)