Skip to content

TypeError: zip argument #1 must support iteration #3330

Closed
@aakhmetz

Description

@aakhmetz

Description of your problem

Please provide a minimal, self-contained, and reproducible example.

import theano
from theano.compile.ops import as_op
from theano import shared
import theano.tensor as tt
import pymc3 as pm
import numpy as np
from scipy.special import gammainc

@as_op(itypes=[tt.dscalar, tt.dscalar, tt.lvector], otypes=[tt.dmatrix])
def pgamma_for_projection(delay_mean, delay_sd, taus):
    τs_to_forecast = np.append([0],taus[taus<0])
    
    res = np.array([],dtype=np.float64).reshape(0,τs_to_forecast.shape[0])
    for τ in taus[taus>=0]:
        res0 = gammainc((delay_mean/delay_sd)**2, delay_mean*(τ-τs_to_forecast)/(delay_sd**2))
        res0 = np.r_[np.diff(res0),1-res0[-1]]
        res = np.vstack([res,res0])
    return res

τs = np.arange(17,-28,-7,dtype=np.int64)

with pm.Model() as model:
    delaymean = pm.Uniform('delaymean',13,16)
    delaysd = pm.Uniform('delaysd',7,10)
    
    trace = pm.sample(1000, tune=200)
    
    probs = pm.Deterministic('probs',pgamma_for_projection(delaymean,delaysd,shared(τs)))
    counts = pm.NegativeBinomial('counts',10,probs)
    ttl = pm.Deterministic('ttl',counts)

    ppc = pm.sample_posterior_predictive(trace, vars=[probs,counts,ttl], samples=500)

Please provide the full traceback.

Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [delaysd, delaymean]
Sampling 2 chains: 100%|██████████| 2400/2400 [00:01<00:00, 1706.70draws/s]
  0%|          | 0/500 [00:00<?, ?it/s]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-72-1a6f7c9ddc3b> in <module>
     22     ttl = pm.Deterministic('ttl',counts)
     23 
---> 24     ppc = pm.sample_posterior_predictive(trace, vars=[probs,counts,ttl], samples=500)

~/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in sample_posterior_predictive(trace, samples, model, vars, size, random_seed, progressbar)
   1102                 param = trace[idx % len_trace]
   1103 
-> 1104             values = draw_values(vars, point=param, size=size)
   1105             for k, v in zip(vars, values):
   1106                 ppc_trace[k.name].append(v)

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in draw_values(params, point, size)
    394                                             point=point,
    395                                             givens=givens.values(),
--> 396                                             size=size)
    397                         evaluated[param_idx] = drawn[param] = value
    398                         givens[param.name] = (param, value)

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in _draw_value(param, point, givens, size)
    502                 not all(var.dshape == getattr(val, 'shape', tuple())
    503                         for var, val in zip(variables, values))):
--> 504                 output = np.array([func(*v) for v in zip(*values)])
    505             elif (size is not None and any((val.ndim > var.ndim)
    506                   for var, val in zip(variables, values))):

TypeError: zip argument #1 must support iteration

Please provide any additional information below.

I wanted to sample sums over columns of counts, but sum() didn't work for me and then even simple creation of Deterministic node led to a Type error.

Versions and main components

  • PyMC3 Version: 3.6
  • Theano Version: 1.0.3
  • Python Version: 3.6.6
  • Operating system: osX
  • How did you install PyMC3: (conda/pip) pip with the latest version from github

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions