ValueError: too many values to unpack in metropolis sampling

Hi,

I ran into this weird error associated with Metropolis sampling step:

I have to use metropolis sampling in this case.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-692-2bf6cba863a0> in <module>
 11 
 12 path = APWPath( 'apw', poles, 2 )
---> 13 trace = path.create_model()
 14 
 15 # def plot_result():

<ipython-input-691-d73d1cea4efe> in create_model(self, site_lon_lat, watson_concentration, rate_scale, tpw_rate_scale)
194 #             print(model.__dict__)
195 
--> 196             trace = pm.sample(1000, step = pm.Metropolis())
197 
198         return trace

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/step_methods/arraystep.py in __new__(cls, *args, **kwargs)
 63                 # If we don't return the instance we have to manually
 64                 # call __init__
---> 65                 step.__init__([var], *args, **kwargs)
 66                 # Hack for creating the class correctly when unpickling.
 67                 step.__newargs = ([var], ) + args, kwargs

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/step_methods/metropolis.py in __init__(self, vars, S, proposal_dist, scaling, tune, tune_interval, model, mode, **kwargs)
134 
135         shared = pm.make_shared_replacements(vars, model)
--> 136         self.delta_logp = delta_logp(model.logpt, vars, shared)
137         super(Metropolis, self).__init__(vars, shared)
138 

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/step_methods/metropolis.py in delta_logp(logp, vars, shared)
627     inarray1 = tensor_type('inarray1')
628 
--> 629     logp1 = pm.CallableTensor(logp0)(inarray1)
630 
631     f = theano.function([inarray1, inarray0], logp1 - logp0)

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/theanof.py in __call__(self, input)
270         input : TensorVariable
271         """
--> 272         oldinput, = inputvars(self.tensor)
273         return theano.clone(self.tensor, {oldinput: input}, strict=False)
274 

ValueError: too many values to unpack (expected 1)

The code for model:

    def create_model(self, site_lon_lat=[0., 0.], watson_concentration=0., rate_scale=2.5, tpw_rate_scale = None):
            rate_scale > 0.0, "rate_scale must be a positive number."
            assert tpw_rate_scale == None or tpw_rate_scale > 0.0
            assert watson_concentration <= 0.0, "Nonnegative Watson concentration parameters are not supported."
            if tpw_rate_scale is None:
                self.include_tpw = False
            else:
                self.include_tpw = True

            args = []
    
            with pm.Model() as model:   
                start = VMF('start', 
                            lon_lat=(self._start_pole.longitude, self._start_pole.latitude), 
                            k=kappa_from_two_sigma(self._start_pole._A95), 
                            testval = np.array([1., 0.]), shape = 2)
    
                if self.include_tpw:
                    tpw_pole_angle = pm.Uniform('tpw_pole_angle', lower = 0., upper = 360.)
                    tpw_rate = pm.Exponential('tpw_rate', tpw_rate_scale)

                for i in range(self.n_euler_rotations):
                    euler = Watson_Girdle('euler_' + str(i), 
                                 lon_lat=site_lon_lat, 
                                 k=watson_concentration,
                                  testval = np.array([1., 0.]), shape = 2)
                    args.append(euler)

                for i in range(self.n_euler_rotations):
                    rate = pm.Exponential('rate_' + str(i), rate_scale)

                    args.append(rate)

                age_list = [p._age for p in self._poles]
                for i in range(self.n_euler_rotations - 1):
                    changepoint = pm.Uniform(
                        'changepoint_' + str(i), lower = min(age_list), upper = max(age_list))

                    args.append(changepoint)

                for i, p in enumerate(self._poles):
                    if p._age_type == 'gaussian':
                        pole_age = pm.Normal(
                            'a_' + str(i), mu=p._age, tau=np.power(p._sigma_age, -2.))
                    elif p._age_type == 'uniform':
                        pole_age = pm.Uniform(
                            'a_' + str(i), lower=p._sigma_age[0], upper=p._sigma_age[1])

                    # Include TPW rate if it is part of model_vars
                    if self.include_tpw:
                        lon_lat = self._pole_position_fn(start, pole_age, tpw_pole_angle, tpw_rate, *args)
           
                    # Otherwise use zero for TPW rate.
                    else:
                        lon_lat = self._pole_position_fn(start, pole_age, 0., 0., *args)

                    observed_pole = VMF('p_' + str(i), 
                                lon_lat, 
                                k=kappa_from_two_sigma(p._A95), 
                                observed=[p.longitude, p.latitude])
                trace = pm.sample(1000, step = pm.Metropolis())
    return trace

when running pm.find_MAP, I got a missing input error:

---------------------------------------------------------------------------
MissingInputError                         Traceback (most recent call last)
<ipython-input-47-c454f54202c3> in <module>
 15 
 16 with model:
---> 17     pm.find_MAP()
 18     pm.sample(2000, step = pm.Metropolis())
 19 # def plot_result():

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/tuning/starting.py in find_MAP(start, vars, method, return_raw, include_transformed, progressbar, maxeval, model, *args, **kwargs)
 81     start = Point(start, model=model)
 82     bij = DictToArrayBijection(ArrayOrdering(vars), start)
---> 83     logp_func = bij.mapf(model.fastlogp_nojac)
 84     x0 = bij.map(start)
 85 

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/model.py in fastlogp_nojac(self)
244     @property
245     def fastlogp_nojac(self):
--> 246         return self.model.fastfn(self.logp_nojact)
247 
248     def fastdlogp_nojac(self, vars=None):

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/model.py in fastfn(self, outs, mode, *args, **kwargs)
938         Compiled Theano function as point function.
939         """
--> 940         f = self.makefn(outs, mode, *args, **kwargs)
941         return FastPointFunc(f)
942 

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/pymc3/model.py in makefn(self, outs, mode, *args, **kwargs)
908                                    on_unused_input='ignore',
909                                    accept_inplace=True,
--> 910                                    mode=mode, *args, **kwargs)
911 
912     def fn(self, outs, mode=None, *args, **kwargs):

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/compile/function.py in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
315                    on_unused_input=on_unused_input,
316                    profile=profile,
--> 317                    output_keys=output_keys)
318     return fn

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/compile/pfunc.py in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
484                          accept_inplace=accept_inplace, name=name,
485                          profile=profile, on_unused_input=on_unused_input,
--> 486                          output_keys=output_keys)
487 
488 

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/compile/function_module.py in    orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
   1837                   on_unused_input=on_unused_input,
   1838                   output_keys=output_keys,
