def test_tt(self): true_sampler = theano.function([self.coin_weight], self.coin) sample, ll, updates = mh_sample(self.s_rng, [self.coin_weight]) sampler = theano.function([self.coin], sample, updates=updates) for i in range(100): print sampler(true_sampler(0.9))
def test_mh_sample(self): sample, ll, updates = mh_sample(self.s_rng, [self.M, self.V], observations={self.X: self.X_data}, lag = 100) sampler = theano.function([], sample, updates=updates) data = [] for i in range(100): print i data.append(sampler()) pylab.subplot(211) pylab.hist(numpy.asarray(data)[:,0]) pylab.subplot(212) pylab.hist(numpy.asarray(data)[:,1]) pylab.show()
def test_mh_sample(self): sample, ll, updates = mh_sample(self.s_rng, [self.M, self.V], observations={self.X: self.X_data}, lag=100) sampler = theano.function([], sample, updates=updates) data = [] for i in range(100): print i data.append(sampler()) pylab.subplot(211) pylab.hist(numpy.asarray(data)[:, 0]) pylab.subplot(212) pylab.hist(numpy.asarray(data)[:, 1]) pylab.show()
[0,0,1,0], [0,0,1,0], [0,0,1,0]], dtype=theano.config.floatX) document_3 = numpy.asarray([[1,0,0,0], [0,0,0,1], [0,1,0,0], [0,1,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1], [1,0,0,0], [0,0,1,0], [0,0,1,0]], dtype=theano.config.floatX) # Map documents to RVs givens = {get_words(1, 10): document_1, get_words(2, 10): document_2, get_words(3, 10): document_3} # Build sampler sample, ll, updates = mh_sample(s_rng, [doc_mixture(1), doc_mixture(2), doc_mixture(3), topic_mixture(0), topic_mixture(1)]) sampler = theano.function([], sample, updates=updates, givens=givens, allow_input_downcast=True) # Run sampling for i in range(10000): d = sampler() if i % 1000 == 0: print d
[[1, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]], dtype=theano.config.floatX) # Map documents to RVs givens = { get_words(1, 10): document_1, get_words(2, 10): document_2, get_words(3, 10): document_3 } # Build sampler sample, ll, updates = mh_sample(s_rng, [ doc_mixture(1), doc_mixture(2), doc_mixture(3), topic_mixture(0), topic_mixture(1) ]) sampler = theano.function([], sample, updates=updates, givens=givens, allow_input_downcast=True) # Run sampling for i in range(10000): d = sampler() if i % 1000 == 0: print d