Skip to content

Histogram trick #38

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

Merged
merged 27 commits into from
Jun 11, 2022
Merged

Histogram trick #38

merged 27 commits into from
Jun 11, 2022

Conversation

ferrine
Copy link
Member

@ferrine ferrine commented Apr 12, 2022

Add histogram trick to experimental utils. The idea is to reduce computations for huge data with smart preprocessing

Features:

  • Dask
  • Zero inflation
  • Discrete data
  • Continuous data
  • Docs
  • 2d inputs
big_data = np.random.randn(10000000000)  # can be dask array as well
BeforeAfter
with pm.Model():
    m = pm.Normal("m")
    s = pm.HalfNormal("s")
    a = pm.Normal("obs", m, s, observed=big_data)
    trace = pm.sample() # very slow
with pm.Model():
    m = pm.Normal("m")
    s = pm.HalfNormal("s")
    pot = pmx.distributions.histogram_approximation(
        "histogram_potential",
        pm.Normal.dist(m, s),
        observed=big_data,
        n_quantiles=1000
    )
    trace = pm.sample() # very fast
And Discrete distributions
big_data = np.random.randint(0, 10000, size=10000000000)  # can be dask array as well
BeforeAfter
with pm.Model():
    lam = pm.Exponential("lambda")
    a = pm.Poisson("obs", lam, observed=big_data)
    trace = pm.sample() # very slow
with pm.Model():
    lam = pm.Exponential("lambda")
    pot = pmx.distributions.histogram_approximation(
        "histogram_potential",
        pm.Poisson.dist(m, s),
        observed=big_data,
        min_count=1000
    )
    trace = pm.sample() # very fast

@ferrine ferrine marked this pull request as draft April 12, 2022 17:10
@ricardoV94
Copy link
Member

Can we come up with a better name than trick? Approximation, Compression, Discretization?

@ferrine
Copy link
Member Author

ferrine commented Apr 12, 2022

Can we come up with a better name than trick? Approximation, Compression, Discretization?

Don't know, I just like the "trick"

@ferrine
Copy link
Member Author

ferrine commented Apr 12, 2022

"approximation" is not that fancy

@ricardoV94
Copy link
Member

Looks like we need a pre-commit hook. There's a missing empty line at the end of one of the files

@twiecki
Copy link
Member

twiecki commented Apr 13, 2022

I agree with @ricardoV94, approximation is more appropriate here. We can leave the fancy language for the blog post @ferrine ;).

@ferrine
Copy link
Member Author

ferrine commented May 5, 2022

Ok, I'll will take that in account!

@ferrine ferrine force-pushed the histogram-trick branch from 24e9a25 to f3d8ff0 Compare May 24, 2022 13:37
@ferrine
Copy link
Member Author

ferrine commented Jun 11, 2022

I seem to have finished (on the converging path) the implementation for the histogram approximation. I converged with the following API

  1. Moved histogram_utils to pmx.distributions.
  2. histogram_utils contain the code used to approximate a potential. Namely, pmx.distributions.histogram_approximation
  3. See the detailed API in the PR description

@ferrine
Copy link
Member Author

ferrine commented Jun 11, 2022

blocked by #44

@ferrine ferrine marked this pull request as ready for review June 11, 2022 16:41
@ferrine
Copy link
Member Author

ferrine commented Jun 11, 2022

The PR is ready for review

Copy link
Member

@aloctavodia aloctavodia left a comment

Choose a reason for hiding this comment

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

LGTM!

@ferrine ferrine merged commit f50600b into main Jun 11, 2022
@ferrine ferrine deleted the histogram-trick branch June 11, 2022 20:27
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

Successfully merging this pull request may close these issues.

4 participants