def prior_prob(self, prior: torch.distributions = None, log=True):

        if prior is None:
            prior = self.prior_w

        w_log = prior.log_prob(self.w.weights).sum()
        b_log = prior.log_prob(
            self.b.weights).sum() if self.b is not None else 1

        if not log:
            w_log = w_log.exp()
            b_log = b_log.exp() if self.b is not None else 1

        return w_log + b_log
Пример #2
0
 def forward(self, output: torch.distributions, target: torch.Tensor):
     """
     calculates NegativeLogLikelihood
     """
     return -output.log_prob(target).sum()