Skip to content

Commit

Permalink
Remove RQI
Browse files Browse the repository at this point in the history
  • Loading branch information
haampie committed Jul 11, 2017
1 parent 9e435ba commit 8cb858d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 69 deletions.
63 changes: 3 additions & 60 deletions src/simple.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Simple methods
export powm, invpowm, rqi
export powm, invpowm

####################
# API method calls #
Expand Down Expand Up @@ -95,54 +95,6 @@ function invpowm_method!{T}(log::ConvergenceHistory, K::KrylovSubspace{T}, σ::N
σ+1/θ, y/θ
end

####################
# API method calls #
####################

function rqi(A;
x=nothing, shift::Number=0, tol::Real=eps(real(eltype(A)))*size(A,2)^3,
maxiter::Int=size(A,2), plot::Bool=false, log::Bool=false, kwargs...
)
K = KrylovSubspace(A, 1)
x==nothing ? initrand!(K) : init!(K, x/norm(x))

(plot & !log) && error("Can't plot when log keyword is false")
history = ConvergenceHistory(partial=!log)
history[:tol] = tol
reserve!(history,:resnorm, maxiter)
eig, v = rqi_method!(history, K, shift; tol=tol, maxiter=maxiter, kwargs...)
(plot || log) && shrink!(history)
plot && showplot(history)
log ? (eig, v, history) : (eig, v)
end

#########################
# Method Implementation #
#########################

#Rayleigh quotient iteration
#XXX Doesn't work well
function rqi_method!{T}(log::ConvergenceHistory, K::KrylovSubspace{T}, σ::Number;
tol::Real=eps(real(T)), maxiter::Int=K.n, verbose::Bool=false
)
verbose && @printf("=== rqi ===\n%4s\t%7s\n","iter","resnorm")
v = lastvec(K)
ρ = dot(v, nextvec(K))
for iter=1:maxiter
nextiter!(log,mvps=1)
y = (K.A-ρ*eye(K))\v
θ = norm(y)
ρ += dot(y,v)/θ^2
v = y/θ
resnorm=1/θ
push!(log,:resnorm,resnorm)
verbose && @printf("%3d\t%1.2e\n",iter,resnorm)
θ >= 1/tol && (setconv(log, resnorm >= 0); break)
end
verbose && @printf("\n")
ρ, v
end

#################
# Documentation #
#################
Expand All @@ -153,31 +105,23 @@ doc1_call = """ powm(A)
"""
doc2_call = """ invpowm(A)
"""
doc3_call = """ rqi(A)
"""
doc1_msg = """Find biggest eigenvalue of `A` and its associated eigenvector
using the power method.
"""
doc2_msg = """Find closest eigenvalue of `A` to `shift` and its associated eigenvector
using the inverse power iteration method.
"""
doc3_msg = """Try find closest eigenvalue of `A` to `shift` and its associated eigenvector
using the rayleigh quotient iteration method. This method converges rapidly
but is not guaranteed to compute the eigenvalue closes to `shift`.
"""
doc1_karg = ""
doc2_karg = "`shift::Number=0`: shift to be applied to matrix A."
doc3_karg = "`shift::Number=0`: shift to be applied to matrix A."

doc1_version = (powm, doc1_call, doc1_msg, doc1_karg)
doc2_version = (invpowm, doc2_call, doc2_msg, doc2_karg)
doc3_version = (rqi, doc3_call, doc3_msg, doc3_karg)

i=0
docstring = Vector(3)
docstring = Vector(2)

#Build docs
for (func, call, msg, karg) in [doc1_version, doc2_version, doc3_version]
for (func, call, msg, karg) in [doc1_version, doc2_version]
i+=1
docstring[i] = """
$call
Expand Down Expand Up @@ -239,5 +183,4 @@ end

@doc docstring[1] -> powm
@doc docstring[2] -> invpowm
@doc docstring[3] -> rqi
end
3 changes: 0 additions & 3 deletions test/history.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ facts("ConvergenceHistory") do
plot(invpowm(A; log=true)[2])
@fact true --> true

plot(rqi(A; log=true)[2])
@fact true --> true

plot(svdl(A; log=true)[3])
@fact true --> true
end
Expand Down
6 changes: 0 additions & 6 deletions test/simple_eigensolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ for T in (Float32, Float64, Complex64, Complex128)
@fact norm(eval_rand-eval_ii) --> less_than(tol)
end

#context("Rayleigh quotient iteration") do
#XXX broken?
#l = eigvals_rqi(A, eigvals_rand, 2000, √eps())[2]
#@fact norm(eigvals_rand-l) --> less_than(tol)
#end

end
end
end

0 comments on commit 8cb858d

Please sign in to comment.