I am not a user of PyMC myself, but recently I stumbled upon this article that showed a snippet of some PyMC model:
def linear_regression(x):
scale = yield tfd.HalfCauchy(0, 1)
coefs = yield tfd.Normal(tf.zeros(x.shape[1]), 1, )
predictions = yield tfd.Normal(tf.linalg.matvec(x, coefs), scale)
return predictions
The author suggested that users
would be uncomfortable with
bar = yield foo
Uncomfortable indeed I am. I tried to make sense of this generator, but couldn't see how it can be used.
This is my thought process. If I do foo = linear_regression(bar)
and execute foo
(e.g. next(foo)
), it will return the value of scale
to me. However, this will also turn the local variable scale
to None
. Similarly, if foo
is executed again, I can get the value of coefs
, but the local coefs
would become None
. With both local scale
and coefs
being None
, how can predictions
be evaluated?
Or is there a way to evaluate foo
without triggering the yield
on scale
and coefs
, and directly yield on predictions
?
What is the black magic here? Help needed.