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

Enquiry about model.predict() with batch_size and sampling from each layer after model fitting #32

Open
XiaoyuHy opened this issue May 24, 2021 · 0 comments

Comments

@XiaoyuHy
Copy link

XiaoyuHy commented May 24, 2021

Hi,
I'm writing to enquire about two use cases of deep GP.
1.
When I was using the two-layer deep GP to make predictions, when I pass batch_size to the function model.predict(), it seems that it only returns the predicted mean (f_mean) without f_var. However, as in your example below(https://secondmind-labs.github.io/GPflux/notebooks/gpflux_features.html:

def plot(model, X, Y, ax=None):
    if ax is None:
        fig, ax = plt.subplots()

    x_margin = 1.0
    N_test = 100
    X_test = np.linspace(X.min() - x_margin, X.max() + x_margin, N_test).reshape(-1, 1)
    **out = model(X_test)

    mu = out.f_mean.numpy().squeeze()
    var = out.f_var.numpy().squeeze()**
    X_test = X_test.squeeze()
    lower = mu - 2 * np.sqrt(var)
    upper = mu + 2 * np.sqrt(var)

    ax.set_ylim(Y.min() - 0.5, Y.max() + 0.5)
    ax.plot(X, Y, "kx", alpha=0.5)
    ax.plot(X_test, mu, "C1")

    ax.fill_between(X_test, lower, upper, color="C1", alpha=0.3)
prediction_model = deep_gp.as_prediction_model()

When no batch_size is passed, deep_gp.as_prediction_model() returns both f_mean and f_var. Could you please let me know how I can get both f_mean and f_var when passing batch_size to prediction_model.predict() ?

  1. On this webpage, https://secondmind-labs.github.io/GPflux/notebooks/deep_gp_samples.html, you have given an example of making deep GP samples. However, I cannot see the model fitting part on the webpage. If want to make samples from each layer after model fitting , i.e., after model.compile(tf.optimizers.Adam(0.01)) and history = model.fit({"inputs": X, "targets": Y}, epochs=int(1e3), verbose=0), could you please let me know how I can achieve this?

Many thanks.

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

1 participant