Ah, okay. So to sample from my gp using pymc3 random variables I need to create a new model? So my overall form would be to define the surrogate model:
with pm.Model() as surrogate_model:
ls = pm.HalfNormal('l',2./3,shape=len(params))
eta = pm.HalfNormal('eta',1.0,shape=1)
cov = eta**2.*pm.gp.cov.ExpQuad(len(params),ls_inv=ls)
sigma = pm.HalfNormal('sigma',1.0)
gp = pm.gp.Marginal(cov_func=cov)
y_ = gp.marginal_likelihood('y',X=X,y=errors,noise=sigma)
trace = pm.sample(1000,tune=1000,njobs=1)
and then define a new model that samples from the gp fit here as:
with pm.Model() as model:
a_ = pm.Normal('a',params[0],0.1*abs(params[0]),shape=1)
b_ = pm.Normal('b',params[1],0.1*abs(params[1]),shape=1)
c_ = pm.Normal('c',params[2],0.1*abs(params[2]),shape=1)
d_ = pm.Normal('d',params[3],0.1*abs(params[3]),shape=1)
params_ = tt.stack([a_,b_,c_,d_],axis=0).reshape([1,4])
sigma = pm.HalfNormal('sigma', 1.)
e_pred = pm.Deterministic('e_pred',gp.predictt(params_)[0])
e = pm.Normal('e', mu=e_pred, sd=sigma, observed=0.)
trace2 = pm.sample(1000,njobs=1)
I can fit the gp with the first model but in the second sampling I get the error:
---------------------------------------------------------------------------
MissingInputError Traceback (most recent call last)
<ipython-input-33-d32336a23b64> in <module>()
13 e = pm.Normal('e', mu=e_pred, sd=sigma, observed=0.)
14
---> 15 trace2 = pm.sample(1000,njobs=1)
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, discard_tuned_samples, live_plot_kwargs, compute_convergence_checks, use_mmap, **kwargs)
393 start_, step = init_nuts(init=init, chains=chains, n_init=n_init,
394 model=model, random_seed=random_seed,
--> 395 progressbar=progressbar, **args)
396 if start is None:
397 start = start_
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\sampling.py in init_nuts(init, chains, n_init, model, random_seed, progressbar, **kwargs)
1386 'Unknown initializer: {}.'.format(init))
1387
-> 1388 step = pm.NUTS(potential=potential, model=model, **kwargs)
1389
1390 return start, step
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\step_methods\hmc\nuts.py in __init__(self, vars, max_treedepth, early_max_treedepth, **kwargs)
150 `pm.sample` to the desired number of tuning steps.
151 """
--> 152 super(NUTS, self).__init__(vars, **kwargs)
153
154 self.max_treedepth = max_treedepth
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\step_methods\hmc\base_hmc.py in __init__(self, vars, scaling, step_scale, is_cov, model, blocked, potential, integrator, dtype, Emax, target_accept, gamma, k, t0, adapt_step_size, step_rand, **theano_kwargs)
61
62 super(BaseHMC, self).__init__(vars, blocked=blocked, model=model,
---> 63 dtype=dtype, **theano_kwargs)
64
65 self.adapt_step_size = adapt_step_size
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\step_methods\arraystep.py in __init__(self, vars, model, blocked, dtype, **theano_kwargs)
213
214 self._logp_dlogp_func = model.logp_dlogp_function(
--> 215 vars, dtype=dtype, **theano_kwargs)
216
217 def step(self, point):
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\model.py in logp_dlogp_function(self, grad_vars, **kwargs)
656 varnames = [var.name for var in grad_vars]
657 extra_vars = [var for var in self.free_RVs if var.name not in varnames]
--> 658 return ValueGradFunction(self.logpt, grad_vars, extra_vars, **kwargs)
659
660 @property
c:\users\natha\onedrive\documents\python3_modules\pymc3\pymc3\model.py in __init__(self, cost, grad_vars, extra_vars, dtype, casting, **kwargs)
403
404 self._theano_function = theano.function(
--> 405 inputs, [self._cost_joined, grad], givens=givens, **kwargs)
406
407 def set_extra_values(self, extra_vars):
~\Anaconda3\lib\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\lib\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\lib\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\lib\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\lib\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\lib\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\lib\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\lib\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 Elemwise{exp,no_inplace}(sigma_log__), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
Sorry to ask so many questions.