Skip to content

Theano MissingInputError when running model with start argument in sample #2109

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

Closed
narendramukherjee opened this issue May 2, 2017 · 15 comments

Comments

@narendramukherjee
Copy link

narendramukherjee commented May 2, 2017

This is a tangent from issue #2094 - I updated my versions of pymc3 and theano while testing out the model I mentioned in that issue. I am currently running:

In [17]: theano.__version__
Out[17]: '0.9.0.dev-c697eeab84e5b8a74908da654b66ec9eca4f1291'

In [18]: pm.__version__
Out[18]: '3.1rc3'

Here's the model again (same as in #2094 ):

with pm.Model() as model:
	# Dirichlet prior on the emission/spiking probabilities - 7 states (1 start state, 2 from changepoint1 to changepoint2, 4 from changepoint2 to end of the trial)
	p = pm.Dirichlet('p', np.ones(17), shape = (7, 17))

	# Uniform switch times
	# First changepoint
	t1 = pm.Uniform('t1', lower = 20, upper = 60, shape = 32)
	# Second changepoint
	t2 = pm.Uniform('t2', lower = t1 + 20, upper = 130, shape = 32)

	# Get the actual state numbers based on the switch times
	states1 = tt.switch(t1 >= np.repeat(np.arange(150)[:, None], 32, axis = 1), 0, set1[:])
	states2 = tt.switch(t2 >= np.repeat(np.arange(150)[:, None], 32, axis = 1), states1, set2[:])

	# Define the log-likelihood function
	def logp(value):
		value = tt.cast(value, 'int32')
		loglik = tt.sum(tt.log(p[states2.T, value]))
		return loglik

	# Categorical observations
	obs = pm.DensityDist('obs', logp, observed = {'value': data[:, :150]})

	# Inference button
	tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs = 2, start = {'t1': 25.0, 't2': 120.0})

The model runs fine if I don't specify the start argument in pm.sample. However, if I specify the start argument, Theano throws this error (this model was working with the older versions of pymc3 and theano that I had previously):

In [34]: with model:
    ...:     tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs =
    ...:  2, start = {'t1': 25.0, 't2': 120.0})
    ...:     
  0%|                                                | 0/500000 [00:00<?, ?it/s]
---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 344, in __call__
    return self.func(*args, **kwargs)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 131, in __call__
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py", line 131, in <listcomp>
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py", line 274, in _sample
    for it, strace in enumerate(sampling):
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/tqdm/_tqdm.py", line 833, in __iter__
    for obj in iterable:
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py", line 351, in _iter_sample
    _update_start_vals(start, model.test_point, model)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py", line 467, in _update_start_vals
    b[tname] = transform_func[0].forward(a[name]).eval()
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/graph.py", line 516, in eval
    self._fn_cache[inputs] = theano.function(inputs, self)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function.py", line 326, in function
    output_keys=output_keys)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py", line 486, in pfunc
    output_keys=output_keys)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py", line 1794, in orig_function
    output_keys=output_keys).create(
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py", line 1446, in __init__
    accept_inplace)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py", line 177, in std_fgraph
    update_mapping=update_mapping)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py", line 180, in __init__
    self.__import_r__(output, reason="init")
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py", line 351, in __import_r__
    self.__import__(variable.owner, reason=reason)
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py", line 397, in __import__
    raise MissingInputError(error_msg, variable=r)
theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute sigmoid(t1_interval__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/narendra/anaconda3/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 353, in __call__
    raise TransportableException(text, e_type)
joblib.my_exceptions.TransportableException: TransportableException
___________________________________________________________________________
MissingInputError                                  Tue May  2 13:25:22 2017
PID: 26681                Python 3.6.0: /home/narendra/anaconda3/bin/python
...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in __call__(self=<joblib.parallel.BatchedCalls object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        self.items = [(<function _sample>, (), {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None})]
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in <listcomp>(.0=<list_iterator object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        func = <function _sample>
        args = ()
        kwargs = {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None}
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, progressbar=True, model=<pymc3.model.Model object>, random_seed=442901656, live_plot=False, **kwargs={})
    269                             tune, model, random_seed)
    270     if progressbar:
    271         sampling = tqdm(sampling, total=draws)
    272     try:
    273         strace = None
--> 274         for it, strace in enumerate(sampling):
        it = undefined
        strace = None
        sampling =   0%|                                                | 0/500000 [00:00<?, ?it/s]
    275             if live_plot:
    276                 if it >= skip_first:
    277                     trace = MultiTrace([strace])
    278                     if it == skip_first:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/tqdm/_tqdm.py in __iter__(self=  0%|                                                | 0/500000 [00:00<?, ?it/s])
    828             except AttributeError:
    829                 raise TqdmDeprecationWarning("""\
    830 Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
    831 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    832 
--> 833             for obj in iterable:
        obj = undefined
        iterable = <generator object _iter_sample>
    834                 yield obj
    835                 # Update and print the progressbar.
    836                 # Note: does not call self.update(1) for speed optimisation.
    837                 n += 1

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _iter_sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, model=<pymc3.model.Model object>, random_seed=442901656)
    346     strace = _choose_backend(trace, chain, model=model)
    347 
    348     if len(strace) > 0:
    349         _update_start_vals(start, strace.point(-1), model)
    350     else:
--> 351         _update_start_vals(start, model.test_point, model)
        start = {'t1': 25.0, 't2': 120.0}
        model.test_point = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.]), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        model = <pymc3.model.Model object>
    352 
    353     try:
    354         step = CompoundStep(step)
    355     except TypeError:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _update_start_vals(a={'t1': 25.0, 't2': 120.0}, b={'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}, model=<pymc3.model.Model object>)
    462     for name in a:
    463         for tname in b:
    464             if is_transformed_name(tname) and get_untransformed_name(tname) == name:
    465                 transform_func = [d.transformation for d in model.deterministics if d.name == name]
    466                 if transform_func:
--> 467                     b[tname] = transform_func[0].forward(a[name]).eval()
        b = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        tname = 't2_interval__'
        transform_func.forward = undefined
        a = {'t1': 25.0, 't2': 120.0}
    468 
    469     a.update({k: v for k, v in b.items() if k not in a})
    470 
    471 def sample_ppc(trace, samples=None, model=None, vars=None, size=None,

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/graph.py in eval(self=Elemwise{sub,no_inplace}.0, inputs_to_values={})
    511         if not hasattr(self, '_fn_cache'):
    512             self._fn_cache = dict()
    513 
    514         inputs = tuple(sorted(inputs_to_values.keys(), key=id))
    515         if inputs not in self._fn_cache:
--> 516             self._fn_cache[inputs] = theano.function(inputs, self)
        self._fn_cache = {}
        inputs = ()
        self = Elemwise{sub,no_inplace}.0
    517         args = [inputs_to_values[param] for param in inputs]
    518 
    519         rval = self._fn_cache[inputs](*args)
    520 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function.py in function(inputs=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None)
    321                    accept_inplace=accept_inplace, name=name,
    322                    rebuild_strict=rebuild_strict,
    323                    allow_input_downcast=allow_input_downcast,
    324                    on_unused_input=on_unused_input,
    325                    profile=profile,
--> 326                    output_keys=output_keys)
        output_keys = None
    327     # We need to add the flag check_aliased inputs if we have any mutable or
    328     # borrowed used defined inputs
    329     fn._check_for_aliased_inputs = check_for_aliased_inputs
    330     return fn

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py in pfunc(params=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None, output_keys=None)
    481         inputs.append(si)
    482 
    483     return orig_function(inputs, cloned_outputs, mode,
    484                          accept_inplace=accept_inplace, name=name,
    485                          profile=profile, on_unused_input=on_unused_input,
--> 486                          output_keys=output_keys)
        output_keys = None
    487 
    488 
    489 def _pfunc_param_to_in(param, strict=False, allow_downcast=None):
    490     if isinstance(param, Constant):

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in orig_function(inputs=[], outputs=Out(Elemwise{sub,no_inplace}.0,False), mode=<theano.compile.mode.Mode object>, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', profile=None, on_unused_input=None, output_keys=None)
   1789                    outputs,
   1790                    mode,
   1791                    accept_inplace=accept_inplace,
   1792                    profile=profile,
   1793                    on_unused_input=on_unused_input,
-> 1794                    output_keys=output_keys).create(
        output_keys = None
        output_keys.create = undefined
   1795             defaults)
   1796 
   1797     t2 = time.time()
   1798     if profile:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in __init__(self=<theano.compile.function_module.FunctionMaker object>, inputs=[], outputs=[Out(Elemwise{sub,no_inplace}.0,False)], mode=<theano.compile.mode.Mode object>, accept_inplace=False, function_builder=<class 'theano.compile.function_module.Function'>, profile=None, on_unused_input=None, fgraph=None, output_keys=None)
   1441         if fgraph is None:
   1442             need_opt = True
   1443             # make the fgraph (copies the graph, creates NEW INPUT AND
   1444             # OUTPUT VARIABLES)
   1445             fgraph, additional_outputs = std_fgraph(inputs, outputs,
-> 1446                                                     accept_inplace)
        accept_inplace = False
   1447             fgraph.profile = profile
   1448         else:
   1449             # fgraph is already an optimized one
   1450             need_opt = False

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in std_fgraph(input_specs=[], output_specs=[Out(Elemwise{sub,no_inplace}.0,False)], accept_inplace=False)
    172             out_idx += 1
    173 
    174     orig_outputs = [spec.variable for spec in output_specs] + updates
    175 
    176     fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,
--> 177                                   update_mapping=update_mapping)
        update_mapping = {}
    178 
    179     for node in fgraph.apply_nodes:
    180         if getattr(node.op, 'destroy_map', None):
    181             if not accept_inplace:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __init__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], inputs=[], outputs=[Elemwise{sub,no_inplace}.0], features=[], clone=True, update_mapping={})
    175                                  "input's owner or use graph.clone.")
    176             self.__setup_r__(input)
    177             self.variables.add(input)
    178 
    179         for output in outputs:
--> 180             self.__import_r__(output, reason="init")
        self.__import_r__ = <bound method FunctionGraph.__import_r__ of [Ele...(TensorConstant{130}, TensorConstant{120.0}))))]>
        output = Elemwise{sub,no_inplace}.0
    181         for i, output in enumerate(outputs):
    182             output.clients.append(('output', i))
    183 
    184         self.profile = None

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import_r__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], variable=Elemwise{sub,no_inplace}.0, reason='init')
    346         reason
    347             reason is the name of the optimization or operation in progress.
    348         """
    349         # Imports the owners of the variables
    350         if variable.owner and variable.owner not in self.apply_nodes:
--> 351                 self.__import__(variable.owner, reason=reason)
        self.__import__ = <bound method FunctionGraph.__import__ of [Elemw...(TensorConstant{130}, TensorConstant{120.0}))))]>
        variable.owner = Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0)
        reason = 'init'
    352         elif (variable.owner is None and
    353                 not isinstance(variable, graph.Constant) and
    354                 variable not in self.inputs):
    355             global NullType

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], apply_node=Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0), check=True, reason='init')
    392                                      "provided and not given a value. Use the "
    393                                      "Theano flag exception_verbosity='high', "
    394                                      "for more information on this error."
    395                                      % (node.inputs.index(r), str(node)))
    396                         error_msg += get_variable_trace_string(r)
--> 397                         raise MissingInputError(error_msg, variable=r)
        error_msg = "Input 0 of the graph (indices start from 0), use...osity='high', for more information on this error."
        r = t1_interval__
    398 
    399         for node in new_nodes:
    400             assert node not in self.apply_nodes
    401             self.__setup_node__(node)

MissingInputError: Input 0 of the graph (indices start from 0), used to compute sigmoid(t1_interval__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
___________________________________________________________________________
"""

The above exception was the direct cause of the following exception:

TransportableException                    Traceback (most recent call last)
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in retrieve(self)
    681                 if 'timeout' in getfullargspec(job.get).args:
--> 682                     self._output.extend(job.get(timeout=self.timeout))
    683                 else:

/home/narendra/anaconda3/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
    607         else:
--> 608             raise self._value
    609 

TransportableException: TransportableException
___________________________________________________________________________
MissingInputError                                  Tue May  2 13:25:22 2017
PID: 26681                Python 3.6.0: /home/narendra/anaconda3/bin/python
...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in __call__(self=<joblib.parallel.BatchedCalls object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        self.items = [(<function _sample>, (), {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None})]
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in <listcomp>(.0=<list_iterator object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        func = <function _sample>
        args = ()
        kwargs = {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None}
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, progressbar=True, model=<pymc3.model.Model object>, random_seed=442901656, live_plot=False, **kwargs={})
    269                             tune, model, random_seed)
    270     if progressbar:
    271         sampling = tqdm(sampling, total=draws)
    272     try:
    273         strace = None
--> 274         for it, strace in enumerate(sampling):
        it = undefined
        strace = None
        sampling =   0%|                                                | 0/500000 [00:00<?, ?it/s]
    275             if live_plot:
    276                 if it >= skip_first:
    277                     trace = MultiTrace([strace])
    278                     if it == skip_first:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/tqdm/_tqdm.py in __iter__(self=  0%|                                                | 0/500000 [00:00<?, ?it/s])
    828             except AttributeError:
    829                 raise TqdmDeprecationWarning("""\
    830 Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
    831 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    832 
--> 833             for obj in iterable:
        obj = undefined
        iterable = <generator object _iter_sample>
    834                 yield obj
    835                 # Update and print the progressbar.
    836                 # Note: does not call self.update(1) for speed optimisation.
    837                 n += 1

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _iter_sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, model=<pymc3.model.Model object>, random_seed=442901656)
    346     strace = _choose_backend(trace, chain, model=model)
    347 
    348     if len(strace) > 0:
    349         _update_start_vals(start, strace.point(-1), model)
    350     else:
