From 027d5a3e3f825e12a1dae9491177e7551c7f3049 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Thu, 16 Jan 2025 08:57:20 -0500 Subject: [PATCH] Optimized and reorganized Moore-Penrose --- EC.jl | 11 ++++++----- calculations/3body_Berggren_B2R_EC.jl | 2 +- calculations/3body_CSM_B2R_EC.jl | 2 +- calculations/3body_HO_B2R_EC.jl | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/EC.jl b/EC.jl index 9f26375..01797ed 100644 --- a/EC.jl +++ b/EC.jl @@ -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 diff --git a/calculations/3body_Berggren_B2R_EC.jl b/calculations/3body_Berggren_B2R_EC.jl index aceb0cb..263130d 100644 --- a/calculations/3body_Berggren_B2R_EC.jl +++ b/calculations/3body_Berggren_B2R_EC.jl @@ -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") diff --git a/calculations/3body_CSM_B2R_EC.jl b/calculations/3body_CSM_B2R_EC.jl index 7bf0978..8e34f6d 100644 --- a/calculations/3body_CSM_B2R_EC.jl +++ b/calculations/3body_CSM_B2R_EC.jl @@ -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") diff --git a/calculations/3body_HO_B2R_EC.jl b/calculations/3body_HO_B2R_EC.jl index 9d8c988..ee52f80 100644 --- a/calculations/3body_HO_B2R_EC.jl +++ b/calculations/3body_HO_B2R_EC.jl @@ -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")