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

Mixtures not refactored for V4 #4781

Closed
larryshamalama opened this issue Jun 18, 2021 · 1 comment · Fixed by #5438
Closed

Mixtures not refactored for V4 #4781

larryshamalama opened this issue Jun 18, 2021 · 1 comment · Fixed by #5438
Assignees
Labels
Milestone

Comments

@larryshamalama
Copy link
Member

larryshamalama commented Jun 18, 2021

The following snipet and error uses v4:

import numpy as np
import pandas as pd
import pymc3 as pm

from aesara import tensor as at

old_faithful_df = pd.read_csv(pm.get_data("old_faithful.csv"))
waiting_times = old_faithful_df["waiting"]
waiting_times = ((waiting_times - waiting_times.mean())/waiting_times.std()).values

def stick_breaking(betas):
    '''
    betas is a K-vector of iid draws from a Beta distribution
    '''
    sticks = tt.concatenate(
        [
            [1],
            (1 - betas[:-1])
        ]
    )
    
    return tt.mul(betas, tt.cumprod(sticks))

with pm.Model() as model:
    alpha = pm.Gamma(name="alpha", alpha=1, beta=1)
    v = pm.Beta(name="v", alpha=1, beta=alpha, shape=(K,)) # beta=alpha kinda confusing here
    
    w = pm.Deterministic(name="w", var=stick_breaking(v))
    mu = pm.Normal(name="mu", mu=0, sigma=5)
    sigma = pm.InverseGamma(name="sigma", alpha=1, beta=1, shape=(K,))
    obs = pm.NormalMixture(name="theta", w=w, mu=mu, tau=1/sigma, observed=waiting_times)

yields

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-9959a48ef76f> in <module>
      6     mu = pm.Normal(name="mu", mu=0, sigma=5)
      7     sigma = pm.InverseGamma(name="sigma", alpha=1, beta=1, shape=(K,))
----> 8     obs = pm.NormalMixture(name="theta", w=w, mu=mu, tau=1/sigma, observed=waiting_times)

~/anaconda3/envs/pymc3-dev-py39/lib/python3.9/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
    205         # Create the RV without specifying initval, because the initval may have a shape
    206         # that only matches after replicating with a size implied by dims (see below).
--> 207         rv_out = cls.dist(*args, rng=rng, initval=None, **kwargs)
    208         ndim_actual = rv_out.ndim
    209         resize_shape = None

TypeError: dist() missing 1 required positional argument: 'dist_params'

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-9959a48ef76f> in <module>
      6     mu = pm.Normal(name="mu", mu=0, sigma=5)
      7     sigma = pm.InverseGamma(name="sigma", alpha=1, beta=1, shape=(K,))
----> 8     obs = pm.NormalMixture(name="theta", w=w, mu=mu, tau=1/sigma, observed=waiting_times)

~/anaconda3/envs/pymc3-dev-py39/lib/python3.9/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
    205         # Create the RV without specifying initval, because the initval may have a shape
    206         # that only matches after replicating with a size implied by dims (see below).
--> 207         rv_out = cls.dist(*args, rng=rng, initval=None, **kwargs)
    208         ndim_actual = rv_out.ndim
    209         resize_shape = None

TypeError: dist() missing 1 required positional argument: 'dist_params'

However, when using v3.11.2, my model works fine. Is this because we have yet to port Mixture distributions in v4? (Similar to issue 4642?)

@ricardoV94
Copy link
Member

Yes it hasn't been refactored yet

@ricardoV94 ricardoV94 added this to the vNext (4.0.0) milestone Jun 27, 2021
@ricardoV94 ricardoV94 changed the title TypeError dist_params when using pm.NormalMixture pm.NormalMixture not refactored for V4 Jun 27, 2021
@ricardoV94 ricardoV94 added the v4 label Jun 27, 2021
@ricardoV94 ricardoV94 changed the title pm.NormalMixture not refactored for V4 Mixtures not refactored for V4 Dec 13, 2021
@michaelosthege michaelosthege modified the milestones: v4.0.0b2, v4.0.0b3 Jan 7, 2022
@ricardoV94 ricardoV94 self-assigned this Jan 30, 2022
@ricardoV94 ricardoV94 modified the milestones: v4.0.0b3, v4.0.0 Feb 3, 2022
@ricardoV94 ricardoV94 modified the milestones: v4.0.0, v4.0.0b4 Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants