|
10 | 10 | import jax.scipy.linalg as jlinalg |
11 | 11 | import numpy as np |
12 | 12 | import pandas as pd |
13 | | -import tikzplotlib |
14 | 13 | import tqdm.auto as tqdm |
15 | 14 | from jax.scipy.stats import norm |
16 | 15 | from matplotlib import pyplot as plt |
17 | | -from matplotlib.ticker import FormatStrFormatter |
18 | 16 |
|
19 | 17 | from coupled_rejection_sampling.mvn import coupled_mvns, mvn_logpdf |
20 | 18 | from coupled_rejection_sampling.thorisson import modified_thorisson |
21 | 19 |
|
22 | | - |
23 | 20 | JAX_KEY = jax.random.PRNGKey(0) |
24 | 21 | K = 10_000 # number of experiments |
25 | 22 | CS = np.linspace(0.8, 0.99, 7) |
@@ -121,6 +118,7 @@ def body(carry): |
121 | 118 | op_key, sample_key = jax.random.split(op_key, 2) |
122 | 119 | x, y, coupled = simplified_manifold_mala_step(sample_key, x, y, eps, sampler, log_pi) |
123 | 120 | return op_key, x, y, iteration + 1, coupled |
| 121 | + |
124 | 122 | *_, meeting_time, _ = jax.lax.while_loop(cond, body, (key, x0, y0, 0, False)) |
125 | 123 | return meeting_time |
126 | 124 |
|
@@ -208,68 +206,15 @@ def log_target(theta, return_fisher=False): |
208 | 206 | rejection_df.loc[("meeting time", "mean")] = [f"${v.mean(-1):.1f}$" for v in data["rejection_meeting_times"]] |
209 | 207 | rejection_df.loc[("run time (s)", "mean")] = [f"${v.mean(-1):.1e}$" for v in data["rejection_runtime"][:, 1:]] |
210 | 208 |
|
| 209 | + thorisson_df.loc[("meeting time", "standard deviation")] = [f"${v.std(-1):.1f}$" for v in |
| 210 | + data["thorisson_meeting_times"]] |
| 211 | + thorisson_df.loc[("run time (s)", "standard deviation")] = [f"${v.std(-1):.1e}$" for v in |
| 212 | + data["thorisson_runtime"][:, 1:]] |
211 | 213 |
|
212 | | - thorisson_df.loc[("meeting time", "standard deviation")] = [f"${v.std(-1):.1f}$" for v in data["thorisson_meeting_times"]] |
213 | | - thorisson_df.loc[("run time (s)", "standard deviation")] = [f"${v.std(-1):.1e}$" for v in data["thorisson_runtime"][:, 1:]] |
214 | | - |
215 | | - rejection_df.loc[("meeting time", "standard deviation")] = [f"${v.std(-1):.1f}$" for v in data["rejection_meeting_times"]] |
216 | | - rejection_df.loc[("run time (s)", "standard deviation")] = [f"${v.std(-1):.1e}$" for v in data["rejection_runtime"][:, 1:]] |
217 | | - |
| 214 | + rejection_df.loc[("meeting time", "standard deviation")] = [f"${v.std(-1):.1f}$" for v in |
| 215 | + data["rejection_meeting_times"]] |
| 216 | + rejection_df.loc[("run time (s)", "standard deviation")] = [f"${v.std(-1):.1e}$" for v in |
| 217 | + data["rejection_runtime"][:, 1:]] |
218 | 218 |
|
219 | 219 | print(rejection_df.to_latex("out/rejection_mmala.tex")) |
220 | 220 | print(thorisson_df.to_latex("out/thorisson_mmala.tex")) |
221 | | - # for i, D in enumerate(DS): |
222 | | - # axes[0].set_title("Rejection") |
223 | | - # axes[0].set_xscale("log") |
224 | | - # axes[0].set_yscale("log") |
225 | | - # axes[0].plot(data["NS"], data["rejection_meeting_times"][i].mean(-1).mean(-1), |
226 | | - # color=cmap(i), label=f"$D={D}$") |
227 | | - # axes[0].fill_between(data["NS"], |
228 | | - # data["rejection_meeting_times"][i].mean(-1).mean(-1) - 1.96 * |
229 | | - # data["rejection_meeting_times"][i].mean(-1).std(-1), |
230 | | - # data["rejection_meeting_times"][i].mean(-1).mean(-1) + 1.96 * |
231 | | - # data["rejection_meeting_times"][i].mean(-1).std(-1), |
232 | | - # color=cmap(i), alpha=0.66) |
233 | | - # |
234 | | - # axes[1].set_title("Thorisson") |
235 | | - # axes[1].plot(data["CS"], data["thorisson_meeting_times"][i].mean(-1).mean(-1), |
236 | | - # color=cmap(i), label=f"$D={D}$") |
237 | | - # axes[1].fill_between(data["CS"], |
238 | | - # data["thorisson_meeting_times"][i].mean(-1).mean(-1) - 1.96 * |
239 | | - # data["thorisson_meeting_times"][i].mean(-1).std(-1), |
240 | | - # data["thorisson_meeting_times"][i].mean(-1).mean(-1) + 1.96 * |
241 | | - # data["thorisson_meeting_times"][i].mean(-1).std(-1), |
242 | | - # color=cmap(i), alpha=0.66) |
243 | | - # axes[1].set_yscale("log") |
244 | | - # axes[1].xaxis.set_major_formatter(FormatStrFormatter('%.1f')) |
245 | | - # axes[1].legend() |
246 | | - # tikzplotlib.save("out/gibbs_meeting_time.tikz") |
247 | | - # |
248 | | - # fig, axes = plt.subplots(ncols=2, figsize=(15, 6), sharey=True) |
249 | | - # |
250 | | - # for i, D in enumerate(DS): |
251 | | - # axes[0].set_title("Rejection") |
252 | | - # axes[0].set_xscale("log") |
253 | | - # axes[0].set_yscale("log") |
254 | | - # axes[0].plot(data["NS"], data["rejection_runtime"][i].mean(-1), |
255 | | - # color=cmap(i), label=f"$D={D}$") |
256 | | - # axes[0].fill_between(data["NS"], |
257 | | - # data["rejection_runtime"][i].mean(-1) - 1.96 * |
258 | | - # data["rejection_runtime"][i].std(-1), |
259 | | - # data["rejection_runtime"][i].mean(-1) + 1.96 * |
260 | | - # data["rejection_runtime"][i].std(-1), |
261 | | - # color=cmap(i), alpha=0.66) |
262 | | - # axes[1].set_title("Thorisson") |
263 | | - # axes[1].plot(data["CS"], data["thorisson_runtime"][i].mean(-1), |
264 | | - # color=cmap(i), label=f"$D={D}$") |
265 | | - # axes[1].fill_between(data["CS"], |
266 | | - # data["thorisson_runtime"][i].mean(-1) - 1.96 * |
267 | | - # data["thorisson_runtime"][i].std(-1), |
268 | | - # data["thorisson_runtime"][i].mean(-1) + 1.96 * |
269 | | - # data["thorisson_runtime"][i].std(-1), |
270 | | - # color=cmap(i), alpha=0.66) |
271 | | - # axes[1].set_yscale("log") |
272 | | - # axes[1].xaxis.set_major_formatter(FormatStrFormatter('%.1f')) |
273 | | - # axes[1].legend() |
274 | | - # |
275 | | - # tikzplotlib.save("out/gibbs_run_time.tikz") |
0 commit comments