aesara icon indicating copy to clipboard operation
aesara copied to clipboard

Scan Gibbs example is outdated and wrong

Open ricardoV94 opened this issue 2 years ago • 1 comments

This section of the Scan documentation has several issues:

https://aesara.readthedocs.io/en/latest/library/scan.html#using-shared-variables-gibbs-sampling

  1. Binomial no longer accepts n, p as keyword arguments
  2. Outputs info is wrong because it uses a float vector, but the returned output type is int64
  3. aesara.dot is no longer a thing
  4. updates are not actually optional, the function will not compile without them #579

ricardoV94 avatar Apr 07 '22 12:04 ricardoV94

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)

LegrandNico avatar Sep 15 '22 22:09 LegrandNico