Skip to content

Mixtures not refactored for V4 #4781

Closed
@larryshamalama

Description

@larryshamalama

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?)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions