TypeError: Random() got an unexpected keyword argument 'point' when running sample_posterior_predictive

I’m able to build a model but get an error when running sample_posterior_predictive.
Note that I specify cores = 1 as recommended here. Without it, the modeling just hangs with the progress bar at 0%.

The ShiftedGamma distribution is from this post.

class ShiftedGamma(pm.Gamma):
    def __init__(self, alpha, beta, shift, *args, **kwargs):
        transform = pm.distributions.transforms.lowerbound(shift)
        super().__init__(alpha=alpha, beta=beta, *args, **kwargs,
                         transform=transform)
        self.shift = shift
        self.mean += shift
        self.mode += shift
        
    def random(self):
        return super().random() + self.shift
    
    def logp(self, x):
        return super().logp(x - self.shift)

with pm.Model() as model1:
    loc = pm.AsymmetricLaplace('loc', b = 117545, kappa = 2.677, mu = 626924)   
    scale = pm.AsymmetricLaplace('scale', b = 276.69, kappa = 1.86, mu = 3046.7)

    pred = ShiftedGamma("test_var", alpha = 574, beta = 1/scale, shift = loc, observed = np.array([1.72e6, 1.58e6, 1.64e6, 1.59e6]))

    trace = pm.sample(400, cores = 1)

params_pred = pm.sample_posterior_predictive(trace, 1000, model1)

Get this error when running sample_posterior_predictive mentioned elsewhere, but unclear whether this is a bug:

TypeError: random() got an unexpected keyword argument 'point'

Assuming you are using PyMC3 here and not v4, the random method should have point and size keyword arguments.

1 Like