VI node sampling with multiple parameters

Hello there!

I’ve been playing a lot with Bayesian neural networks lately and until now I’ve been sampling on a single input like so:

_sample_proba_nn = approx.sample_node(bnn.out.distribution.p,
                                   size = n,
                                   more_replacements = {bnn['bnn_input']: x})

where x and n are theano symbolic matrix and scalar, respectively.

Do any of you know how can I feed this function a tuple on training? Something like:

_sample_proba_nn = approx.sample_node([bnn.out1.distribution.p, bnn.out2.distribution.p]
                                   size = n,
                                   more_replacements = {bnn['bnn_input1']: x1, bnn['bnn_input2']: x2})

I am currently working on a Bayesian siamese network and I’d like to sample on both input streamsat once.

I am much oblidged to any who can shed some light upon this!

cc @ferrine

Hi, you should pass same argument in pm.fit it will be bypassed to this:

I’ve tried using that parameter:

x1 = T.matrix('X')
n1 = T.iscalar('n')
x1.tag.test_value = np.empty_like(X_test1[:100])
n1.tag.test_value = 100

_sample_proba_nn1 = approx.sample_node(bsnn.out1.distribution.p,
                                   size = n1,
                                   more_replacements = {bsnn['bnn_input1']: x1)

But more_replacements is not accepting a dictionary with more than 1 element.

What traceback do you have?

For the following:

_sample_proba_nn1 = approx.sample_node({bsnn.out1.distribution.p, bsnn.out2.distribution.p},
                                   size = n1,
                                   more_replacements = {bsnn['bnn_input1']: x1, 
                                                        bsnn['bnn_input2']: x2})

I get:

TypeError: ('output must be a theano Variable or Out instance (or list of them)', {sigmoid.0, sigmoid.0})

Also getting this when trying to sample:

---------------------------------------------------------------------------

UnusedInputError Traceback (most recent call last)
in
----> 1 sample_proba1 = theano.function([x1, n1], _sample_proba_nn1)
2 # sample_proba2 = theano.function([x2, n2], _sample_proba_nn2)

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

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

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

~/anaconda3/envs/progprob3/lib/python3.7/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)
1472
1473 # Check if some input variables are unused
-> 1474 self._check_unused_inputs(inputs, outputs, on_unused_input)
1475
1476 # Make a list of (SymbolicInput|SymblicInputKits, indices,

~/anaconda3/envs/progprob3/lib/python3.7/site-packages/theano/compile/function_module.py in _check_unused_inputs(self, inputs, outputs, on_unused_input)
1625 elif on_unused_input == ‘raise’:
1626 raise UnusedInputError(msg % (inputs.index(i),
-> 1627 i.variable, err_msg))
1628 else:
1629 raise ValueError("Invalid value for keyword "

UnusedInputError: theano.function was asked to create a function computing outputs given certain inputs, but the provided input variable at index 0 is not part of the computational graph needed to compute the outputs: X.
To make this error into a warning, you can pass the parameter on_unused_input=‘warn’ to theano.function. To disable it completely, use on_unused_input=‘ignore’.

sample_nn1 = sample_proba1(X_test1, 15000)

sample_nn2 = sample_proba2(X_test2, 15000)

In the above snippet (sample_node) you are trying to pass a Set of variables and this what theano complains about. Turn it into a list