Small optimization
This commit is contained in:
parent
42a63d6957
commit
e5346e1ef4
18
EC.jl
18
EC.jl
|
|
@ -66,7 +66,8 @@ end
|
||||||
|
|
||||||
"Extrapolate using a trained EC model for a given range of c values
|
"Extrapolate using a trained EC model for a given range of c values
|
||||||
If a list is provided for ref_eval, they are used as reference values for picking the closest eigenvalues at each point.
|
If a list is provided for ref_eval, they are used as reference values for picking the closest eigenvalues at each point.
|
||||||
If a single number is provided for ref_eval, it is used as a reference for the first point, and the previous eigenvalue is used as the reference for each successive point."
|
If a single number is provided for ref_eval, it is used as a reference for the first point, and the previous eigenvalue is used as the reference for each successive point.
|
||||||
|
If precalculated_exact_E is provided, ref_eval is ignored."
|
||||||
function extrapolate!(EC::affine_EC, c_vals; ref_eval=EC.training_E[end], verbose=true, tol=1e-5, precalculated_exact_E=nothing)
|
function extrapolate!(EC::affine_EC, c_vals; ref_eval=EC.training_E[end], verbose=true, tol=1e-5, precalculated_exact_E=nothing)
|
||||||
@assert EC.trained "EC model must be trained using train() before extrapolation"
|
@assert EC.trained "EC model must be trained using train() before extrapolation"
|
||||||
|
|
||||||
|
|
@ -74,15 +75,17 @@ function extrapolate!(EC::affine_EC, c_vals; ref_eval=EC.training_E[end], verbos
|
||||||
verbose && println("Extact solution for c = $c")
|
verbose && println("Extact solution for c = $c")
|
||||||
|
|
||||||
global current_E
|
global current_E
|
||||||
if ref_eval isa Number
|
|
||||||
current_E = ref_eval
|
|
||||||
ref_eval = nothing
|
|
||||||
elseif !isnothing(ref_eval)
|
|
||||||
current_E = popfirst!(ref_eval)
|
|
||||||
end
|
|
||||||
|
|
||||||
if isnothing(precalculated_exact_E)
|
if isnothing(precalculated_exact_E)
|
||||||
|
if ref_eval isa Number
|
||||||
|
current_E = ref_eval
|
||||||
|
ref_eval = nothing
|
||||||
|
elseif !isnothing(ref_eval)
|
||||||
|
current_E = popfirst!(ref_eval)
|
||||||
|
end
|
||||||
|
|
||||||
verbose && println("Extact solution for c = $c")
|
verbose && println("Extact solution for c = $c")
|
||||||
|
|
||||||
H = EC.H0 + c .* EC.H1
|
H = EC.H0 + c .* EC.H1
|
||||||
evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=tol, ritzvec=false, check=1)
|
evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=tol, ritzvec=false, check=1)
|
||||||
current_E = nearest(evals, current_E)
|
current_E = nearest(evals, current_E)
|
||||||
|
|
@ -95,7 +98,6 @@ function extrapolate!(EC::affine_EC, c_vals; ref_eval=EC.training_E[end], verbos
|
||||||
verbose && println("Extrapolating for c = $c")
|
verbose && println("Extrapolating for c = $c")
|
||||||
|
|
||||||
H_EC = EC.H0_EC + c .* EC.H1_EC
|
H_EC = EC.H0_EC + c .* EC.H1_EC
|
||||||
|
|
||||||
evals = isnothing(EC.N_EC) ? eigvals(H_EC) : eigvals(H_EC, EC.N_EC)
|
evals = isnothing(EC.N_EC) ? eigvals(H_EC) : eigvals(H_EC, EC.N_EC)
|
||||||
push!(EC.extrapolated_E, nearest(evals, current_E))
|
push!(EC.extrapolated_E, nearest(evals, current_E))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue