Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing around with Surrogates.jl #442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SimulationParameters = "32ab26d3-25d6-405d-a295-367385e16093"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Surrogates = "6fc51010-71bc-11e9-0e15-a3fcc6593c49"
TAUENN = "4f5ffc88-c87f-11eb-142e-4d2ba0394a67"
TEQUILA = "a60c9cbd-e72f-4185-96b6-b8fc312c4d37"
TGLFNN = "558c7b13-fd9f-4806-b461-592296cfa9d0"
Expand Down
28 changes: 28 additions & 0 deletions src/actors/transport/flux_matcher_actor.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import NLsolve
using LinearAlgebra
import Surrogates
import Statistics

#= ================ =#
# ActorFluxMatcher #
Expand Down Expand Up @@ -112,6 +114,32 @@ function _step(actor::ActorFluxMatcher)
actor_logging(dd, old_logging)
end

#### SURROGATES ####
old_logging = actor_logging(dd, false)
try
tmp = hcat(map(collect, z_scaled_history)...)

# Calculate the mean and standard deviation for each set of corresponding elements.
means = Statistics.mean(tmp; dims=2) # Result is a 1-row matrix
std_devs = Statistics.std(tmp; dims=2) # Result is a 1-row matrix

N = 5 # Number of sigmas (change this to your specific number of sigmas)

# Calculate the lower and upper bounds.
lower_bound = means .- N * std_devs
upper_bound = means .+ N * std_devs
lower_bound = scale_z_profiles(means .* 0.0 .- 4.0)
upper_bound = scale_z_profiles(means .* 0.0 .+ 0.0)
@show lower_bound
@show upper_bound

radial_basis = Surrogates.SecondOrderPolynomialSurrogate(z_scaled_history, err_history, lower_bound, upper_bound)
Surrogates.surrogate_optimize(z -> norm(flux_match_errors(actor, z)), Surrogates.SRBF(), lower_bound, upper_bound, radial_basis, Surrogates.SobolSample(); maxiters=50)
finally
actor_logging(dd, old_logging)
end
#### SURROGATES ####

if par.do_plot
display(res)
end
Expand Down
Loading