aesara
aesara copied to clipboard
Scan Gibbs example is outdated and wrong
This section of the Scan documentation has several issues:
https://aesara.readthedocs.io/en/latest/library/scan.html#using-shared-variables-gibbs-sampling
- Binomial no longer accepts
n
,p
as keyword arguments - Outputs info is wrong because it uses a
float
vector, but the returned output type isint64
-
aesara.dot
is no longer a thing - updates are not actually optional, the function will not compile without them #579
I would like to help with this one. I got the code below compiled but I don't know what results are expected exactly.
import aesara
import aesara. tensor as at
W = aesara.shared(W_values) # we assume that ``W_values`` contains the
# initial values of your weight matrix
bvis = aesara.shared(bvis_values)
bhid = aesara.shared(bhid_values)
trng = at.random.utils.RandomStream(1234)
def OneStep(vsample):
hmean = at.sigmoid(at.dot(vsample, W) + bhid)
hsample = trng.binomial(1, hmean, size=hmean.shape)
vmean = at.sigmoid(at.dot(hsample, W.T) + bvis)
return trng.binomial(1, vmean, size=vsample.shape)
sample = aesara.tensor.lvector()
values, updates = aesara.scan(OneStep, outputs_info=sample, n_steps=10)
gibbs10 = aesara.function([sample], values[-1], updates=updates)