Seperate Julia file for exporting PMM data

This commit is contained in:
Nuwan Yapa 2025-04-26 21:11:49 -04:00
parent b68887e822
commit 65d0f44b69
3 changed files with 38 additions and 11 deletions

View File

@ -0,0 +1,33 @@
using Roots, DelimitedFiles
include("../EC.jl")
include("../common.jl")
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)
# determining c0 with EC
temp_c = range(1.1, 0.9, 3)
p, w = get_mesh([0, 8], [256])
H0 = get_T_matrix(p, μ)
V = get_V_matrix(V_system(1), p, w)
EC = affine_EC(H0, V, w)
train!(EC, temp_c; ref_eval=-0.2, CAEC=false, verbose=false)
quick_extrapolate(c) = minimum(abs2, get_extrapolated_evals(EC.H0_EC, EC.H1_EC, EC.N_EC, c, 0))
c0 = find_zero(quick_extrapolate, 0.85)
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)
data_c = vcat(training_c, extrapolating_c)
data_E = [quick_pole_E(V_system(c)) for c in data_c]
# export to CSV
file = "temp/2body_data.csv"
delim = ','
open(file, "w") do f
writedlm(f, ["c" "re_E" "im_E"], delim)
writedlm(f, [c0 0 0], delim) # first entry for the threshold
writedlm(f, hcat(data_c, real.(data_E), imag.(data_E)), delim)
end

View File

@ -69,9 +69,3 @@ end
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)
# export results
using DataFrames, CSV
df = DataFrame(c=all_c, re_E=real.(exact_E), im_E=imag.(exact_E))
#pushfirst!(df, (c0, 0, 0)) # add the threshold
CSV.write("temp/PMM.csv", df)

View File

@ -3,13 +3,13 @@ import pandas as pd
import torch
#%%
df = pd.read_csv('../temp/PMM.csv')
df = pd.read_csv('../temp/2body_data.csv')
df['E'] = df['re_E'] + 1j * df['im_E']
train_data = df[abs(df['im_E']) < 1e-5]
target_data = df[abs(df['im_E']) > 1e-5]
train_data = df[df['re_E'] < 0]
target_data = df[df['re_E'] > 0]
train_cs = torch.tensor(train_data['c'], dtype=torch.float64)
train_Es = torch.tensor(train_data['E'], dtype=torch.complex128)
train_cs = torch.tensor(train_data['c'].to_numpy(), dtype=torch.float64)
train_Es = torch.tensor(train_data['E'].to_numpy(), dtype=torch.complex128)
#%%
# hyperparameters