Skip to content

Commit

Permalink
Merge branch 'master' into parallel_like1
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeyers314 committed Jul 13, 2016
2 parents b7f927c + a9a740e commit 1041dd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dpmm/dpmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ def update_latent_data(self):
# Pseudo-marginal samples or (TBD) means and Gaussian errors.
if isinstance(self._D, PseudoMarginalData):
for i, ph in enumerate(self.phi):
index = np.nonzero(self.label == i)
index = np.nonzero(self.label == i)[0]
data = self._D[index] # a PseudoMarginalData instance
# calculate weights for selecting a representative sample
ps = self.prior.like1(self.manip(data.data), ph) / data.interim_prior
ps /= np.sum(ps, axis=1)[:, np.newaxis] # think this line can go.
for j, p in enumerate(ps):
self.D[index[0][j]] = data.data[j, pick_discrete(p)]
self.D[index[j]] = data.data[j, pick_discrete(p)]
# Need to update the r_i probabilities too since self.D changed.
# self.r_i = self.alpha * self.prior.pred(self.mD)
self.p[:, 0] = self.alpha * self.prior.pred(self.mD)
Expand Down
7 changes: 6 additions & 1 deletion dpmm/shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def __init__(self, g):
# g should be a length-2 array representing the real and imag parts of the complex
# representation of the reduced shear.
self.g = g
self.Nproposals = 0
self.Nacceptances = 0

def init(self, D):
"""A quick and dirty estimate of g is just the average over D."""
Expand All @@ -150,7 +152,7 @@ def update(self, D, phi, label, prior):
# Whoops! The weak shear limit proposal doesn't lead to *any* acceptances when ngal is
# large. Need to try something more clever.
# prop_g = draw_g_2d_weak_shear(D, phi, label)
prop_g = np.random.multivariate_normal(mean=self.g, cov=np.eye(2)*0.0005**2)
prop_g = np.random.multivariate_normal(mean=self.g, cov=np.eye(2)*0.003**2)

current_e_int = unshear(D, self.g)
prop_e_int = unshear(D, prop_g)
Expand All @@ -162,7 +164,10 @@ def update(self, D, phi, label, prior):
prop_lnlike += prior.lnlikelihood(prop_e_int[index], ph)
if prop_lnlike > current_lnlike:
self.g = prop_g
self.Nacceptances += 1
else:
u = np.random.uniform()
if u < np.exp(prop_lnlike - current_lnlike):
self.g = prop_g
self.Nacceptances += 1
self.Nproposals += 1

0 comments on commit 1041dd2

Please sign in to comment.