dfm / george

Fast and flexible Gaussian Process regression in Python
http://george.readthedocs.io
MIT License
445 stars 128 forks source link

Questions about the model fitting example #138

Closed kennychowdhary closed 3 years ago

kennychowdhary commented 3 years ago

Hi,

I had a few questions about the model fitting example when you use a GP noise:

1) You defined the generic kernel as K_ij = \sigma^2delta_ij + k(t_i,t_j) but in the code you defined the kernel as `np.var(y) kernels.Matern32Kernel(10.0)` Why the np.var(y) factor and where is the \sigma^2*delta_ij term?

2) What does gp.compute do and why do you need yerr? I assume it precomputes k(r) since it only needs to be done once, but why do you need yerr? It seems like the results change dramatically if the yerr changes.

dfm commented 3 years ago

The answer to both of your questions is the same: sigma == yerr!

Also: The var(y) is the initial guess for the amplitude of the Matern kernel.

kennychowdhary commented 3 years ago

Oh I see. So by default the white noise kernel is added, where sigma is yerr.

One other related question. Once you define the log likelihood, as you did in the tutorial, why aren’t the kernel hyper parameters, e.g. length scale and amplitude, included in the mcmc sampler? In other words is it possible (or even necessary) to get a posterior on both the model parameters and the noise parameters?

dfm commented 3 years ago

It's not quite a jitter term: it's heteroscedastic (the values can be different for each data point) and it won't be included in predictions.

The kernel hyperparameters certainly are included in the MCMC! There might be scenarios where that's not needed, but you'll generally want to marginalize.

kennychowdhary commented 3 years ago

Is there a way to extract the hyperparameter samples like the sigma, amplitude and length scale?

dfm commented 3 years ago

I mean, that's what's happening in the tutorial: https://george.readthedocs.io/en/latest/tutorials/model/#the-final-fit

dfm commented 3 years ago

Look at gp.get_parameter_names() to figure out the names.

kennychowdhary commented 3 years ago

you're absolutely right! For some reason I thought those five parameters were just from the f(t) model. The last two parameters are the matern kernel params:

('mean:amp', 'mean:location', 'mean:log_sigma2', 'kernel:k1:log_constant', 'kernel:k2:metric:log_M_0_0') Is there a way to add a white noise kernel parameter? I would like to add \sigma_i to the gp parameters shown above in addition to the two matern32 hyperparameters. It seems like you are hard coding it as yerr?

dfm commented 3 years ago

Yes this is explained in several places throughout the documentation (e.g. https://george.readthedocs.io/en/latest/tutorials/hyper/). Perhaps you should spend some more time with the docs and try to work out these answers yourself because there's only so much support I can provide!

kennychowdhary commented 3 years ago

Thanks for all your help. I really appreciate it.