Skip to content

Commit aaeeee9

Browse files
committed
add GP lengthscales to the GPJL code, and modfiy default lengscales for SKLJL
1 parent d31a2dc commit aaeeee9

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/GaussianProcess.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,22 @@ Optimize Gaussian process hyperparameters using in-build package method.
233233
Warning: if one uses `GPJL()` and wishes to modify positional arguments. The first positional argument must be the `Optim` method (default `LBGFS()`).
234234
"""
235235
function optimize_hyperparameters!(gp::GaussianProcess{GPJL}, args...; kwargs...)
236+
237+
if !(haskey(kwargs, :kernbounds)) # if no bounds defined
238+
n_hparams=length(get_params(gp)[1])
239+
low = repeat([log(1e-5)], n_hparams) # bounds provided in log space
240+
high = repeat([log(1e5)], n_hparams)
241+
extended_kwargs = merge((; kwargs...), (; kernbounds=(low,high), ))
242+
else
243+
ext_kwargs = (; kwargs...)
244+
end
236245
N_models = length(gp.models)
246+
237247
for i in 1:N_models
238248
# always regress with noise_learn=false; if gp was created with noise_learn=true
239249
# we've already explicitly added noise to the kernel
240250

241-
optimize!(gp.models[i], args...; noise = false, kwargs...)
251+
optimize!(gp.models[i], args...; noise = false, ext_kwargs...)
242252
println("optimized hyperparameters of GP: ", i)
243253
println(gp.models[i].kernel)
244254
end
@@ -304,7 +314,7 @@ function build_models!(
304314
const_value = 1.0
305315
var_kern = pykernels.ConstantKernel(constant_value = const_value, constant_value_bounds = (1e-5, 1e4))
306316
rbf_len = ones(size(input_values, 2))
307-
rbf = pykernels.RBF(length_scale = rbf_len, length_scale_bounds = (1e-5, 1e4))
317+
rbf = pykernels.RBF(length_scale = rbf_len, length_scale_bounds = (1e-5, 1e5))
308318
kern = var_kern * rbf
309319
println("Using default squared exponential kernel:", kern)
310320
else

0 commit comments

Comments
 (0)