greta-dev / greta.gp

a greta extension for Gaussian process modelling
https://greta-dev.github.io/greta.gp/
Apache License 2.0
19 stars 4 forks source link

catch incorrect length of lengthscale vector #12

Open goldingn opened 4 years ago

goldingn commented 4 years ago

When a kernel is specified with a single lengthscale, but evaluated on a design matrix with multiple columns, only the first column is used and no warning is issued. We should let the user know about a dimension mismatch, and either error, or in the case of a single lengthscale bing provided, just replicate it and assume they want an isotropic kernel.

See here for a reprex: https://forum.greta-stats.org/t/gaussian-process-in-greta-matern-covariance/151/17

jdyen commented 4 years ago

This is messy. I wanted to add a check similar to check_active_dims when setting up the kernels. See here: https://github.com/greta-dev/greta.gp/blob/448f29c85f73dc7ccf0b9594dd2111e40e478dd1/R/kernel_constructors.R#L81

But the dimension of the design matrix is unknown at this stage. So possibly needs to go in the kernel call, e.g., https://github.com/greta-dev/greta.gp/blob/448f29c85f73dc7ccf0b9594dd2111e40e478dd1/R/greta_kernel_class.R#L172

Then the issue is that it needs to check only when lengthscale is a valid parameter.

jdyen commented 4 years ago

Probably need to do the same with other parameters, e.g., variance in the rbf kernel. It's surprising that it doesn't error inside the tf calls, e.g., https://github.com/greta-dev/greta.gp/blob/448f29c85f73dc7ccf0b9594dd2111e40e478dd1/R/tf_kernels.R#L74-L86

I assume the extra dims aren't dropped before here, in which case it's a result of how tf handles broadcasting.