-> 1839                   name=name)
   1840         with theano.change_flags(compute_test_value="off"):
   1841             fn = m.create(defaults)

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/compile/function_module.py in __init__(self, inputs, outputs, mode, accept_inplace, function_builder, profile, on_unused_input, fgraph, output_keys, name)
   1485             # OUTPUT VARIABLES)
   1486             fgraph, additional_outputs = std_fgraph(inputs, outputs,
    -> 1487                                                     accept_inplace)
   1488             fgraph.profile = profile
   1489         else:

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/compile/function_module.py in std_fgraph(input_specs, output_specs, accept_inplace)
179 
180     fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,
--> 181                                   update_mapping=update_mapping)
182 
183     for node in fgraph.apply_nodes:

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/gof/fg.py in __init__(self, inputs, outputs, features, clone, update_mapping)
173 
174         for output in outputs:
--> 175             self.__import_r__(output, reason="init")
176         for i, output in enumerate(outputs):
177             output.clients.append(('output', i))

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/gof/fg.py in __import_r__(self, variable, reason)
344         # Imports the owners of the variables
345         if variable.owner and variable.owner not in self.apply_nodes:
--> 346                 self.__import__(variable.owner, reason=reason)
347         elif (variable.owner is None and
348                 not isinstance(variable, graph.Constant) and

~/anaconda3/envs/Bayesian/lib/python3.6/site-packages/theano/gof/fg.py in __import__(self, apply_node, check, reason)
389                                      "for more information on this error."
390                                      % (node.inputs.index(r), str(node)))
  --> 391                         raise MissingInputError(error_msg, variable=r)
392 
393         for node in new_nodes:

MissingInputError: Input 0 of the graph (indices start from 0), used to compute Subtensor{int64}(euler_0, Constant{1}), was not provided and not given a value. Use the Theano flag exception_verbosity=‘high’, for more information on this error.