Beispiel #1
0
 def stats(self):
     # Update accept stat if any subtrees were accepted
     if self.log_size > 0:
         # Remove contribution from initial state which is always a perfect
         # accept
         log_sum_weight = logdiffexp_numpy(self.log_size, 0.0)
         self.mean_tree_accept = np.exp(self.log_weighted_accept_sum -
                                        log_sum_weight)
     return {
         "depth": self.depth,
         "mean_tree_accept": self.mean_tree_accept,
         "energy_error": self.proposal.energy - self.start.energy,
         "energy": self.proposal.energy,
         "tree_size": self.n_proposals,
         "max_energy_error": self.max_energy_change,
         "model_logp": self.proposal.logp,
     }
Beispiel #2
0
def test_logdiffexp():
    a = np.log([1, 2, 3, 4])
    b = np.log([0, 1, 2, 3])

    assert np.allclose(logdiffexp_numpy(a, b), 0)
    assert np.allclose(logdiffexp(a, b).eval(), 0)