--> 351         _update_start_vals(start, model.test_point, model)
        start = {'t1': 25.0, 't2': 120.0}
        model.test_point = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.]), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        model = <pymc3.model.Model object>
    352 
    353     try:
    354         step = CompoundStep(step)
    355     except TypeError:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _update_start_vals(a={'t1': 25.0, 't2': 120.0}, b={'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}, model=<pymc3.model.Model object>)
    462     for name in a:
    463         for tname in b:
    464             if is_transformed_name(tname) and get_untransformed_name(tname) == name:
    465                 transform_func = [d.transformation for d in model.deterministics if d.name == name]
    466                 if transform_func:
--> 467                     b[tname] = transform_func[0].forward(a[name]).eval()
        b = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        tname = 't2_interval__'
        transform_func.forward = undefined
        a = {'t1': 25.0, 't2': 120.0}
    468 
    469     a.update({k: v for k, v in b.items() if k not in a})
    470 
    471 def sample_ppc(trace, samples=None, model=None, vars=None, size=None,

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/graph.py in eval(self=Elemwise{sub,no_inplace}.0, inputs_to_values={})
    511         if not hasattr(self, '_fn_cache'):
    512             self._fn_cache = dict()
    513 
    514         inputs = tuple(sorted(inputs_to_values.keys(), key=id))
    515         if inputs not in self._fn_cache:
--> 516             self._fn_cache[inputs] = theano.function(inputs, self)
        self._fn_cache = {}
        inputs = ()
        self = Elemwise{sub,no_inplace}.0
    517         args = [inputs_to_values[param] for param in inputs]
    518 
    519         rval = self._fn_cache[inputs](*args)
    520 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function.py in function(inputs=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None)
    321                    accept_inplace=accept_inplace, name=name,
    322                    rebuild_strict=rebuild_strict,
    323                    allow_input_downcast=allow_input_downcast,
    324                    on_unused_input=on_unused_input,
    325                    profile=profile,
--> 326                    output_keys=output_keys)
        output_keys = None
    327     # We need to add the flag check_aliased inputs if we have any mutable or
    328     # borrowed used defined inputs
    329     fn._check_for_aliased_inputs = check_for_aliased_inputs
    330     return fn

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py in pfunc(params=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None, output_keys=None)
    481         inputs.append(si)
    482 
    483     return orig_function(inputs, cloned_outputs, mode,
    484                          accept_inplace=accept_inplace, name=name,
    485                          profile=profile, on_unused_input=on_unused_input,
--> 486                          output_keys=output_keys)
        output_keys = None
    487 
    488 
    489 def _pfunc_param_to_in(param, strict=False, allow_downcast=None):
    490     if isinstance(param, Constant):

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in orig_function(inputs=[], outputs=Out(Elemwise{sub,no_inplace}.0,False), mode=<theano.compile.mode.Mode object>, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', profile=None, on_unused_input=None, output_keys=None)
   1789                    outputs,
   1790                    mode,
   1791                    accept_inplace=accept_inplace,
   1792                    profile=profile,
   1793                    on_unused_input=on_unused_input,
-> 1794                    output_keys=output_keys).create(
        output_keys = None
        output_keys.create = undefined
   1795             defaults)
   1796 
   1797     t2 = time.time()
   1798     if profile:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in __init__(self=<theano.compile.function_module.FunctionMaker object>, inputs=[], outputs=[Out(Elemwise{sub,no_inplace}.0,False)], mode=<theano.compile.mode.Mode object>, accept_inplace=False, function_builder=<class 'theano.compile.function_module.Function'>, profile=None, on_unused_input=None, fgraph=None, output_keys=None)
   1441         if fgraph is None:
   1442             need_opt = True
   1443             # make the fgraph (copies the graph, creates NEW INPUT AND
   1444             # OUTPUT VARIABLES)
   1445             fgraph, additional_outputs = std_fgraph(inputs, outputs,
-> 1446                                                     accept_inplace)
        accept_inplace = False
   1447             fgraph.profile = profile
   1448         else:
   1449             # fgraph is already an optimized one
   1450             need_opt = False

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in std_fgraph(input_specs=[], output_specs=[Out(Elemwise{sub,no_inplace}.0,False)], accept_inplace=False)
    172             out_idx += 1
    173 
    174     orig_outputs = [spec.variable for spec in output_specs] + updates
    175 
    176     fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,
--> 177                                   update_mapping=update_mapping)
        update_mapping = {}
    178 
    179     for node in fgraph.apply_nodes:
    180         if getattr(node.op, 'destroy_map', None):
    181             if not accept_inplace:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __init__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], inputs=[], outputs=[Elemwise{sub,no_inplace}.0], features=[], clone=True, update_mapping={})
    175                                  "input's owner or use graph.clone.")
    176             self.__setup_r__(input)
    177             self.variables.add(input)
    178 
    179         for output in outputs:
--> 180             self.__import_r__(output, reason="init")
        self.__import_r__ = <bound method FunctionGraph.__import_r__ of [Ele...(TensorConstant{130}, TensorConstant{120.0}))))]>
        output = Elemwise{sub,no_inplace}.0
    181         for i, output in enumerate(outputs):
    182             output.clients.append(('output', i))
    183 
    184         self.profile = None

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import_r__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], variable=Elemwise{sub,no_inplace}.0, reason='init')
    346         reason
    347             reason is the name of the optimization or operation in progress.
    348         """
    349         # Imports the owners of the variables
    350         if variable.owner and variable.owner not in self.apply_nodes:
--> 351                 self.__import__(variable.owner, reason=reason)
        self.__import__ = <bound method FunctionGraph.__import__ of [Elemw...(TensorConstant{130}, TensorConstant{120.0}))))]>
        variable.owner = Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0)
        reason = 'init'
    352         elif (variable.owner is None and
    353                 not isinstance(variable, graph.Constant) and
    354                 variable not in self.inputs):
    355             global NullType

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], apply_node=Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0), check=True, reason='init')
    392                                      "provided and not given a value. Use the "
    393                                      "Theano flag exception_verbosity='high', "
    394                                      "for more information on this error."
    395                                      % (node.inputs.index(r), str(node)))
    396                         error_msg += get_variable_trace_string(r)
--> 397                         raise MissingInputError(error_msg, variable=r)
        error_msg = "Input 0 of the graph (indices start from 0), use...osity='high', for more information on this error."
        r = t1_interval__
    398 
    399         for node in new_nodes:
    400             assert node not in self.apply_nodes
    401             self.__setup_node__(node)

MissingInputError: Input 0 of the graph (indices start from 0), used to compute sigmoid(t1_interval__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
___________________________________________________________________________

During handling of the above exception, another exception occurred:

JoblibMissingInputError                   Traceback (most recent call last)
<ipython-input-34-0c062e078a92> in <module>()
      1 with model:
----> 2     tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs = 2, start = {'t1': 25.0, 't2': 120.0})
      3 

/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain, njobs, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, **kwargs)
    257         sample_func = _sample
    258 
--> 259     return sample_func(**sample_args)
    260 
    261 

/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _mp_sample(**kwargs)
    441                                                      random_seed=rseed[i],
    442                                                      start=start_vals[i],
--> 443                                                      **kwargs) for i in range(njobs))
    444     return merge_traces(traces)
    445 

/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in __call__(self, iterable)
    766                 # consumption.
    767                 self._iterating = False
--> 768             self.retrieve()
    769             # Make sure that we get a last message telling us we are done
    770             elapsed_time = time.time() - self._start_time

/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in retrieve(self)
    717                     ensure_ready = self._managed_backend
    718                     backend.abort_everything(ensure_ready=ensure_ready)
--> 719                 raise exception
    720 
    721     def __call__(self, iterable):

JoblibMissingInputError: JoblibMissingInputError
___________________________________________________________________________
Multiprocessing exception:
...........................................................................
/home/narendra/anaconda3/bin/ipython in <module>()
      1 #!/home/narendra/anaconda3/bin/python
      2 if __name__ == '__main__':
      3     import sys
      4     import IPython
      5 
----> 6     sys.exit(IPython.start_ipython())
      7 
      8 
      9 
     10 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/__init__.py in start_ipython(argv=None, **kwargs={})
    114     kwargs : various, optional
    115         Any other kwargs will be passed to the Application constructor,
    116         such as `config`.
    117     """
    118     from IPython.terminal.ipapp import launch_new_instance
