import inferpy as inf
import numpy as np
import tensorflow as tf
@inf.probmodel
def pca(k,d):
w = inf.Normal(loc=np.zeros([k,d]), scale=1, name="w") # shape = [k,d]
with inf.datamodel():
z = inf.Normal(np.ones([k]),1, name="z") # shape = [N,k]
x = inf.Normal(z @ w , 1, name="x") # shape = [N,d]
# generate training data
N = 1000
sess = tf.Session()
x_train = np.concatenate([inf.Normal([0.0,0.0], scale=1.).sample(int(N/2)), inf.Normal([10.0,10.0], scale=1.).sample(int(N/2))])
@inf.probmodel
def qmodel(k,d):
qw_loc = inf.Parameter(tf.ones([k,d]), name="qw_loc")
qw_scale = tf.math.softplus(inf.Parameter(tf.ones([k, d]), name="qw_scale"))
qw = inf.Normal(qw_loc, qw_scale, name="w")
with inf.datamodel():
qz_loc = inf.Parameter(tf.ones([k]), name="qz_loc")
qz_scale = tf.math.softplus(inf.Parameter(tf.ones([k]), name="qz_scale"))
qz = inf.Normal(qz_loc, qz_scale, name="z")
# set the inference algorithm
VI = inf.inference.VI(qmodel(k=1,d=2), epochs=1000)
# create an instance of the model
m = pca(k=1,d=2)
# run the inference
m.fit({"x": x_train}, VI)
I get the error:
Traceback (most recent call last):
File "/Users/rcabanas/venv/InferPy/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-8b91a39c8a1e>", line 49, in <module>
m.fit({"x": x_train}, VI)
File "[...]/inferpy/util/runtime.py", line 86, in wrapper
return f(*args, **kwargs)
File "[...]/inferpy/models/prob_model.py", line 199, in fit
inference_method.compile(self, plate_size)
File "[...]/inferpy/inference/variational/vi.py", line 76, in compile
self.train_tensor = self._generate_train_tensor(plate_size=self.plate_size)
File "[...]/inferpy/inference/variational/vi.py", line 133, in _generate_train_tensor
loss_tensor = self.loss_fn(pvars, qvars, **kwargs)
TypeError: ELBO() got an unexpected keyword argument 'plate_size'
When running the following code:
I get the error: