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

Further Kriging improvements - Noise variance, log likelihood, and simplifying implementation #375

Open
archermarx opened this issue Jul 12, 2022 · 1 comment

Comments

@archermarx
Copy link
Contributor

I'd like to make a couple more changes to kriging

1. Noise variance hyperparameter

This would allow modeling and optimization of noisy functions. I would probably add this as a field to the Kriging struct. Noise variance is usually easier to estimate by the user than other hyperparameters, and would default to zero (aka the surrogate interpolates the data). I would also add an example to the documentation for minimizing a noisy function.

One question: does adding fields to a struct count as a breaking change?

2. Log likelihood function

As another incremental step toward better hyperparameter optimization, I'd like to bundle the Kriging log likelihood function with Surrogates. I could then add a tutorial to the kriging section of the documentation on hyperparameter optimization.

3. Combine 1D and ND functions

I'm not sure of the historical reasons for this, but maintaining separate versions of the surrogate construction functions for 1D and ND data seems ripe for problems, as I found during #374. I have already tested that the ND versions work just fine on 1D data, but run slightly slower. It would take some thought to do it in a way that doesn't hurt performance, but it would allow us to remove a lot of code and make maintenance much easier.

@archermarx
Copy link
Contributor Author

archermarx commented Jul 12, 2022

Here's what including noise variance looks like:

Random.seed!(1234)
  lb = 0.0
  ub = 10.0
  func = x -> sin(x)
  n_samples = 50
  x = sample(n_samples, lb, ub, SobolSample())

  # Add some random noise to the function
  y = func.(x) .+ 0.1 * randn(n_samples)

  # Build a kriging surrogate without noise
  my_k = Kriging(x, y, lb, ub, noise_variance = 0.0)

  x_fine = LinRange(lb, ub, 10000)
  y_fine = func.(x_fine)
  pred_fine = my_k.(x_fine)
  errs = std_error_at_point.(my_k, x_fine)
  p = Plots.plot(x_fine, y_fine, label = "True function", legend = :outertop)
  Plots.plot!(x_fine, pred_fine, label = "surrogate", ribbon= 3 * errs, ylims = (-2, 2))
  Plots.scatter!(my_k.x, my_k.y, mc = :black, label = "Data")

plot_258

This interpolates the data but doesn't tell us much about how the signal varies

If we now instead include a noise variance, we get a much more accurate picture of the underlying function

my_k = Kriging(x, y, lb, ub, noise_variance = 0.1)

plot_257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant