Optimized and reorganized Moore-Penrose

This commit is contained in:
Nuwan Yapa 2025-01-16 08:57:20 -05:00
parent 14b7671f6a
commit 027d5a3e3f
4 changed files with 9 additions and 8 deletions

11
EC.jl
View File

@ -22,8 +22,10 @@ end
"Train an 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 sampling 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.
Set orthonormalize_threshold=0 to skip Gram-Schmidt orthonormalization and use GEVP. Otherwise this value is used as the threshold for dropping redundant vectors."
function train!(EC::affine_EC, c_vals; ref_eval=-10.0, orthonormalize_threshold=1e-5, CAEC=false, verbose=true, tol=1e-5, pseudo_inv_rtol=0)
If pseudo_inv_rtol > 0, the GEVP is avoided using Moore-Penrose psuedoinverse, using this value as the relative tolerance for dropping redundant vectors.
If orthonormalize_threshold > 0, Gram-Schmidt orthonormalization is performed, overriding Moore-Penrose, using this value as the threshold for dropping redundant vectors.
If both are = 0, GEVP is solved instead."
function train!(EC::affine_EC, c_vals; ref_eval=-10.0, pseudo_inv_rtol=1e-6, orthonormalize_threshold=0, CAEC=false, verbose=true, tol=1e-5)
training_vecs = Vector{ComplexF64}[]
for c in c_vals
@ -61,9 +63,8 @@ function train!(EC::affine_EC, c_vals; ref_eval=-10.0, orthonormalize_threshold=
EC.N_EC = transpose(EC_basis) * weights_mat * EC_basis
if pseudo_inv_rtol > 0
inv_N_EC = pinv(EC.N_EC; rtol=pseudo_inv_rtol)
@time "Square root of N" sqrt_inv_N_EC = sqrt(inv_N_EC)
EC.H0_EC = sqrt_inv_N_EC * EC.H0_EC * sqrt_inv_N_EC
EC.H1_EC = sqrt_inv_N_EC * EC.H1_EC * sqrt_inv_N_EC
EC.H0_EC = inv_N_EC * EC.H0_EC
EC.H1_EC = inv_N_EC * EC.H1_EC
EC.N_EC = nothing
end
end

View File

@ -32,7 +32,7 @@ extrapolating_ref = [4.076662025307587-0.012709842443350328im,
1.233088227541505-0.0003070320106485624im]
EC = affine_EC(H0, Vp, weights)
train!(EC, training_c; ref_eval=training_ref, CAEC=true, orthonormalize_threshold=0, pseudo_inv_rtol=1e-6)
train!(EC, training_c; ref_eval=training_ref, CAEC=true)
extrapolate!(EC, extrapolating_c; ref_eval=extrapolating_ref)
exportCSV(EC, "temp/Berggren_B2R.csv")

View File

@ -32,7 +32,7 @@ exact_E = [4.077092809998592-0.01206085331850782im,
1.2329696647679096-0.00019879325231064393im]
EC = affine_EC(H0, Vp, weights)
train!(EC, training_c; ref_eval=training_ref, CAEC=true, orthonormalize_threshold=0, pseudo_inv_rtol=1e-6)
train!(EC, training_c; ref_eval=training_ref, CAEC=true)
extrapolate!(EC, extrapolating_c; precalculated_exact_E=exact_E)
exportCSV(EC, "temp/CSM_B2R.csv")

View File

@ -21,7 +21,7 @@ training_c = [2.0, 1.9, 1.8]
extrapolating_c = 0.0 : 0.2 : 1.2
EC = affine_EC(H0, Vp)
train!(EC, training_c; ref_eval=training_ref, CAEC=true, orthonormalize_threshold=0, pseudo_inv_rtol=1e-6)
train!(EC, training_c; ref_eval=training_ref, CAEC=true)
extrapolate!(EC, extrapolating_c; ref_eval=extrapolating_ref)
exportCSV(EC, "temp/HO_B2R.csv")