def tensor(self):
"""
Return corresponding Tensor through sampling, or if observed, return
the observed value.
:return: A Tensor.
"""
if not hasattr(self, '_tensor'):
if self._observed is not None:
self._tensor = self._observed
elif self._name in self._net.observed:
try:
self._tensor = tf.convert_to_tensor(
self._net.observed[self._name], dtype=self._dtype)
except ValueError as e:
raise ValueError(
"StochasticTensor('{}') not compatible "
"with its observed value. Error message: {}".format(
self._name, e))
else:
self._tensor = self.sample(self._n_samples)
return self._tensor
评论列表
文章目录