Combine latent with observable variables for Latent Gaussian Processes

Hello, I am working on a latent Gaussian Processes model, where I have 4 features, 2 of them are observable and the other 2 are uncertain. I am wondering how can I combine both of them as inputs to the function.

Here is my trial, but I can not simply concatenate them as numpy array because I get an error that they are not of the same shape.

My second question is if I can assume a Gaussian likelihood but I have these two latent variables, can I still use the Marginal Implementation of GP? I am a little bit confused about the difference of the two implementations, would both of them have the same number of parameters ?

with pm.Model() as model:

    #Covariance Function
    rho_1 = pm.HalfNormal("rho_1", 100) 
    rho_2 = pm.HalfNormal("rho_2", 100)
    cov= pm.gp.cov.Exponential(2,[rho_1, rho_2])

    #Mean Function
    mean_func = pm.gp.mean.Zero() 

    nu12_mu=X_train[:,2]
    nu_mu=X_train[:,3]

    uncertain_nu12=pm.Normal("uncertain_nu12", mu=nu12_mu, sigma=df["nu12"].std())
    uncertain_nu=pm.Normal("uncertain_nu", mu=nu_mu, sigma=df["nu"].std())
    X_observable_latent=np.concatenate([X_train[:,0].reshape(len(X_train),1),X_train[:,1].reshape(len(X_train),1),uncertain_nu12, uncertain_nu], axis=1)
    gp = pm.gp.Latent(mean_func=mean_func,cov_func=cov)

    f = gp.prior("f", X=X_observable_latent)

    sigma = pm.HalfNormal("sigma", sigma=1.0) 
    y_ = pm.Normal("y", mu=f, sigma = sigma, observed=y_train_temp)

    idata = pm.sample(3000, tune=1000, nuts_sampler="numpyro", chains=4)

You can do this with either Marginal or Latent. You’ll need to use pt.concatenate though, since not all of the inputs are numpy arrays.

1 Like