--> 119     return launch_new_instance(argv=argv, **kwargs)
        launch_new_instance = <bound method Application.launch_instance of <class 'IPython.terminal.ipapp.TerminalIPythonApp'>>
        argv = None
        kwargs = {}
    120 
    121 def start_kernel(argv=None, **kwargs):
    122     """Launch a normal IPython kernel instance (as opposed to embedded)
    123     

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py in launch_instance(cls=<class 'IPython.terminal.ipapp.TerminalIPythonApp'>, argv=None, **kwargs={})
    653 
    654         If a global instance already exists, this reinitializes and starts it
    655         """
    656         app = cls.instance(**kwargs)
    657         app.initialize(argv)
--> 658         app.start()
        app.start = <bound method TerminalIPythonApp.start of <IPython.terminal.ipapp.TerminalIPythonApp object>>
    659 
    660 #-----------------------------------------------------------------------------
    661 # utility functions, for convenience
    662 #-----------------------------------------------------------------------------

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/terminal/ipapp.py in start(self=<IPython.terminal.ipapp.TerminalIPythonApp object>)
    343         if self.subapp is not None:
    344             return self.subapp.start()
    345         # perform any prexec steps:
    346         if self.interact:
    347             self.log.debug("Starting IPython's mainloop...")
--> 348             self.shell.mainloop()
        self.shell.mainloop = <bound method TerminalInteractiveShell.mainloop ...nteractiveshell.TerminalInteractiveShell object>>
    349         else:
    350             self.log.debug("IPython not interactive...")
    351 
    352 def load_default_config(ipython_dir=None):

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py in mainloop(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=<object object>)
    435         # out of our internal code.
    436         if display_banner is not DISPLAY_BANNER_DEPRECATED:
    437             warn('mainloop `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.', DeprecationWarning, stacklevel=2)
    438         while True:
    439             try:
--> 440                 self.interact()
        self.interact = <bound method TerminalInteractiveShell.interact ...nteractiveshell.TerminalInteractiveShell object>>
    441                 break
    442             except KeyboardInterrupt:
    443                 print("\nKeyboardInterrupt escaped interact()\n")
    444 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py in interact(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=<object object>)
    426                         or self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'):
    427                     self.ask_exit()
    428 
    429             else:
    430                 if code:
--> 431                     self.run_cell(code, store_history=True)
        self.run_cell = <bound method InteractiveShell.run_cell of <IPyt...nteractiveshell.TerminalInteractiveShell object>>
        code = "with model:\n    tr = pm.sample(500000, init = No...jobs = 2, start = {'t1': 25.0, 't2': 120.0})\n    "
    432 
    433     def mainloop(self, display_banner=DISPLAY_BANNER_DEPRECATED):
    434         # An extra layer of protection in case someone mashing Ctrl-C breaks
    435         # out of our internal code.

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, raw_cell="with model:\n    tr = pm.sample(500000, init = No...jobs = 2, start = {'t1': 25.0, 't2': 120.0})\n    ", store_history=True, silent=False, shell_futures=True)
   2712                 self.displayhook.exec_result = result
   2713 
   2714                 # Execute the user code
   2715                 interactivity = "none" if silent else self.ast_node_interactivity
   2716                 has_raised = self.run_ast_nodes(code_ast.body, cell_name,
-> 2717                    interactivity=interactivity, compiler=compiler, result=result)
        interactivity = 'last_expr'
        compiler = <IPython.core.compilerop.CachingCompiler object>
   2718                 
   2719                 self.last_execution_succeeded = not has_raised
   2720 
   2721                 # Reset this so later displayed values do not modify the

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_ast_nodes(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, nodelist=[<_ast.With object>], cell_name='<ipython-input-34-0c062e078a92>', interactivity='none', compiler=<IPython.core.compilerop.CachingCompiler object>, result=<ExecutionResult object at 7f690b963d68, executi..._before_exec=None error_in_exec=None result=None>)
   2816 
   2817         try:
   2818             for i, node in enumerate(to_run_exec):
   2819                 mod = ast.Module([node])
   2820                 code = compiler(mod, cell_name, "exec")
-> 2821                 if self.run_code(code, result):
        self.run_code = <bound method InteractiveShell.run_code of <IPyt...nteractiveshell.TerminalInteractiveShell object>>
        code = <code object <module> at 0x7f690a0fd150, file "<ipython-input-34-0c062e078a92>", line 1>
        result = <ExecutionResult object at 7f690b963d68, executi..._before_exec=None error_in_exec=None result=None>
   2822                     return True
   2823 
   2824             for i, node in enumerate(to_run_interactive):
   2825                 mod = ast.Interactive([node])

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_code(self=<IPython.terminal.interactiveshell.TerminalInteractiveShell object>, code_obj=<code object <module> at 0x7f690a0fd150, file "<ipython-input-34-0c062e078a92>", line 1>, result=<ExecutionResult object at 7f690b963d68, executi..._before_exec=None error_in_exec=None result=None>)
   2876         outflag = 1  # happens in more places, so it's easier as default
   2877         try:
   2878             try:
   2879                 self.hooks.pre_run_code_hook()
   2880                 #rprint('Running code', repr(code_obj)) # dbg
