Compare commits

..

12 Commits
main ... pmm/k

Author SHA1 Message Date
Nuwan Yapa 5bd6f70eeb Adjust GIF axes 2025-04-30 02:51:20 -05:00
Nuwan Yapa 336a6a1020 Major bug fix 2025-04-30 01:05:53 -05:00
Nuwan Yapa b30ee6e1fb Bugfix related to c0 2025-04-30 00:47:22 -05:00
Nuwan Yapa 56497d6fbf Adam optimizer 2025-04-29 23:25:54 -05:00
Nuwan Yapa c1eb71c231 Better constraint virtual state 2025-04-29 20:55:50 -05:00
Nuwan Yapa a761c6d0de Train for virtual trajectory 2025-04-29 20:30:36 -05:00
Nuwan Yapa e68370cf7d Revered animation 2025-04-28 18:54:44 -05:00
Nuwan Yapa 7e7e1a4185 GIF of extrapolation 2025-04-28 18:49:06 -05:00
Nuwan Yapa 8d3cbe5f4d Enforce EP 2025-04-27 21:32:27 -04:00
Nuwan Yapa 66701bab38 Adjust parameters 2025-04-27 21:00:01 -04:00
Nuwan Yapa b2c2b80a83 Merge branch 'main' into pmm/k 2025-04-27 20:43:21 -04:00
Nuwan Yapa ae5b4ecea8 Emulate k instead of E 2025-04-27 17:42:37 -04:00
10 changed files with 212 additions and 339 deletions

6
EC.jl
View File

