Exemplo n.º 1
0
 def is_pathwise(self, tensor: StochasticTensor, cost_node: CostTensor) -> bool:
     if has_differentiable_path(cost_node, tensor):
         # There is a differentiable path, so we will just use reparameterization here.
         return True
     else:
         # No automatic baselines. Use the score function.
         return False
Exemplo n.º 2
0
 def adds_loss(self, tensor: StochasticTensor,
               cost_node: CostTensor) -> bool:
     if has_differentiable_path(cost_node, tensor):
         # There is a differentiable path, so we will just use reparameterization here.
         return False
     raise ValueError(
         "There is no differentiable path between the cost tensor and the stochastic tensor. "
         "We cannot use reparameterization. Use a different gradient estimator, or make sure your"
         "code is differentiable.")