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

catch incorrect length of lengthscale vector #12

Open
goldingn opened this issue Nov 8, 2019 · 3 comments
Open

catch incorrect length of lengthscale vector #12

goldingn opened this issue Nov 8, 2019 · 3 comments

Comments

@goldingn
Copy link
Member

goldingn commented Nov 8, 2019

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
Copy link
Contributor

jdyen commented Nov 12, 2019

This is messy. I wanted to add a check similar to check_active_dims when setting up the kernels. See here:

arguments = list(active_dims = check_active_dims(columns, lengthscales)))

But the dimension of the design matrix is unknown at this stage. So possibly needs to go in the kernel call, e.g.,

tf_K <- function(operation, X, X_prime, greta_kernel, out_dim) {

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

@jdyen
Copy link
Contributor

jdyen commented Nov 12, 2019

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.,

greta.gp/R/tf_kernels.R

Lines 74 to 86 in 448f29c

tf_rbf <- function(X, X_prime, lengthscales, variance, active_dims) {
# pull out active dimensions
X <- tf_cols(X, active_dims)
X_prime <- tf_cols(X_prime, active_dims)
# calculate squared distances
r2 <- squared_dist(X, X_prime, lengthscales)
# construct and return RBF kernel
variance * tf$math$exp(-r2 / fl(2))
}

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

@njtierney
Copy link
Contributor

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

3 participants