-> 2881                 exec(code_obj, self.user_global_ns, self.user_ns)
        code_obj = <code object <module> at 0x7f690a0fd150, file "<ipython-input-34-0c062e078a92>", line 1>
        self.user_global_ns = {'In': ['', "get_ipython().magic('cd Desktop/')", "get_ipython().magic('ls ')", 'import numpy as np', 'import pymc3 as pm', 'import theano.tensor as tt', "set1 = np.load('set1.npy')", "set2 = np.load('set2.npy')", "data = np.load('data.npy')", 'data.shape', "get_ipython().magic('paste')", "with model:\n    tr = pm.sample(500000, init = No...jobs = 2, start = {'t1': 25.0, 't2': 120.0})\n    ", 't1.tag.test_value', 't2.tag.test_value', 'with model:\n    tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs = 2)\n    ', "with pm.Model() as model:\n    p = pm.Dirichlet('p', np.ones(17), shape = (7, 17))\n    ", "with model:\n    t1 = pm.Uniform('t1', lower = 20...', lower = t1 + 10, upper = 130, shape = 32)\n    ", 'with model:\n    states1 = tt.switch(t1 >= np.rep... 32, axis = 1), states1, palatability[2, :])\n    ', 'x = np.arange(2000)', 'y = 10*x + 10 + np.random.random(2000)', ...], 'Out': {9: (32, 150), 12: array([ 40.,  40.,  40.,  40.,  40.,  40.,  40.,...  40.,  40.,  40.,  40.,  40.,  40.,  40.,  40.]), 13: array([ 95.,  95.,  95.,  95.,  95.,  95.,  95.,...  95.,  95.,  95.,  95.,  95.,  95.,  95.,  95.]), 21: [<matplotlib.lines.Line2D object>], 24: [<matplotlib.lines.Line2D object>], 27: (2000,), 28: (2000,), 31: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2]), 32: array([5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,...4, 4, 4, 4, 4,
       4, 3, 3, 3, 3, 3, 3, 3, 3])}, '_': array([5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,...4, 4, 4, 4, 4,
       4, 3, 3, 3, 3, 3, 3, 3, 3]), '_12': array([ 40.,  40.,  40.,  40.,  40.,  40.,  40.,...  40.,  40.,  40.,  40.,  40.,  40.,  40.,  40.]), '_13': array([ 95.,  95.,  95.,  95.,  95.,  95.,  95.,...  95.,  95.,  95.,  95.,  95.,  95.,  95.,  95.]), '_21': [<matplotlib.lines.Line2D object>], '_24': [<matplotlib.lines.Line2D object>], '_27': (2000,), '_28': (2000,), '_31': array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2]), ...}
        self.user_ns = {'In': ['', "get_ipython().magic('cd Desktop/')", "get_ipython().magic('ls ')", 'import numpy as np', 'import pymc3 as pm', 'import theano.tensor as tt', "set1 = np.load('set1.npy')", "set2 = np.load('set2.npy')", "data = np.load('data.npy')", 'data.shape', "get_ipython().magic('paste')", "with model:\n    tr = pm.sample(500000, init = No...jobs = 2, start = {'t1': 25.0, 't2': 120.0})\n    ", 't1.tag.test_value', 't2.tag.test_value', 'with model:\n    tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs = 2)\n    ', "with pm.Model() as model:\n    p = pm.Dirichlet('p', np.ones(17), shape = (7, 17))\n    ", "with model:\n    t1 = pm.Uniform('t1', lower = 20...', lower = t1 + 10, upper = 130, shape = 32)\n    ", 'with model:\n    states1 = tt.switch(t1 >= np.rep... 32, axis = 1), states1, palatability[2, :])\n    ', 'x = np.arange(2000)', 'y = 10*x + 10 + np.random.random(2000)', ...], 'Out': {9: (32, 150), 12: array([ 40.,  40.,  40.,  40.,  40.,  40.,  40.,...  40.,  40.,  40.,  40.,  40.,  40.,  40.,  40.]), 13: array([ 95.,  95.,  95.,  95.,  95.,  95.,  95.,...  95.,  95.,  95.,  95.,  95.,  95.,  95.,  95.]), 21: [<matplotlib.lines.Line2D object>], 24: [<matplotlib.lines.Line2D object>], 27: (2000,), 28: (2000,), 31: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2]), 32: array([5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,...4, 4, 4, 4, 4,
       4, 3, 3, 3, 3, 3, 3, 3, 3])}, '_': array([5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,...4, 4, 4, 4, 4,
       4, 3, 3, 3, 3, 3, 3, 3, 3]), '_12': array([ 40.,  40.,  40.,  40.,  40.,  40.,  40.,...  40.,  40.,  40.,  40.,  40.,  40.,  40.,  40.]), '_13': array([ 95.,  95.,  95.,  95.,  95.,  95.,  95.,...  95.,  95.,  95.,  95.,  95.,  95.,  95.,  95.]), '_21': [<matplotlib.lines.Line2D object>], '_24': [<matplotlib.lines.Line2D object>], '_27': (2000,), '_28': (2000,), '_31': array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2]), ...}
   2882             finally:
   2883                 # Reset our crash handler in place
   2884                 sys.excepthook = old_excepthook
   2885         except SystemExit as e:

...........................................................................
/home/narendra/Desktop/<ipython-input-34-0c062e078a92> in <module>()
      1 
----> 2 
      3 
      4 
      5 with model:
      6     tr = pm.sample(500000, init = None, step = pm.Metropolis(), njobs = 2, start = {'t1': 25.0, 't2': 120.0})
      7     
      8 
      9 
     10 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, init=None, n_init=200000, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, njobs=2, tune=None, nuts_kwargs=None, step_kwargs=None, progressbar=True, model=<pymc3.model.Model object>, random_seed=-1, live_plot=False, **kwargs={})
    254         sample_func = _mp_sample
    255         sample_args['njobs'] = njobs
    256     else:
    257         sample_func = _sample
    258 
