Skip to content

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

Description

@XiaoyuHy

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions