Skip to content

Commit a98a7c7

Browse files
committed
Fix potentials bug in independence sampler
1 parent 6d088a4 commit a98a7c7

File tree

12 files changed

+50
-29
lines changed

12 files changed

+50
-29
lines changed

deep_tensor/debiasing/mcmc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,19 @@ def run_independence_sampler(
305305
"""
306306

307307
n, d = xs.shape
308-
potentials = neglogfxs_exact - neglogfxs_irt
309308

310309
chain = MarkovChain(n, d)
311-
chain.add_new_state(xs[0], potentials[0])
310+
chain.add_new_state(xs[0], neglogfxs_exact[0])
311+
i_cur = 0
312312

313313
for i in range(n-1):
314-
315-
alpha = chain.current_potential - potentials[i+1]
314+
315+
alpha = (neglogfxs_exact[i_cur] + neglogfxs_irt[i+1]
316+
- neglogfxs_exact[i+1] - neglogfxs_irt[i_cur])
316317

317318
if alpha.exp() > torch.rand(1):
318-
chain.add_new_state(xs[i+1], potentials[i+1])
319+
chain.add_new_state(xs[i+1], neglogfxs_exact[i+1])
320+
i_cur = i+1
319321
else:
320322
chain.add_current_state()
321323

deep_tensor/polynomials/spectral/spectral_cdf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def newton(
163163
self,
164164
coefs: Tensor,
165165
cdf_poly_base: Tensor,
166+
cdf_poly_norm,
166167
zs_unnorm: Tensor,
167168
l0s: Tensor,
168169
l1s: Tensor
@@ -177,7 +178,7 @@ def newton(
177178
for _ in range(self.num_newton):
178179
zs, dzs = self.eval_int_newton(coefs, cdf_poly_base, zs_unnorm, ls)
179180
ls, dls = self._newton_step(ls, zs, dzs, l0s, l1s)
180-
if self.converged(zs, dls):
181+
if self.converged(zs / cdf_poly_norm, dls / cdf_poly_norm):
181182
return ls
182183

183184
# self.print_unconverged(zs, dls, "Newton's method")
@@ -232,5 +233,5 @@ def invert_cdf(self, ps: Tensor, zs: Tensor) -> Tensor:
232233
l0s = self.sampling_nodes[left_inds]
233234
l1s = self.sampling_nodes[left_inds+1]
234235

235-
ls = self.newton(coefs, cdf_poly_base, zs_cdf, l0s, l1s)
236+
ls = self.newton(coefs, cdf_poly_base, cdf_poly_norm, zs_cdf, l0s, l1s)
236237
return ls

docs/_freeze/examples/heat/execute-results/html.json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.
-597 Bytes
Loading
731 Bytes
Loading

docs/_freeze/examples/shock/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.
-2.19 KB
Loading
-13.6 KB
Loading
-927 Bytes
Loading

docs/examples/heat.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ d_obs += noise
142142
143143
fig, ax = plt.subplots(figsize=(6.0, 2.0))
144144
cbar_label = r"$u(\bm{x}, 10)$"
145-
plot_dl_function(fig, ax, model_full.vec2func(u_true[:, -1]), cbar_label, vmin=-0.15, vmax=0.1)
145+
plot_dl_function(fig, ax, model_full.vec2func(u_true[:, -1]), cbar_label, vmin=-0.15, vmax=0.10)
146146
ax.scatter(*model_full.xs_obs.T, s=16, c="k", marker=".")
147147
ax.set_xlabel(r"$x_{0}$")
148148
ax.set_ylabel(r"$x_{1}$")

0 commit comments

Comments
 (0)