--> 259     return sample_func(**sample_args)
        sample_func = <function _mp_sample>
        sample_args = {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'njobs': 2, 'progressbar': True, 'random_seed': -1, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, ...}
    260 
    261 
    262 def _sample(draws, step=None, start=None, trace=None, chain=0, tune=None,
    263             progressbar=True, model=None, random_seed=-1, live_plot=False,

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _mp_sample(**kwargs={'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None})
    438     pbars = [kwargs.pop('progressbar')] + [False] * (njobs - 1)
    439     traces = Parallel(n_jobs=njobs)(delayed(_sample)(chain=chains[i],
    440                                                      progressbar=pbars[i],
    441                                                      random_seed=rseed[i],
    442                                                      start=start_vals[i],
--> 443                                                      **kwargs) for i in range(njobs))
        kwargs = {'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None}
        njobs = 2
    444     return merge_traces(traces)
    445 
    446 
    447 def stop_tuning(step):

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in __call__(self=Parallel(n_jobs=2), iterable=<generator object _mp_sample.<locals>.<genexpr>>)
    763             if pre_dispatch == "all" or n_jobs == 1:
    764                 # The iterable was consumed all at once by the above for loop.
    765                 # No need to wait for async callbacks to trigger to
    766                 # consumption.
    767                 self._iterating = False
--> 768             self.retrieve()
        self.retrieve = <bound method Parallel.retrieve of Parallel(n_jobs=2)>
    769             # Make sure that we get a last message telling us we are done
    770             elapsed_time = time.time() - self._start_time
    771             self._print('Done %3i out of %3i | elapsed: %s finished',
    772                         (len(self._output), len(self._output),

---------------------------------------------------------------------------
Sub-process traceback:
---------------------------------------------------------------------------
MissingInputError                                  Tue May  2 13:25:22 2017
PID: 26681                Python 3.6.0: /home/narendra/anaconda3/bin/python
...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in __call__(self=<joblib.parallel.BatchedCalls object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        self.items = [(<function _sample>, (), {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None})]
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/joblib/parallel.py in <listcomp>(.0=<list_iterator object>)
    126     def __init__(self, iterator_slice):
    127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
        func = <function _sample>
        args = ()
        kwargs = {'chain': 0, 'draws': 500000, 'live_plot': False, 'model': <pymc3.model.Model object>, 'progressbar': True, 'random_seed': 442901656, 'start': {'t1': 25.0, 't2': 120.0}, 'step': <pymc3.step_methods.compound.CompoundStep object>, 'trace': None, 'tune': None}
    132 
    133     def __len__(self):
    134         return self._size
    135 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, progressbar=True, model=<pymc3.model.Model object>, random_seed=442901656, live_plot=False, **kwargs={})
    269                             tune, model, random_seed)
    270     if progressbar:
    271         sampling = tqdm(sampling, total=draws)
    272     try:
    273         strace = None
--> 274         for it, strace in enumerate(sampling):
        it = undefined
        strace = None
        sampling =   0%|                                                | 0/500000 [00:00<?, ?it/s]
    275             if live_plot:
    276                 if it >= skip_first:
    277                     trace = MultiTrace([strace])
    278                     if it == skip_first:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/tqdm/_tqdm.py in __iter__(self=  0%|                                                | 0/500000 [00:00<?, ?it/s])
    828             except AttributeError:
    829                 raise TqdmDeprecationWarning("""\
    830 Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
    831 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    832 
--> 833             for obj in iterable:
        obj = undefined
        iterable = <generator object _iter_sample>
    834                 yield obj
    835                 # Update and print the progressbar.
    836                 # Note: does not call self.update(1) for speed optimisation.
    837                 n += 1

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _iter_sample(draws=500000, step=<pymc3.step_methods.compound.CompoundStep object>, start={'t1': 25.0, 't2': 120.0}, trace=None, chain=0, tune=None, model=<pymc3.model.Model object>, random_seed=442901656)
    346     strace = _choose_backend(trace, chain, model=model)
    347 
    348     if len(strace) > 0:
    349         _update_start_vals(start, strace.point(-1), model)
    350     else:
--> 351         _update_start_vals(start, model.test_point, model)
        start = {'t1': 25.0, 't2': 120.0}
        model.test_point = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.]), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        model = <pymc3.model.Model object>
    352 
    353     try:
    354         step = CompoundStep(step)
    355     except TypeError:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in _update_start_vals(a={'t1': 25.0, 't2': 120.0}, b={'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}, model=<pymc3.model.Model object>)
    462     for name in a:
    463         for tname in b:
    464             if is_transformed_name(tname) and get_untransformed_name(tname) == name:
    465                 transform_func = [d.transformation for d in model.deterministics if d.name == name]
    466                 if transform_func:
--> 467                     b[tname] = transform_func[0].forward(a[name]).eval()
        b = {'p_stickbreaking__': array([[  0.00000000e+00,   0.00000000e+00,   0....00,   3.33066907e-16,
          0.00000000e+00]]), 't1_interval__': array(-1.9459102153778076, dtype=float32), 't2_interval__': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  ...,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.])}
        tname = 't2_interval__'
        transform_func.forward = undefined
        a = {'t1': 25.0, 't2': 120.0}
    468 
    469     a.update({k: v for k, v in b.items() if k not in a})
    470 
    471 def sample_ppc(trace, samples=None, model=None, vars=None, size=None,

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/graph.py in eval(self=Elemwise{sub,no_inplace}.0, inputs_to_values={})
    511         if not hasattr(self, '_fn_cache'):
    512             self._fn_cache = dict()
    513 
    514         inputs = tuple(sorted(inputs_to_values.keys(), key=id))
    515         if inputs not in self._fn_cache:
--> 516             self._fn_cache[inputs] = theano.function(inputs, self)
        self._fn_cache = {}
        inputs = ()
        self = Elemwise{sub,no_inplace}.0
    517         args = [inputs_to_values[param] for param in inputs]
    518 
    519         rval = self._fn_cache[inputs](*args)
    520 

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function.py in function(inputs=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None)
    321                    accept_inplace=accept_inplace, name=name,
    322                    rebuild_strict=rebuild_strict,
    323                    allow_input_downcast=allow_input_downcast,
    324                    on_unused_input=on_unused_input,
    325                    profile=profile,
--> 326                    output_keys=output_keys)
        output_keys = None
    327     # We need to add the flag check_aliased inputs if we have any mutable or
    328     # borrowed used defined inputs
    329     fn._check_for_aliased_inputs = check_for_aliased_inputs
    330     return fn

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py in pfunc(params=(), outputs=Elemwise{sub,no_inplace}.0, mode=None, updates=[], givens=[], no_default_updates=False, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', rebuild_strict=True, allow_input_downcast=None, profile=None, on_unused_input=None, output_keys=None)
    481         inputs.append(si)
    482 
    483     return orig_function(inputs, cloned_outputs, mode,
    484                          accept_inplace=accept_inplace, name=name,
    485                          profile=profile, on_unused_input=on_unused_input,
--> 486                          output_keys=output_keys)
        output_keys = None
    487 
    488 
    489 def _pfunc_param_to_in(param, strict=False, allow_downcast=None):
    490     if isinstance(param, Constant):

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in orig_function(inputs=[], outputs=Out(Elemwise{sub,no_inplace}.0,False), mode=<theano.compile.mode.Mode object>, accept_inplace=False, name='/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py:467', profile=None, on_unused_input=None, output_keys=None)
   1789                    outputs,
   1790                    mode,
   1791                    accept_inplace=accept_inplace,
   1792                    profile=profile,
   1793                    on_unused_input=on_unused_input,
-> 1794                    output_keys=output_keys).create(
        output_keys = None
        output_keys.create = undefined
   1795             defaults)
   1796 
   1797     t2 = time.time()
   1798     if profile:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in __init__(self=<theano.compile.function_module.FunctionMaker object>, inputs=[], outputs=[Out(Elemwise{sub,no_inplace}.0,False)], mode=<theano.compile.mode.Mode object>, accept_inplace=False, function_builder=<class 'theano.compile.function_module.Function'>, profile=None, on_unused_input=None, fgraph=None, output_keys=None)
   1441         if fgraph is None:
   1442             need_opt = True
   1443             # make the fgraph (copies the graph, creates NEW INPUT AND
   1444             # OUTPUT VARIABLES)
   1445             fgraph, additional_outputs = std_fgraph(inputs, outputs,
-> 1446                                                     accept_inplace)
        accept_inplace = False
   1447             fgraph.profile = profile
   1448         else:
   1449             # fgraph is already an optimized one
   1450             need_opt = False

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/compile/function_module.py in std_fgraph(input_specs=[], output_specs=[Out(Elemwise{sub,no_inplace}.0,False)], accept_inplace=False)
    172             out_idx += 1
    173 
    174     orig_outputs = [spec.variable for spec in output_specs] + updates
    175 
    176     fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,
--> 177                                   update_mapping=update_mapping)
        update_mapping = {}
    178 
    179     for node in fgraph.apply_nodes:
    180         if getattr(node.op, 'destroy_map', None):
    181             if not accept_inplace:

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __init__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], inputs=[], outputs=[Elemwise{sub,no_inplace}.0], features=[], clone=True, update_mapping={})
    175                                  "input's owner or use graph.clone.")
    176             self.__setup_r__(input)
    177             self.variables.add(input)
    178 
    179         for output in outputs:
--> 180             self.__import_r__(output, reason="init")
        self.__import_r__ = <bound method FunctionGraph.__import_r__ of [Ele...(TensorConstant{130}, TensorConstant{120.0}))))]>
        output = Elemwise{sub,no_inplace}.0
    181         for i, output in enumerate(outputs):
    182             output.clients.append(('output', i))
    183 
    184         self.profile = None

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import_r__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], variable=Elemwise{sub,no_inplace}.0, reason='init')
    346         reason
    347             reason is the name of the optimization or operation in progress.
    348         """
    349         # Imports the owners of the variables
    350         if variable.owner and variable.owner not in self.apply_nodes:
--> 351                 self.__import__(variable.owner, reason=reason)
        self.__import__ = <bound method FunctionGraph.__import__ of [Elemw...(TensorConstant{130}, TensorConstant{120.0}))))]>
        variable.owner = Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0)
        reason = 'init'
    352         elif (variable.owner is None and
    353                 not isinstance(variable, graph.Constant) and
    354                 variable not in self.inputs):
    355             global NullType

...........................................................................
/home/narendra/anaconda3/lib/python3.6/site-packages/theano/gof/fg.py in __import__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{130}, TensorConstant{120.0}))))], apply_node=Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0), check=True, reason='init')
    392                                      "provided and not given a value. Use the "
    393                                      "Theano flag exception_verbosity='high', "
    394                                      "for more information on this error."
    395                                      % (node.inputs.index(r), str(node)))
    396                         error_msg += get_variable_trace_string(r)
