I am trying to do the following:
f = K1((x1, y1), (x1, y1)*) + K2((x2, y2), (x2, y2)*) + x4 * K3((x1, y1), (x1, y1)*)
where K1, K2, and K3 are kernels that use two dimensions each (x and y). The third kernel (K3) needs to be scaled by x3. I thought I would perform this by K4(x4) * K3. However, I don’t see that I can specify the active_dims
in the constant kernel.
Here my code if my above explanation wasn’t clear:
# Features contains rows of [lon_eq, lat_eq, lon_sta, lat_sta, dist_jb]
X = features
with pm.Model() as model:
def make_gp(name, active_dims):
theta = pm.HalfCauchy(f'theta_{name}', 5)
pi = pm.HalfCauchy(f'pi_{name}', 5)
rho = pm.HalfCauchy(f'rho_{name}', 5)
cov = theta * pm.gp.cov.Exponential(ls=rho, input_dim=5, active_dims=active_dims) + pi
gp = pm.gp.MarginalSparse(cov_func=cov, approx="FITC")
return {
'theta': theta,
'pi': pi,
'rho': rho,
'cov': cov,
'gp': gp
}
parts = {}
parts['eq'] = make_gp('eq', [0, 1])
parts['sta'] = make_gp('sta', [2, 3])
parts['dist_jb'] = make_gp('dist_jb', [0, 1])
# How to combine parts['dist_jb']['gp'] with 'dist_jb', active_dims=4
gp = parts['eq']['gp'] + parts['sta']['gp']
# Model error
sigma_noise = pm.HalfNormal("sigma_noise", sd=1)
# initialize inducing points with K-means
Xu = pm.gp.util.kmeans_inducing_points(200, X)
y = gp.marginal_likelihood("y", X=X, Xu=Xu, y=resids, sigma=sigma_noise)