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

Make figure in AR2 example reproducible #1816

Merged
merged 6 commits into from
Jun 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/ar2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def transition(carry, _):
with numpyro.handlers.condition(data={"y": y[2:]}):
_, mu = scan(transition, init, timesteps)

numpyro.deterministic("mu", mu)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ebbaa7



def ar2_for_loop(y):
alpha_1 = numpyro.sample("alpha_1", dist.Normal(0, 1))
Expand All @@ -75,13 +73,16 @@ def ar2_for_loop(y):

y_prev = y[1]
y_prev_prev = y[0]

mu = []
for i in range(2, len(y)):
m_t = const + alpha_1 * y_prev + alpha_2 * y_prev_prev
mu.append(m_t)
y_t = numpyro.sample("y_{}".format(i), dist.Normal(m_t, sigma), obs=y[i])
y_prev_prev = y_prev
y_prev = y_t

numpyro.deterministic("mu", jnp.asarray(mu))


def run_inference(model, args, rng_key, y):
start = time.time()
Expand Down