@ -156,11 +156,11 @@ exportCSV(EC::affine_EC, filename) = exportCSV(filename, (EC.training_E, EC.exac
"Plot EC data and optionally save figure to a file"
function plot(EC::affine_EC, save_fig_filename=nothing; basis_points=nothing, basis_contour=nothing, xlims=nothing, ylims=nothing)
scatter(real.(EC.training_E), imag.(EC.training_E), label="training")
scatter!(real.(EC.exact_E), imag.(EC.exact_E), label="exact", markercolor=:white)
scatter!(real.(EC.exact_E), imag.(EC.exact_E), label="exact")
if EC.ensemble_size > 0
scatter!(real.(EC.extrapolated_E), imag.(EC.extrapolated_E), xerror=real.(EC.extrapolated_CI), yerror=imag.(EC.extrapolated_CI), label="extrapolated", m=:x)
scatter!(real.(EC.extrapolated_E), imag.(EC.extrapolated_E), xerror=real.(EC.extrapolated_CI), yerror=imag.(EC.extrapolated_CI), label="extrapolated")
else
scatter!(real.(EC.extrapolated_E), imag.(EC.extrapolated_E), label="extrapolated", m=:x)
scatter!(real.(EC.extrapolated_E), imag.(EC.extrapolated_E), label="extrapolated")
end
isnothing(basis_points) || scatter!(real.(basis_points), imag.(basis_points), m=:x, label="basis")

View File

@ -1,68 +0,0 @@
using Roots, LinearAlgebra, Plots
include("../EC.jl")
include("../common.jl")
include("../ho_basis.jl")
V_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
Λ = 0
m = 1.0
ϕ = 0.1
μω_global = 0.5 * exp(-2im * ϕ)
E_max = 40
H0 = get_3b_H_matrix(jacobi, V_of_r, μω_global, E_max, Λ, m, true, true)
# Vp = perturbation to make the state artificially bound
Vp_of_r(r) = -exp(-(r/3)^2)
@time "Vp" Vp = get_3b_H_matrix(jacobi, Vp_of_r, μω_global, E_max, Λ, m, false, true)
training_ref = -2.22
extrapolating_ref = [4.076662025307587-0.012709842443350328im,
3.613318119833891-0.007335804709990623im,
3.1453431847006783-0.004030580410326795im,
2.672967129943755-0.00211498327461944im,
2.196542557810288-0.0010719835443437104im,
1.7164583929199813-0.0005455212208182736im,
1.233088227541505-0.0003070320106485624im]
training_c = range(2.8, 1.8, 5)
extrapolating_c = 0.0 : 0.2 : 1.2
EC = affine_EC(H0, Vp)
train!(EC, training_c; ref_eval=training_ref, CAEC=true)
extrapolate!(EC, extrapolating_c; ref_eval=extrapolating_ref)
# determining c0 with EC
approx_c0 = 1.5
quick_extrapolate(c) = minimum(abs2, get_extrapolated_evals(EC.H0_EC, EC.H1_EC, EC.N_EC, c, 1e-14))
c0 = find_zero(quick_extrapolate, approx_c0)
order::Int = ceil((length(training_c) - 1) / 2) # order of the Pade approximant
# Solve coefficients as a linear system
training_k = alt_sqrt.(EC.training_E)
M_left_element(c, i) = alt_sqrt(c - c0)^i
M_left = M_left_element.(training_c, (0:order)')
M_right = -training_k .* M_left[:, 2:end] # remove the first column
M = hcat(M_left, M_right) # M = [M_left | M_right]
sol = M \ training_k
a = sol[1:order+1]
b = [1; sol[order+2:end]]
# Pade approximant
polynomial(a, c) = sum(i -> a[i+1] * alt_sqrt(c - c0)^i, 0:order)
pade_approx(c) = polynomial(a, c) / polynomial(b, c)
# Extrapolate
extrapolated_k = pade_approx.([extrapolating_c; training_c])
extrapolated_E = extrapolated_k .^ 2
# Plotting
scatter(real.(EC.training_E), imag.(EC.training_E), label="training")
scatter!(real.(EC.exact_E), imag.(EC.exact_E), label="exact")
scatter!(real.(EC.extrapolated_E), imag.(EC.extrapolated_E), label="CAEC", m=:x)
scatter!(real.(extrapolated_E), imag.(extrapolated_E), label="ACCC", m=:+)
title!("3-body extrapolation with $(length(training_c)) training points")
savefig("temp/3body_HO_B2R_ACCC-$(length(training_c)).pdf")

71
calculations/PMM.jl Normal file
View File

@ -0,0 +1,71 @@
using LinearAlgebra, Random, Plots
include("../p_space.jl")
μ = 0.5
V_system(c) = (p, q) -> c*(-5*g0(sqrt(3), p, q) + 2*g0(sqrt(10), p, q)) # ResonanceEC: Eq. (20)
training_c = range(1.2, 0.9, 9) # original: range(1.35, 0.9, 5)
extrapolating_c = range(0.78, 0.45, 7) # original: range(0.75, 0.40, 8)
# calculate training data
data_c = training_c
data_E = [quick_pole_E(V_system(c)) for c in data_c]
# hyperparameters
N = 9
# initialize random Hamiltonians
H0 = randn(ComplexF64, N, N)
H0 = H0 + transpose(H0) # symmetric
H1 = randn(ComplexF64, N, N)
H1 = H1 + transpose(H1) # symmetric
# training
Es = ComplexF64[]
ψs = Vector{ComplexF64}[]
lr = 0.05
epochs = 100000
for epoch in 1:epochs
empty!(Es)
empty!(ψs)
for (c, E) in zip(data_c, data_E)
H = H0 + c * H1
evals, evecs = eigen(H)
i = nearestIndex(evals, E) # TODO: more robust way to identify the eigenvector
push!(Es, evals[i])
push!(ψs, evecs[:, i])
end
if epoch % 1000 == 0
loss = sum(abs2, Es .- data_E)
println("Epoch:$epoch/$epochs \t Loss: $loss")
end
# gradient of the loss function
function grad(c_order=0)
out = zeros(ComplexF64, N, N)
for (c, E_target, ψ, E) in zip(data_c, data_E, ψs, Es)
out .+= (c^c_order * conj(E - E_target)) .* (ψ * transpose(ψ))
end
return 2 .* real.(out)
end
H0 .-= lr .* grad(0) # update H0
H1 .-= lr .* grad(1) # update H1
end
# evaluate for all points
all_c = vcat(training_c, extrapolating_c)
exact_E = [quick_pole_E(V_system(c)) for c in all_c]
extrapolated_E = ComplexF64[]
for (c, ref) in zip(all_c, exact_E)
H = H0 + c * H1
evals, evecs = eigen(H)
evals = vcat(evals, conj.(evals)) # include complex conjugates
push!(extrapolated_E, nearest(evals, ref))
end
# plot results
scatter(real.(data_E), imag.(data_E), label="training", title="PMM", xlabel="Re E", ylabel="Im E")
scatter!(real.(exact_E), imag.(exact_E), label="exact", m=:+)
scatter!(real.(extrapolated_E), imag.(extrapolated_E), label="predicted", m=:x)

View File

@ -5,16 +5,23 @@ import numpy as np
#%%
df = pd.read_csv('../temp/2body_data.csv').sort_values(by='c')
df.loc[df['re_E'] < 0, 'im_E'] = 0 # set im_E = 0 for bound states (to avoid square root issues)
df['E'] = df['re_E'] + 1j * df['im_E']
df['k'] = np.sqrt(df['E'])
c0 = df[df['E'] == 0]['c'].values[0]
df = df[df['c'] != c0] # remove the threshold point
df['c'] = df['c'] - c0 # shift c to set c=0 at the exceptional point
train_data = df[df['re_E'] < 0]
target_data = df[df['re_E'] > 0]
train_cs = train_data['c'].to_numpy()
train_Es = torch.tensor(train_data['E'].to_numpy(), dtype=torch.complex128)
train_ks = torch.tensor(train_data['k'].to_numpy(), dtype=torch.complex128)
#%%
# hyperparameters
N = 9
N = 5
# initialize random Hamiltonians
H0 = torch.randn(N, N, dtype=torch.complex128)
@ -22,60 +29,134 @@ H0 = (H0 + torch.transpose(H0, 0, 1)).requires_grad_() # symmetric
H1 = torch.randn(N, N, dtype=torch.complex128)
H1 = (H1 + torch.transpose(H1, 0, 1)).requires_grad_() # symmetric
def enforce_ep(): # enforce exceptional point at c=0
with torch.no_grad():
H0[0:2, :] = 0
H0[:, 0:2] = 0
H0[0, 1] = 1
enforce_ep()
#%%
# training
# generate a set of c values to follow by subdividing the training cs
subdivisions = 3
c_steps = np.concatenate([np.linspace(start, stop, subdivisions, endpoint=False) for (start, stop) in zip(train_cs, train_cs[1:])])
subdivisions = 2
c_steps = np.concatenate([np.linspace(start, stop, subdivisions, endpoint=False) for (start, stop) in zip(np.insert(train_cs, 0, 0), train_cs)])
c_steps = np.append(c_steps, train_cs[-1])
c_steps = np.delete(c_steps, 0) # remove the first point (c=0)
lr = 0.05
epochs = 100000
# Initialize the Adam optimizer
optimizer = torch.optim.Adam([H0, H1])
# Training loop
epochs = 50000
for epoch in range(epochs):
Es = torch.empty(len(train_data), dtype=torch.complex128)
current_E = 0.0 # start at the threshold
ks = torch.empty(len(train_data), dtype=torch.complex128)
kvs = torch.empty(len(train_data), dtype=torch.complex128)
current_k = 0.0 # start at the threshold
current_kv = 0.0 # start at the threshold
for c in c_steps:
H = H0 + c * H1
evals = torch.linalg.eigvals(H)
current_E = evals[torch.argmin(torch.abs(evals - current_E))]
current_k = evals[torch.argmin(torch.abs(evals - current_k))]
evals = evals[evals != current_k] # remove selected k
current_kv = evals[torch.argmin(torch.abs(evals - current_kv))]
if np.any(c == train_cs):
index = np.where(c == train_cs)[0][0]
Es[index] = current_E
ks[index] = current_k
kvs[index] = current_kv
loss = ((Es - train_Es).abs() ** 2).sum()
loss = ((ks - train_ks).abs() ** 2).sum()
# push virtual states towards (-)bound and then to the imaginary axis
if epoch/epochs < 0.75:
loss += ((kvs + train_ks).abs() ** 2).sum()
else:
loss += (kvs.real ** 2).sum()
if epoch % 1000 == 0:
print(f"Training {(epoch+1)/epochs:.1%} \t Loss: {loss}")
if H0.grad is not None:
H0.grad.zero_()
if H1.grad is not None:
H1.grad.zero_()
# Zero gradients, backpropagate, and update parameters
optimizer.zero_grad()
loss.backward()
optimizer.step()
with torch.no_grad():
H0 -= lr * H0.grad
H1 -= lr * H1.grad
# Enforce exceptional point constraints
enforce_ep()
# %%
# evaluate for all points
all_c = torch.tensor(df['c'].values, dtype=torch.float64)
exact_E = torch.tensor(df['E'].values, dtype=torch.complex128)
pred_Es = torch.empty(len(df), dtype=torch.complex128)
exact_k = torch.tensor(df['k'].values, dtype=torch.complex128)
pred_ks = np.empty(len(df), dtype=np.complex128)
with torch.no_grad():
for (index, (c, E)) in enumerate(zip(all_c, exact_E)):
for (index, (c, k)) in enumerate(zip(all_c, exact_k)):
H = H0 + c * H1
evals = torch.linalg.eigvals(H)
i = torch.argmin(torch.abs(evals - E)) # TODO: more robust way to identify the eigenvector
pred_Es[index]= evals[i]
i = torch.argmin(torch.abs(evals - k)) # TODO: more robust way to identify the eigenvector
pred_ks[index]= evals[i]
pred_Es = pred_ks ** 2
# %%
# plot the results
import matplotlib.pyplot as plt
plt.scatter(train_data['re_E'], train_data['im_E'], label='training')
plt.scatter(target_data['re_E'], target_data['im_E'], label='target')
plt.scatter(pred_Es.real, pred_Es.imag, marker='x', label='predicted')
plt.legend()
fig, axs = plt.subplots(2, 1, figsize=(8, 12)) # Create a figure with two vertical panels
# First panel: k values
axs[0].scatter(np.real(train_data['k']), np.imag(train_data['k']), label='training')
axs[0].scatter(np.real(target_data['k']), np.imag(target_data['k']), label='target')
axs[0].scatter(np.real(pred_ks), np.imag(pred_ks), marker='x', label='predicted')
axs[0].set_xlabel('Re(k)')
axs[0].set_ylabel('Im(k)')
axs[0].legend()
# Second panel: E values
axs[1].scatter(np.real(train_data['E']), np.imag(train_data['E']), label='training')
axs[1].scatter(np.real(target_data['E']), np.imag(target_data['E']), label='target')
axs[1].scatter(np.real(pred_Es), np.imag(pred_Es), marker='x', label='predicted')
axs[1].set_xlabel('Re(E)')
axs[1].set_ylabel('Im(E)')
axs[1].legend()
plt.tight_layout() # Adjust spacing between panels
plt.show()
# %%
# animation of eigenvalues
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# Prepare figure
fig, ax = plt.subplots(figsize=(8, 8))
ax.scatter(np.real(train_data['k']), np.imag(train_data['k']), label='training')
ax.scatter(np.real(target_data['k']), np.imag(target_data['k']), label='target')
sc = ax.scatter([], [], marker='x', label='predicted') # Placeholder for predicted eigenvalues
ax.set_xlim(-0.6, 0.6) # Adjust limits as needed
ax.set_ylim(-0.75, 0.75) # Adjust limits as needed
ax.set_xlabel('Re(k)')
ax.set_ylabel('Im(k)')
ax.legend()
ax.set_title('c = ?')
# Animation function
def update(c):
H = H0 + c * H1
evals = torch.linalg.eigvals(H).detach().numpy()
sc.set_offsets(np.c_[np.real(evals), np.imag(evals)])
ax.set_title(f'c = {c:.2f}')
return sc,
# Create animation
no_frames = 100
c_steps = np.linspace(max(df['c']), min(df['c']), no_frames)
ani = FuncAnimation(fig, update, frames=c_steps, interval=100, blit=True)
# Save or display the animation
ani.save('../temp/PMM.gif', writer='pillow') # Save as a GIF file
plt.show() # Display the animation
# %%

View File

@ -1,39 +0,0 @@
using Plots
include("../../EC.jl")
include("../../ho_basis.jl")
include("../../p_space.jl")
angle = 0.25 * pi # DOESN'T WORK WITHOUT ROTATION
μω_gen = 0.5 * exp(-2im * angle)
μ = 0.5
l = 0
V1 = -5
R1 = sqrt(3)
V2 = 2
R2 = sqrt(10)
n_max = 15
ns = collect(0:n_max)
ls = fill(l, n_max + 1)
T = get_sp_T_matrix(ns, ls; μω_gen=μω_gen, μ=μ)
V = V1 .* V_Gaussian.(R1, l, ns, transpose(ns); μω_gen=μω_gen) + V2 .* V_Gaussian.(R2, l, ns, transpose(ns); μω_gen=μω_gen)
n_EC = 8
train_cs = (0.7 .+ 0.05 * randn(n_EC)) - 1im * (0.2 .+ 0.05 * randn(n_EC))
target_cs = [0.5]
near_E = 0.2 + 0.2im
exact_E = [0.20845136860234303 - 0.07100640993695649im]
EC = affine_EC(T, V; ensemble_size=32)
train!(EC, train_cs; ref_eval=near_E, CAEC=false)
extrapolate!(EC, target_cs; precalculated_exact_E=exact_E)
plot(EC; xlims=(0,0.3), ylims=(-0.3,0.3))
hline!([0], color=:red, label="continuum")
xlabel!("Re(E)")
ylabel!("Im(E)")
plot!(legend=:bottomleft)
savefig("temp/2b_HO_XZ.pdf")

View File

@ -1,50 +0,0 @@
using Plots
include("../../EC.jl")
include("../../ho_basis.jl")
include("../../p_space.jl")
# paramters of the system
angle = 0.0
μ = 0.5
l = 0
V1 = -5
R1 = sqrt(3)
V2 = 2
R2 = sqrt(10)
n_EC = 8
train_cs = (0.7 .+ 0.03 * randn(n_EC)) - 1im * (0.2 .+ 0.03 * randn(n_EC))
near_E = 0.2 + 0.2im
target_c = 0.5
exact_E = 0.20845136860234303 - 0.07100640993695649im
vertices = [0, 4 * exp(-1im * angle)]
subdivisions = [256]
ks, ws = get_mesh(vertices, subdivisions)
V_of_r(r) = V1 * exp(-r^2 / R1^2) + V2 * exp(-r^2 / R2^2)
V_mat_elem(k, kp) = Vl_mat_elem(V_of_r, l, k, kp; atol=10^-5, maxevals=10^5, R_cutoff=16)
V = get_V_matrix(V_mat_elem, ks, ws)
T = get_T_matrix(ks, μ)
EC_p_space = affine_EC(T, V)
train!(EC_p_space, train_cs; ref_eval=near_E, CAEC=false)
extrapolate!(EC_p_space, [target_c]; precalculated_exact_E=[exact_E])
# Plotting
theme(:dark) # Set the global theme to dark
scatter([real(exact_E)], [imag(exact_E)], label="exact", marker=:circle, markercolor=:white, bg = :black) # black background
scatter!(real.(EC_p_space.training_E), imag.(EC_p_space.training_E), label="training", marker=:circle, color=:blue)
scatter!(real.(EC_p_space.extrapolated_E), imag.(EC_p_space.extrapolated_E), label="extrapolated", marker=:x, color=:green)
hline!([0], color=:red, label="continuum")
plot!(legend=:bottomleft)
xlabel!("Re(E)")
ylabel!("Im(E)")
xlims!(0, 0.3)
ylims!(-0.3, 0.3)
savefig("temp/2body_p_space.pdf")

View File

@ -1,36 +0,0 @@
include("../../ho_basis.jl")
include("../../EC.jl")
V_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
Λ = 0
m = 1.0
ϕ = 0.1 # DOESN'T WORK WITHOUT ROTATION
μω_global = 0.5 * exp(-2im * ϕ)
E_max = 40
H0 = get_3b_H_matrix(jacobi, V_of_r, μω_global, E_max, Λ, m, true, true)
# Vp = perturbation to make the state artificially bound
Vp_of_r(r) = -exp(-(r/3)^2)
@time "Vp" Vp = get_3b_H_matrix(jacobi, Vp_of_r, μω_global, E_max, Λ, m, false, true)
training_ref = 2 + 0.5im
exact_E = [4.076642792419057-0.012998408352259658im,
3.6129849325287-0.007397677539402868im,
3.145212908643357-0.0038660337822150753im,
2.6729225739451596-0.0021090370393881063im,
2.196385760253282-0.0010430088245526555im,
1.7162659936896967-0.0004515351140200029,
1.2329926791785895-0.00017698044022813525im]
training_c = [0.6 - 0.16im] .+ 0.04 .* (randn(8) .+ 0.5im * randn(8))
extrapolating_c = 0.0 : 0.2 : 1.2
EC = affine_EC(H0, Vp)
train!(EC, training_c; ref_eval=training_ref, CAEC=false)
extrapolate!(EC, extrapolating_c; precalculated_exact_E=exact_E)
exportCSV(EC, "temp/3b_HO_XZ.csv")
plot(EC, "temp/3b_HO_XZ.pdf")

View File

@ -1,45 +0,0 @@
include("../../p_space.jl")
include("../../EC.jl")
using Arpack
# target = 4.0766890719636875 - 0.012758927741074495im
Λ = 0
m = 1.0
V_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
vertices = [0, 2 - 0.2im, 3, 4] # TODO: real contour instead of Berggren basis
subdivisions = [15, 10, 10]
jmax = 4
E_max = 40
μω_global = 0.5
@time "H0" H0, _ = get_3b_H_matrix(jacobi, V_of_r, vertices, subdivisions, jmax, μω_global, E_max, Λ, m, true, true)
# Vp = perturbation to make the state artificially bound
Vp_of_r(r) = -exp(-(r/3)^2)
@time "Vp" Vp, _ = get_3b_H_matrix(jacobi, Vp_of_r, vertices, subdivisions, jmax, μω_global, E_max, Λ, m, false, true)
training_ref = 2 + 0.5im
exact_E = [4.076642792419057-0.012998408352259658im,
3.6129849325287-0.007397677539402868im,
3.145212908643357-0.0038660337822150753im,
2.6729225739451596-0.0021090370393881063im,
2.196385760253282-0.0010430088245526555im,
1.7162659936896967-0.0004515351140200029,
1.2329926791785895-0.00017698044022813525im]
training_c = [-1.5 - 0.5im] .+ (randn(8) .+ 0.05im * randn(8))
extrapolating_c = 0.0 : 0.2 : 1.2
EC = affine_EC(H0, Vp)
train!(EC, training_c; ref_eval=training_ref, CAEC=false)
extrapolate!(EC, extrapolating_c; precalculated_exact_E=exact_E)
exportCSV(EC, "temp/3b_p_space_XZ.csv")
plot(EC, "temp/3b_p_space_XZ.pdf")
# Results: training points are all over the place, and extrapolated values are garbage.

View File

@ -1,71 +0,0 @@
using Plots
include("../../EC.jl")
include("../../ho_basis.jl")
include("../../p_space.jl")
# paramters of the system
angle = 0.0 * pi
μ = 0.5
l = 0
V1 = -5
R1 = sqrt(3)
V2 = 2
R2 = sqrt(10)
n_EC = 8
train_cs = (0.7 .+ 0.03 * randn(n_EC)) - 1im * (0.2 .+ 0.03 * randn(n_EC))
near_E = 0.2 + 0.2im
target_c = 0.5
exact_E = 0.20845136860234303 - 0.07100640993695649im
# HO basis
global EC_HO
begin
println("HO basis calculation")
μω_gen = 0.5 * exp(-1im * angle)
n_max = 40
ns = collect(0:n_max)
ls = fill(l, n_max + 1)
T = get_sp_T_matrix(ns, ls; μω_gen=μω_gen, μ=μ)
V = V1 .* V_Gaussian.(R1, l, ns, transpose(ns); μω_gen=μω_gen) + V2 .* V_Gaussian.(R2, l, ns, transpose(ns); μω_gen=μω_gen)
global EC_HO = affine_EC(T, V)
train!(EC_HO, train_cs; ref_eval=near_E, CAEC=false)
extrapolate!(EC_HO, [target_c]; precalculated_exact_E=[exact_E])
end
# p-space
global EC_p_space
begin
println("p-space calculation")
vertices = [0, 4 * exp(-1im * angle)]
subdivisions = [256]
ks, ws = get_mesh(vertices, subdivisions)
V_of_r(r) = V1 * exp(-r^2 / R1^2) + V2 * exp(-r^2 / R2^2)
V_mat_elem(k, kp) = Vl_mat_elem(V_of_r, l, k, kp; atol=10^-5, maxevals=10^5, R_cutoff=16)
V = get_V_matrix(V_mat_elem, ks, ws)
T = get_T_matrix(ks, μ)
global EC_p_space = affine_EC(T, V)
train!(EC_p_space, train_cs; ref_eval=near_E, CAEC=false)
extrapolate!(EC_p_space, [target_c]; precalculated_exact_E=[exact_E])
end
# Plotting
scatter([real(exact_E)], [imag(exact_E)], label="Exact", marker=:circle, markercolor=:white)
scatter!(real.(EC_HO.training_E), imag.(EC_HO.training_E), label="HO basis training", marker=:circle, color=:blue)
scatter!(real.(EC_HO.extrapolated_E), imag.(EC_HO.extrapolated_E), label="HO basis extrapolated", marker=:x, color=:blue)
scatter!(real.(EC_p_space.training_E), imag.(EC_p_space.training_E), label="p-space training", marker=:circle, color=:red)
scatter!(real.(EC_p_space.extrapolated_E), imag.(EC_p_space.extrapolated_E), label="p-space extrapolated", marker=:x, color=:red)
plot!(legend=:bottomleft)
xlabel!("Re(E)")
ylabel!("Im(E)")
savefig("temp/2b_p_space_vs_HO.pdf")

View File

@ -0,0 +1,30 @@
include("../EC.jl")
include("../ho_basis.jl")
include("../p_space.jl")
μω_gen = 0.5 * exp(-1im * 0.47 * pi)
μ = 0.5
l = 0
V1 = -5
R1 = sqrt(3)
V2 = 2
R2 = sqrt(10)
n_max = 15
ns = collect(0:n_max)
ls = fill(l, n_max + 1)
T = get_sp_T_matrix(ns, ls; μω_gen=μω_gen, μ=μ)
V = V1 .* V_Gaussian.(R1, l, ns, transpose(ns); μω_gen=μω_gen) + V2 .* V_Gaussian.(R2, l, ns, transpose(ns); μω_gen=μω_gen)
n_EC = 8
train_cs = (0.7 .+ 0.05 * randn(n_EC)) - 1im * (0.2 .+ 0.05 * randn(n_EC))
target_cs = range(0.77, 0.22, 6)
near_E = 0.2 + 0.2im
EC = affine_EC(T, V)
train!(EC, train_cs; ref_eval=near_E, CAEC=false)
extrapolate!(EC, target_cs)
plot(EC, "temp/XZ.pdf"; xlims=(-0.2,0.3), ylims=(-0.3,0.3))