--> 397                         raise MissingInputError(error_msg, variable=r)
        error_msg = "Input 0 of the graph (indices start from 0), use...osity='high', for more information on this error."
        r = t1_interval__
    398 
    399         for node in new_nodes:
    400             assert node not in self.apply_nodes
    401             self.__setup_node__(node)

MissingInputError: Input 0 of the graph (indices start from 0), used to compute sigmoid(t1_interval__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
___________________________________________________________________________

Same model, sampled without the start argument:

In [36]: with model:
    ...:     tr = pm.sample(5000, init = None, step = pm.Metropolis(), njobs = 2)
    ...:     
100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 5000/5000 [00:12<00:00, 412.09it/s]

@ferrine
Copy link
Member

ferrine commented May 2, 2017

That's for sure a bug in ADVI start kwarg.

@ferrine
Copy link
Member

ferrine commented May 2, 2017

Hm wait. You use metropolis and no init. That's another problem

@ferrine
Copy link
Member

ferrine commented May 3, 2017

Could you please provide minimal failing example? I was not able to reproduce the error on a simple model

twiecki pushed a commit that referenced this issue May 4, 2017
@twiecki
Copy link
Member

twiecki commented May 4, 2017

@narendramukherjee Can you try if #2109 (now on master) fixed this for you?

@narendramukherjee
Copy link
Author

Hi guys,

Thanks for the responses. Although, a simple linear regression fit with Metropolis doesn't give this error, I have reproduced it with a simple test case for the kind of model I am fitting. I am using the latest pymc3 version from master, and here's the versions again:

In [41]: pm.__version__
Out[41]: '3.1rc3'

In [42]: theano.__version__
Out[42]: '0.9.0'

Here's the minimal example - the dataset has categorical emissions (0, 1, or 2) with probabilities that change twice - once at 100 samples and again at 200 samples. There are 2 trials of the data, each has 300 samples, and both of them change emission probabilities at 100 and 200 samples

import numpy as np
import pymc3 as pm
import theano.tensor as tt

# Data has 2 trials/independent runs, each with 300 observations (which can be 0, 1 or 2)
data = np.zeros((2,300))
data[0, :100] = np.random.choice(np.arange(3), size = 100, p = [1/3, 1/3, 1/3])
data[0, 100:200] = np.random.choice(np.arange(3), size = 100, p =  [1/6, 2/3, 1/6])
data[0, 200:] = np.random.choice(np.arange(3), size = 100, p = [1/3, 1/3, 1/3])
data[1, :100] = np.random.choice(np.arange(3), size = 100, p =  [1/3, 1/3, 1/3])
data[1, 100:200] = np.random.choice(np.arange(3), size = 100, p =  [1/6, 2/3, 1/6])
data[1, 200:] = np.random.choice(np.arange(3), size = 100, p =  [1/3, 1/3, 1/3])

And here's my model:

with pm.Model() as model:
	# Dirichlet prior for emission probabilities, 3 emission 'states', each with 3 types of emissions (0, 1, 2)
	p = pm.Dirichlet('p', np.ones(3), shape = (3, 3))

	# Uniform prior on switchpoints
	t1 = pm.Uniform('t1', lower = 30, upper = 130, shape = 2)
	t2 = pm.Uniform('t2', lower = t1 + 20, upper = 230, shape = 2)

	# State numbers from the switchpoints
	states1 = tt.switch(t1 >= np.repeat(np.arange(300)[:, None], 2, axis = 1), 0, 1)
	states2 = tt.switch(t2 >= np.repeat(np.arange(300)[:, None], 2, axis = 1), states1, 2)

with model:
	# Log likelihood
	def logp(value):
		value = tt.cast(value, 'int32')
		loglik = tt.sum(tt.log(p[states2.T, value]))
		return loglik

with model:
	# Categorical emissions
	obs = pm.DensityDist('obs', logp, observed = {'value': data})

with model:
	# Sampling with 'start' specified, only works if 'start' is not specified
	tr = pm.sample(5000, init = None, step = pm.Metropolis(), njobs = 2, start = {'t1': 50.0, 't2': 150.0})

This model works fine if the 'start' argument isn't specified (I am sampling with init = None with Metropolis). However, if I specify the 'start' argument (as in the model above), sampling fails with the same error as previously (I have pasted the last part here again).

home/narendra/anaconda3/lib/python3.6/site-packages/Theano-0.9.0-py3.6.egg/theano/gof/fg.py in __import__(self=[Elemwise{sub,no_inplace}(Elemwise{log,no_inplac...}(TensorConstant{230}, TensorConstant{150.0}))))], apply_node=Elemwise{sub,no_inplace}(Elemwise{log,no_inplace}.0, InplaceDimShuffle{x}.0), check=True, reason='init')
    392                                      "provided and not given a value. Use the "
    393                                      "Theano flag exception_verbosity='high', "
    394                                      "for more information on this error."
    395                                      % (node.inputs.index(r), str(node)))
    396                         error_msg += get_variable_trace_string(r)
--> 397                         raise MissingInputError(error_msg, variable=r)
        error_msg = "Input 0 of the graph (indices start from 0), use...osity='high', for more information on this error."
        r = t1_interval__
    398 
    399         for node in new_nodes:
    400             assert node not in self.apply_nodes
    401             self.__setup_node__(node)

