def eval(self, x, rand=False):
"""Evaluate net at locations in x."""
if rand:
# compile theano computation graph, if haven't already done so
if self.eval_f_rand == None:
n_data = tt.iscalar('n_data')
uas = [tt.tile(self.srng.normal((n_units,), dtype=dtype), [n_data, 1]) for n_units in self.n_units[1:]]
self.eval_f_rand = theano.function(
inputs=[self.hs[0], n_data],
outputs=self.hs[-1],
givens=zip(self.uas, uas)
)
return self.eval_f_rand(x.astype(dtype), x.shape[0])
else:
# compile theano computation graph, if haven't already done so
if self.eval_f == None:
self.eval_f = theano.function(
inputs=[self.hs[0]],
outputs=self.hs[-1],
givens=zip(self.zas, self.mas)
)
return self.eval_f(x.astype(dtype))
评论列表
文章目录