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

Bug in "Variational Inference: Bayesian Neural Networks" notebook #654

Open
yoshida-chem opened this issue Apr 3, 2024 · 2 comments · May be fixed by #689 or #719
Open

Bug in "Variational Inference: Bayesian Neural Networks" notebook #654

yoshida-chem opened this issue Apr 3, 2024 · 2 comments · May be fixed by #689 or #719
Labels
good first issue Good for newcomers

Comments

@yoshida-chem
Copy link

Notebook title: Variational Inference: Bayesian Neural Networks
Notebook url: https://www.pymc.io/projects/examples/en/latest/variational_inference/bayesian_neural_network_advi.html

Issue description

One needs to pass all the variables to a single Minibatch call so that their slices are identical, otherwise it would randomly pair some X with unrelated y.

minibatch_x = pm.Minibatch(X_train, batch_size=50)
minibatch_y = pm.Minibatch(Y_train, batch_size=50)

ann_input and ann_output are overwritten by X _train and Y_train.

def construct_nn(ann_input, ann_output):
    n_hidden = 5

    # Initialize random weights between each layer
    init_1 = rng.standard_normal(size=(X_train.shape[1], n_hidden)).astype(floatX)
    init_2 = rng.standard_normal(size=(n_hidden, n_hidden)).astype(floatX)
    init_out = rng.standard_normal(size=n_hidden).astype(floatX)

    coords = {
        "hidden_layer_1": np.arange(n_hidden),
        "hidden_layer_2": np.arange(n_hidden),
        "train_cols": np.arange(X_train.shape[1]),
        # "obs_id": np.arange(X_train.shape[0]),
    }
    with pm.Model(coords=coords) as neural_network:
        ann_input = pm.Data("ann_input", X_train, mutable=True, dims=("obs_id", "train_cols"))
        ann_output = pm.Data("ann_output", Y_train, mutable=True, dims="obs_id")

Proposed solution

One needs to pass all the variables to a single Minibatch call so that their slices are identical.

minibatch_x, minibatch_y = pm.Minibatch(X_train, Y_train, batch_size=50)
@twiecki twiecki added the good first issue Good for newcomers label Jun 15, 2024
ElisabethBrockhausQC added a commit to ElisabethBrockhausQC/pymc-examples that referenced this issue Jun 15, 2024
- Improve axis labels
- Remove `mutable=True` argument (will get deprecated)
- Fix shape warning
- Fix minibatch sampling issue (cf. pymc-devs#654)
twiecki pushed a commit that referenced this issue Jun 15, 2024
- Improve axis labels
- Remove `mutable=True` argument (will get deprecated)
- Fix shape warning
- Fix minibatch sampling issue (cf. #654)
@Deepakchowdavarapu
Copy link

Deepakchowdavarapu commented Aug 2, 2024

@yoshida-chem , @twiecki @ can you review my PR #689

@Deepakchowdavarapu
Copy link

@yoshida-chem @twiecki @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
3 participants