Hi,
I’m trying to use Pymc3 to find the appropriate number of componements used to predict a time serie of concentrations called aCH and aCOH. These are two distincts PLS models. Each model can use between 1 and 20 number of components. The predictions are stored in an ndarray with the time series prediction. aCH_[0,1] would be the predictions using 2 components. Such as:
This is similar for aCOH
The array is then shared with theano such as:
aCH_=theano.shared(aCH_)
aCOH_=theano.shared(aCOH_)
The model that I’m trying to tune is defined as:
OC=b1*aCH+aCOH
Now I tried to define my model with the number of components defined as free random variables from a discrete uniform distribution and the coefficient b1 used to multiply the of aCH prediction is defined as a uniform continuous free random variable.
from scipy import optimize
basic_model = pm.Model()
with basic_model:
# Priors for unknown model parameters
b1 = pm.Uniform('b1', lower=0.3, upper=0.5,testval=0.45).astype('float32')
ncomp_aCH = pm.DiscreteUniform('ncomp_aCH', lower=0, upper=19,testval=10)
ncomp_aCOH = pm.DiscreteUniform('ncomp_aCOH', lower=0, upper=19,testval=10)
aCH=aCH_[0,ncomp_aCH]
aCOH=aCOH_[0,ncomp_aCOH]
out= b1*aCH+aCOH
# Likelihood (sampling distribution) of observations
Y_obs = pm.Normal('Y_obs', mu=out, tau=sigma, observed=Y)
step = pm.Metropolis()
trace = pm.sample(100000, step)
where Y is a vector of true measurements and sigma a vector of my measurements uncertainties.
Now when I run my model I have a index out of bonds error. I also tried to used a Categorical distribution to generate my number of components free random variables as suggested here: Issue with DiscreteUniform distribution.
But I get the same error
Such as (just showing the beginning of the error message as it is very long:
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
“”"
Traceback (most recent call last):
File “C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function_module.py”, line 903, in call
self.fn() if output_subset is None else
IndexError: index out of bounds
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\ProgramData\Anaconda3\lib\site-packages\joblib_parallel_backends.py”, line 350, in call
return self.func(*args, **kwargs)
File “C:\ProgramData\Anaconda3\lib\site-packages\joblib\parallel.py”, line 131, in call
return [func(*args, **kwargs) for func, args, kwargs in self.items]
File “C:\ProgramData\Anaconda3\lib\site-packages\joblib\parallel.py”, line 131, in
return [func(*args, **kwargs) for func, args, kwargs in self.items]
File “C:\ProgramData\Anaconda3\lib\site-packages\pymc3\sampling.py”, line 526, in _sample
for it, strace in enumerate(sampling):
File “C:\ProgramData\Anaconda3\lib\site-packages\tqdm_tqdm.py”, line 959, in iter
for obj in iterable:
File “C:\ProgramData\Anaconda3\lib\site-packages\pymc3\sampling.py”, line 624, in _iter_sample
point, states = step.step(point)
File “C:\ProgramData\Anaconda3\lib\site-packages\pymc3\step_methods\compound.py”, line 24, in step
point, state = method.step(point)
File “C:\ProgramData\Anaconda3\lib\site-packages\pymc3\step_methods\arraystep.py”, line 162, in step
apoint, stats = self.astep(self.bij.map(point))
File “C:\ProgramData\Anaconda3\lib\site-packages\pymc3\step_methods\metropolis.py”, line 162, in astep
accept = self.delta_logp(q, q0)
File “C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function_module.py”, line 917, in call
storage_map=getattr(self.fn, ‘storage_map’, None))
File “C:\ProgramData\Anaconda3\lib\site-packages\theano\gof\link.py”, line 325, in raise_with_op
reraise(exc_type, exc_value, exc_trace)
File “C:\ProgramData\Anaconda3\lib\site-packages\six.py”, line 692, in reraise
raise value.with_traceback(tb)
File “C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function_module.py”, line 903, in call
self.fn() if output_subset is None else
IndexError: index out of bounds
Apply node that caused the error: Subtensor{int64, int64}(<TensorType(float64, 3D)>, Constant{0}, ScalarFromTensor.0)
Toposort index: 11
Inputs types: [TensorType(float64, 3D), Scalar(int64), Scalar(int64)]
Inputs shapes: [(1, 20, 119), (), ()]
Inputs strides: [(19040, 952, 8), (), ()]
Inputs values: [‘not shown’, 0, 21]
Outputs clients: [[Elemwise{Composite{((i0 * sqr((i1 - (i2 + i3)))) + i4)}}(TensorConstant{[-0.372381…29548011]}, TensorConstant{[ 2.449864…74623214]}, Elemwise{mul,no_inplace}.0, Subtensor{int64, int64}.0, TensorConstant{[-2.825712…05703082]})]]
Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
File “C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelbase.py”, line 235, in dispatch_shell
handler(stream, idents, msg)
File “C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\kernelbase.py”, line 399, in execute_request
user_expressions, allow_stdin)
File “C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\ipkernel.py”, line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File “C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\zmqshell.py”, line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File “C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 2698, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File “C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 2802, in run_ast_nodes
if self.run_code(code, result):
File “C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 12, in
aCOH=aCOH_[0,ncomp_aCOH]
HINT: Use the Theano flag ‘exception_verbosity=high’ for a debugprint and storage map footprint of this apply node.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\ProgramData\Anaconda3\lib\multiprocessing\pool.py”, line 119, in worker
result = (True, func(*args, **kwds))
File “C:\ProgramData\Anaconda3\lib\site-packages\joblib_parallel_backends.py”, line 359, in call
raise TransportableException(text, e_type)
joblib.my_exceptions.TransportableException: TransportableException
IndexError Tue Mar 13 11:29:00 2018
PID: 17988 Python 3.6.3: C:\ProgramData\Anaconda3\python.exe
…
C:\ProgramData\Anaconda3\lib\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 = [(, (0, True, 570756469, {'b1_interval_’: array(1.09861229), ‘ncomp_aCH’: array(10, dtype=int64), ‘ncomp_aCOH’: array(10, dtype=int64)}), {‘draws’: 100500, ‘live_plot’: False, ‘live_plot_kwargs’: None, ‘model’: <pymc3.model.Model object>, ‘step’: <pymc3.step_methods.compound.CompoundStep object>, ‘trace’: None, ‘tune’: 500})]
132
133 def len(self):
134 return self._size
135