MissingInputError: Input 0 of the graph (indices start from 0), used to compute sigmoid(t1_interval__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
___________________________________________________________________________


@narendramukherjee
Copy link
Author

Just adding to my previous post - downgrading to the stable version of pymc3 (3.0) with the same theano version (0.9) allows this code to work with the 'start' argument specified. It seems like something's breaking down in the new development version.

In [1]: import pymc3 as pm

In [2]: import theano

In [3]: pm.__version__
Out[3]: '3.0'

In [4]: theano.__version__
Out[4]: '0.9.0'

In [5]: %paste
import numpy as np
import pymc3 as pm
import theano.tensor as tt

# Data has 2 trials/independent runs, each with 300 observations (which can be 0, 1 or 2)
data = np.zeros((2,300))
data[0, :100] = np.random.choice(np.arange(3), size = 100, p = [1/3, 1/3, 1/3])
data[0, 100:200] = np.random.choice(np.arange(3), size = 100, p =  [1/6, 2/3, 1/6])
data[0, 200:] = np.random.choice(np.arange(3), size = 100, p = [1/3, 1/3, 1/3])
data[1, :100] = np.random.choice(np.arange(3), size = 100, p =  [1/3, 1/3, 1/3])
data[1, 100:200] = np.random.choice(np.arange(3), size = 100, p =  [1/6, 2/3, 1/6])
data[1, 200:] = np.random.choice(np.arange(3), size = 100, p =  [1/3, 1/3, 1/3])

with pm.Model() as model:
        # Dirichlet prior for emission probabilities, 3 emission 'states', each with 3 types of emissions (0, 1, 2)
        p = pm.Dirichlet('p', np.ones(3), shape = (3, 3))

        # Uniform prior on switchpoints
        t1 = pm.Uniform('t1', lower = 30, upper = 130, shape = 2)
        t2 = pm.Uniform('t2', lower = t1 + 20, upper = 230, shape = 2)

        # State numbers from the switchpoints
        states1 = tt.switch(t1 >= np.repeat(np.arange(300)[:, None], 2, axis = 1), 0, 1)
        states2 = tt.switch(t2 >= np.repeat(np.arange(300)[:, None], 2, axis = 1), states1, 2)

with model:
        # Log likelihood
        def logp(value):
                value = tt.cast(value, 'int32')
                loglik = tt.sum(tt.log(p[states2.T, value]))
                return loglik

with model:
        # Categorical emissions
        obs = pm.DensityDist('obs', logp, observed = {'value': data})

## -- End pasted text --

In [6]: %paste
with model:
        # Sampling with 'start' specified
        tr = pm.sample(5000, init = None, step = pm.Metropolis(), njobs = 2, start = {'t1': 50.0, 't2': 150.0})

## -- End pasted text --
100%|██████████████████████████████████████| 5000/5000 [00:06<00:00, 718.67it/s]

In [7]: 

@junpenglao
Copy link
Member

The problem is _update_start_vals trying to evaluate a function which depends
on a parent https://github.com/pymc-devs/pymc3/blob/master/pymc3/sampling.py#L468
In this case,

t2 = pm.Uniform('t2', lower = t1 + 20, upper = 230, shape = 2)

is depends on

t1 = pm.Uniform('t1', lower = 30, upper = 130, shape = 2)

but the point value of t1 is not pass to the transform_func[0].forward(a[name]).eval()

@narendramukherjee
Copy link
Author

@junpenglao - was just wondering what the status of this issue was. Did this get fixed? Thanks for your help!

@junpenglao
Copy link
Member

Not yet, for now, you need to pass the transformed variable to start value.
For example, if you want to do:

    a = pm.Uniform('a', lower=0., upper=1.)
    b = pm.Uniform('b', lower=0., upper=1. - a1)
    start = {'a': .5, 'b':.3}

you need to transform the a and b using np.log(value - lower) - np.log(upper - x):
for a: np.log(.5 - 0.) - np.log(1. - .5) = 0.
for b: np.log(.3 - 0.) - np.log(.5 - .3) = 0.40546510810816416
startnew = {'a1_interval__': 0., 'b1_interval__': 0.40546510810816416}

This was referenced Jun 15, 2017
@junpenglao
Copy link
Member

fixed in #2328

@narendramukherjee
Copy link
Author

@junpenglao @twiecki The current development version (on the master branch of pymc3) still has issues with the minimal example I posted above. As I had said previously, that minimal example works fine with pymc3 3.0 and theano 0.9. Here's the versions I am using right now:

In [17]: theano.__version__
Out[17]: '0.9.0'

In [18]: pm.__version__
Out[18]: '3.1'

Here's the last part of the error that the minimal example I posted above produces (again note, this error doesn't come up if the start argument isn't specified):

/home/narendra/anaconda3/lib/python3.6/site-packages/Theano-0.9.0-py3.6.egg/theano/tensor/type.py in filter(self=TensorType(float64, vector), data=array(-1.3862943611198904), strict=False, allow_downcast=True)
    173                         raise TypeError(err_msg, data)
    174 
    175         if self.ndim != data.ndim:
    176             raise TypeError("Wrong number of dimensions: expected %s,"
    177                             " got %s with shape %s." % (self.ndim, data.ndim,
--> 178                                                         data.shape))
        data.shape = ()
    179         if not data.flags.aligned:
    180             try:
    181                 msg = "object buffer" + str(data.data)
    182             except AttributeError:

TypeError: Bad input argument to theano function with name "/home/narendra/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py:223" at index 0 (0-based). Wrong number of dimensions: expected 1, got 0 with shape ().
___________________________________________________________________________

Works fine without start argument not specified:

In [16]: %paste
with model:
        # Sampling with 'start' specified, only works if 'start' is not specified
        tr = pm.sample(5000, init = None, step = pm.Metropolis(), njobs = 2)

## -- End pasted text --
100%|██████████████████████████████████████| 5500/5500 [00:06<00:00, 829.75it/s]

I also tried the transformation that @junpenglao suggested above. Same error comes up:

In [19]: with model:
    ...:     tr = pm.sample(100000, init = None, step = pm.Metropolis(), njobs =
    ...:  2, trace = [t1, t2], start = {'t1_interval__': np.log(50.0 - 30.0) - n
    ...: p.log(130.0 - 50.0), 't2_interval__': np.log(150.0 - 50.0) - np.log(230
    ...: .0 - 150.0)})
    ...:     
  0%|                                                | 0/100500 [00:00<?, ?it/s]
---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback:

Here's the last part of the error:

/home/narendra/anaconda3/lib/python3.6/site-packages/Theano-0.9.0-py3.6.egg/theano/tensor/type.py in filter(self=TensorType(float64, vector), data=array(-1.3862943611198904), strict=False, allow_downcast=None)
    173                         raise TypeError(err_msg, data)
    174 
    175         if self.ndim != data.ndim:
    176             raise TypeError("Wrong number of dimensions: expected %s,"
    177                             " got %s with shape %s." % (self.ndim, data.ndim,
--> 178                                                         data.shape))
        data.shape = ()
    179         if not data.flags.aligned:
    180             try:
    181                 msg = "object buffer" + str(data.data)
    182             except AttributeError:

TypeError: ('Wrong number of dimensions: expected 1, got 0 with shape ().', 'Container name "t1_interval___shared"')
___________________________________________________________________________

@narendramukherjee
Copy link
Author

Also, should we open the issue again as it looks like it wasn't resolved by the last few commits?

Thanks a ton for all your attempts in trying to fix this!

@junpenglao junpenglao reopened this Aug 1, 2017
@junpenglao
Copy link
Member

Thanks a lot for reporting back!

@junpenglao
Copy link
Member

Hi @narendramukherjee, PyMC3 now perform more rigorous test on the inputs, which is why the starting value you provide is failing: you need to feed the value with the right shape. In your example above, if you change your start value from:

start = {'t1': 50.0, 't2': 150.0}

(incorrect shape, as t1 and t2 has shape=2)
to

start = {'t1': np.ones(2)*50.0, 't2': np.ones(2)*150.0}

It should work. The same also for when you are feeding the transformed start value.

@narendramukherjee
Copy link
Author

Thanks @junpenglao , that does solve the issue :) I am closing the issue, thank you so much for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants