Skip to content

Commit

Permalink
Improvements in loss function and plots in hyperparameter optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuellujan committed Jun 27, 2024
1 parent b85d784 commit 1bdc6be
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/Opt-ACE-aHfO2/fit-opt-ace-ahfo2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pars = OrderedDict( :body_order => [2, 3, 4],
# Use random sampling to find the optimal hyper-parameters.
iap, res = hyperlearn!(model, pars, conf_train;
n_samples = 10, sampler = RandomSampler(),
ws = [1.0, 1.0], int = true)
loss = loss, ws = [1.0, 1.0], int = true)

# Save and show results.
@save_var res_path iap.β
Expand Down
37 changes: 2 additions & 35 deletions examples/Opt-ACE-aHfO2/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,6 @@ function get_results(ho)
return sort!(results)
end

# Plot fitting error vs force time (Pareto front)
function plot_err_time(res)
e_mae = res[!, :e_mae]
f_mae = res[!, :f_mae]
times = res[!, :time_us]
plot(times,
e_mae,
seriestype = :scatter,
alpha = 0.55,
thickness_scaling = 1.35,
markersize = 3,
markerstrokewidth = 1,
markerstrokecolor = :black,
markershape = :circle,
markercolor = :gray,
label = "MAE(E_Pred, E_DFT)")
plot!(times,
f_mae,
seriestype = :scatter,
alpha = 0.55,
thickness_scaling = 1.35,
markersize = 3,
markerstrokewidth = 1,
markerstrokecolor = :red,
markershape = :utriangle,
markercolor = :red2,
label = "MAE(F_Pred, F_DFT)")
plot!(dpi = 300,
label = "",
xlabel = "Time per force per atom | µs",
ylabel = "MAE")
end


function get_species(confs)
return unique(vcat(unique.(atomic_symbol.(get_system.(confs)))...))
Expand All @@ -68,8 +35,8 @@ create_ho(x) = Hyperoptimizer(1)

# hyperlearn!
function hyperlearn!(model, pars, conf_train;
n_samples = 5, sampler = RandomSampler(), loss = loss,
ws = [1.0, 1.0], int = true)
n_samples = 5, sampler = RandomSampler(),
loss = loss, ws = [1.0, 1.0], int = true)

s = "create_ho(sampler) = Hyperoptimizer($n_samples, sampler, " *
join("$k = $v, " for (k, v) in pars) * ")"
Expand Down
43 changes: 43 additions & 0 deletions examples/utils/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,46 @@ function plot_cos(
return p
end


"""
plot_err_time(
res
)
`res`: Dataframe with fitting error and force time information.
Returns a plot with fitting errors vs force times. Required in hyper-parameter optimization.
"""
function plot_err_time(res)
e_mae = res[!, :e_mae]
f_mae = res[!, :f_mae]
times = res[!, :time_us]
plot(times,
e_mae,
seriestype = :scatter,
alpha = 0.55,
thickness_scaling = 1.35,
markersize = 3,
markerstrokewidth = 1,
markerstrokecolor = :black,
markershape = :circle,
markercolor = :gray,
label = "MAE(E_Pred, E_DFT) | eV/atom")
plot!(times,
f_mae,
seriestype = :scatter,
alpha = 0.55,
thickness_scaling = 1.35,
markersize = 3,
markerstrokewidth = 1,
markerstrokecolor = :red,
markershape = :utriangle,
markercolor = :red2,
label = "MAE(F_Pred, F_DFT) | eV/Å")
plot!(dpi = 300,
label = "",
xlabel = "Time per force per atom | µs",
ylabel = "MAE")
end

0 comments on commit 1bdc6be

Please sign in to comment.