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

Add compute_deterministics helper #7238

Merged
merged 5 commits into from
Apr 6, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Apr 5, 2024

Description

After #7206 this utility becomes more relevant.

import pymc as pm

with pm.Model(coords={"group": (0, 2, 4)}) as m:
    mu_raw = pm.Normal("mu_raw", 0, 1, dims="group")
    mu = pm.Deterministic("mu", mu_raw.cumsum(), dims="group")

    trace = pm.sample(var_names=["mu_raw"], chains=2, tune=5 draws=5)

assert "mu" not in trace.posterior

with m:
    trace.posterior = pm.compute_deterministics(trace.posterior, merge_dataset=True)

assert "mu" in trace.posterior

Also refactored the base logic to apply a Dataset to a PointFunc which was needed in a couple of places (here and in pymc-experimental).

This function could plausible be used by sample_prior_predictive and sample_posterior_predictive, but it seems that for backward compatibility these return and accept more diverse kinds of inputs. Let me know if I am wrong.

I am not so sure where to place the compute_deterministics. I put it in the sampling module which is a bit odd perhaps.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7238.org.readthedocs.build/en/7238/

@ricardoV94 ricardoV94 changed the title Add pm.compute_deterministics helper Add pm.compute_deterministics helper Apr 5, 2024
@ricardoV94 ricardoV94 force-pushed the compute_deterministics_helper branch 2 times, most recently from 9dbad38 to ff53eed Compare April 5, 2024 14:17
@ricardoV94
Copy link
Member Author

CC @tomicapretto

@ricardoV94 ricardoV94 force-pushed the compute_deterministics_helper branch from ff53eed to 2d29175 Compare April 5, 2024 14:31
@ricardoV94 ricardoV94 changed the title Add pm.compute_deterministics helper Add compute_deterministics helper Apr 5, 2024
@ricardoV94
Copy link
Member Author

Tests are failing because it's picking up the new scipy but the old arviz. Should work if we rerun again in a couple of hours/days

@ricardoV94
Copy link
Member Author

@OriolAbril the RTD preview is failing because it installs old arviz. Should we rerun or you are sure the docs are building correctly?

@ricardoV94
Copy link
Member Author

JAX test is failing with new scipy, should be fixed soon. Since these changes don't touch any related code I'm okay with merging despite them.

@OriolAbril
Copy link
Member

Go ahead, there are still things to fix with step methods so if something were to break I'll open a PR

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

Successfully merging this pull request may close these issues.

Add a helper pm.compute_deterministics to compute any deterministics on demand
2 participants