Skip to content

Commit ff74dd8

Browse files
committed
Updated Examples
Updated optimisation examples to use settings from the paper. Updated cosmo examples to have settings from the paper (Omk may change still). Added example notebook to run through basic examples of how to use.
1 parent 82a0c86 commit ff74dd8

11 files changed

Lines changed: 792 additions & 75 deletions

‎.DS_Store‎

2 KB
Binary file not shown.

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ docs/build/html/
5151
build/
5252
/docs/build
5353
examples/.DS_Store
54-
*.html
54+
*.html
55+
CosmoPosteriors.ipynb

‎examples/Banana.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ def main():
5555
min_evals=25,
5656
max_evals=250,
5757
max_gp_size=250,
58-
logz_threshold=0.01,
58+
logz_threshold=5e-2,
5959
do_final_ns=True,
60-
fit_n_points=2,
60+
fit_n_points=1,
6161
batch_size=1,
62-
ns_n_points=4,
63-
num_hmc_warmup=256,
62+
ns_n_points=1,
63+
num_hmc_warmup=512,
6464
num_hmc_samples=2048,
65-
mc_points_size=128,
65+
mc_points_size=512,
6666
num_chains=4,
67-
convergence_n_iters=1,
67+
convergence_n_iters=2,
6868
)
6969

7070
end = time.time()
@@ -91,7 +91,7 @@ def main():
9191

9292
# Create Dynesty samples to compare against
9393
dns_sampler = DynamicNestedSampler(loglike,prior_transform,ndim=ndim,
94-
sample='rwalk',logl_kwargs={'slow': False})
94+
sample='rwalk')
9595

9696
dns_sampler.run_nested(print_progress=True,dlogz_init=0.01)
9797
res = dns_sampler.results

‎examples/Example Notebook.ipynb‎

Lines changed: 720 additions & 0 deletions
Large diffs are not rendered by default.

‎examples/GaussianRing.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
mean_r = 0.2
1515
scale = 0.02
1616

17-
def loglike(X, slow=False):
17+
def loglike(X):
1818
r2 = (X[0]-0.5)**2 + (X[1]-0.5)**2
1919
r = np.sqrt(r2)
20-
if slow: # artificial delay to simulate slow likelihood
21-
time.sleep(2)
2220
return -0.5*((r-mean_r)/scale)**2
2321

2422
def prior_transform(x):
@@ -57,16 +55,16 @@ def main():
5755
min_evals=25,
5856
max_evals=250,
5957
max_gp_size=250,
60-
logz_threshold=0.01,
58+
logz_threshold=5e-2,
6159
do_final_ns=True,
6260
fit_n_points=2,
63-
batch_size=1,
61+
batch_size=2,
6462
ns_n_points=4,
65-
num_hmc_warmup=256,
63+
num_hmc_warmup=512,
6664
num_hmc_samples=2048,
67-
mc_points_size=128,
65+
mc_points_size=512,
6866
num_chains=4,
69-
convergence_n_iters=1,
67+
convergence_n_iters=2,
7068
)
7169

7270
end = time.time()
@@ -93,7 +91,7 @@ def main():
9391

9492
# Create Dynesty samples to compare against
9593
dns_sampler = DynamicNestedSampler(loglike,prior_transform,ndim=ndim,
96-
sample='rwalk',logl_kwargs={'slow': False})
94+
sample='rwalk')
9795

9896
dns_sampler.run_nested(print_progress=True,dlogz_init=0.01)
9997
res = dns_sampler.results

‎examples/Himmelblau.py‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
def prior_transform(x):
1717
return 8*x - 4
1818

19-
def loglike(X, slow=False):
19+
def loglike(X):
2020
r1 = (X[0] + X[1]**2 -7)**2
2121
r2 = (X[0]**2 + X[1]-11)**2
22-
if slow:
23-
time.sleep(2)
2422
return -0.5*(afac*r1 + r2)
2523

2624
def main():
@@ -56,16 +54,16 @@ def main():
5654
min_evals=25,
5755
max_evals=250,
5856
max_gp_size=250,
59-
logz_threshold=0.01,
57+
logz_threshold=5e-2,
6058
do_final_ns=True,
6159
fit_n_points=2,
62-
batch_size=1,
63-
ns_n_points=4,
64-
num_hmc_warmup=256,
60+
batch_size=2,
61+
ns_n_points=2,
62+
num_hmc_warmup=512,
6563
num_hmc_samples=2048,
66-
mc_points_size=128,
64+
mc_points_size=512,
6765
num_chains=4,
68-
convergence_n_iters=1,
66+
convergence_n_iters=2,
6967
)
7068

7169
end = time.time()
@@ -92,7 +90,7 @@ def main():
9290

9391
# Create Dynesty samples to compare against
9492
dns_sampler = DynamicNestedSampler(loglike,prior_transform,ndim=ndim,
95-
sample='rwalk',logl_kwargs={'slow': False})
93+
sample='rwalk')
9694

9795
dns_sampler.run_nested(print_progress=True,dlogz_init=0.01)
9896
res = dns_sampler.results

‎examples/Planck_DESI_LCDM.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def main():
1717
# Set up the cosmological likelihood
1818
cobaya_input_file = './cosmo_input/LCDM_Planck_DESI.yaml'
19-
likelihood_name = 'Planck_DESI_LCDM'
19+
likelihood_name = 'Planck_DESI_LCDM_z025'
2020

2121
start = time.time()
2222
print("Starting BOBE run...")
@@ -27,14 +27,14 @@ def main():
2727
likelihood_name=likelihood_name,
2828
confidence_for_unbounded=0.9999995,
2929
resume=False,
30-
resume_file=f'./results/{likelihood_name}',
31-
save_dir='./results/',
30+
resume_file=f'./results/LCDM/{likelihood_name}',
31+
save_dir='./results/LCDM/',
3232
save=True,
3333
verbosity='INFO',
3434
n_cobaya_init=8,
3535
n_sobol_init=32,
3636
optimizer='scipy',
37-
gp_kwargs={'lengthscale_prior': None, 'lengthscale_bounds': [1e-2,4.]},
37+
gp_kwargs={'lengthscale_prior': None, 'lengthscale_bounds': [1e-2,5.]},
3838
use_clf=True,
3939
clf_type='svm',
4040
seed=42,
@@ -45,15 +45,15 @@ def main():
4545
min_evals=750,
4646
max_evals=2500,
4747
max_gp_size=1500,
48-
convergence_n_iters=1,
49-
fit_n_points=20,
48+
convergence_n_iters=2,
49+
fit_n_points=10,
5050
batch_size=5,
5151
ns_n_points=10,
5252
num_hmc_warmup=512,
53-
num_hmc_samples=4000,
53+
num_hmc_samples=4096,
5454
mc_points_size=512,
5555
num_chains=6,
56-
logz_threshold=0.5,
56+
logz_threshold=0.25,
5757
do_final_ns=True,
5858
)
5959

@@ -109,7 +109,7 @@ def main():
109109
contour_colors=['#006FED', 'black'], contour_lws=[1, 1.5],
110110
params=param_list_LCDM,
111111
legend_labels=['BOBE', 'MCMC'])
112-
g.export(f'./results/{likelihood.name}_cosmo.pdf')
112+
g.export(f'./results/LCDM/{likelihood.name}_cosmo_posteriors.pdf')
113113

114114
# Create parameter samples plot - all parameters
115115
print("Creating full parameter samples plot...")
@@ -120,7 +120,7 @@ def main():
120120
g.triangle_plot([BOBE_Samples,reference_samples], filled=[True, False],
121121
contour_colors=['#006FED', 'black'], contour_lws=[1, 1.5],
122122
legend_labels=['BOBE', 'MCMC'])
123-
g.export(f'./results/{likelihood.name}_full.pdf')
123+
g.export(f'./results/LCDM/{likelihood.name}_full_posteriors.pdf')
124124

125125
# Print timing analysis
126126
print("DETAILED TIMING ANALYSIS")
@@ -145,7 +145,7 @@ def main():
145145
ax.set_yscale('log')
146146
ax.set_xlabel(r'Iteration')
147147
ax.set_ylabel(r'Acquisition Value')
148-
plt.savefig(f"./results/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
148+
plt.savefig(f"./results/LCDM/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
149149

150150
if __name__ == "__main__":
151151
main()

‎examples/Planck_DESI_Omk_LCDM.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def main():
1616
# Set up the cosmological likelihood
1717
cobaya_input_file = './cosmo_input/LCDM_Planck_DESI_Omk.yaml'
18-
likelihood_name = 'Planck_DESI_Omk_LCDM'
18+
likelihood_name = 'Planck_DESI_Omk_LCDM_z025'
1919

2020
start = time.time()
2121
print("Starting BOBE run...")
@@ -25,12 +25,12 @@ def main():
2525
loglikelihood=cobaya_input_file,
2626
likelihood_name=likelihood_name,
2727
confidence_for_unbounded=0.9999995,
28-
resume=True,
29-
resume_file=f'./results/{likelihood_name}',
30-
save_dir='./results/',
28+
resume=False,
29+
resume_file=f'./results/LCDM_Omk/{likelihood_name}',
30+
save_dir='./results/LCDM_Omk/',
3131
save=True,
3232
verbosity='INFO',
33-
n_cobaya_init=8,
33+
n_cobaya_init=16,
3434
n_sobol_init=32,
3535
optimizer='scipy',
3636
gp_kwargs={'lengthscale_bounds': [1e-2,5.]},
@@ -42,17 +42,17 @@ def main():
4242
results = bobe.run(
4343
acq='wipstd',
4444
min_evals=750,
45-
max_evals=2500,
46-
max_gp_size=1500,
47-
convergence_n_iters=1,
48-
fit_n_points=20,
45+
max_evals=2000,
46+
max_gp_size=1800,
47+
convergence_n_iters=2,
48+
fit_n_points=10,
4949
batch_size=5,
5050
ns_n_points=10,
5151
num_hmc_warmup=512,
52-
num_hmc_samples=5000,
52+
num_hmc_samples=4096,
5353
mc_points_size=512,
5454
num_chains=6,
55-
logz_threshold=0.5,
55+
logz_threshold=0.25,
5656
do_final_ns=True,
5757
)
5858

@@ -108,7 +108,7 @@ def main():
108108
contour_colors=['#006FED', 'black'], contour_lws=[1, 1.5],
109109
params=param_list_LCDM,
110110
legend_labels=['BOBE', 'MCMC'])
111-
g.export(f'./results/{likelihood.name}_cosmo.pdf')
111+
g.export(f'./results/LCDM_Omk/{likelihood.name}_cosmo_posteriors.pdf')
112112

113113
# Create parameter samples plot - all parameters
114114
print("Creating full parameter samples plot...")
@@ -119,7 +119,7 @@ def main():
119119
g.triangle_plot([BOBE_Samples,reference_samples], filled=[True, False],
120120
contour_colors=['#006FED', 'black'], contour_lws=[1, 1.5],
121121
legend_labels=['BOBE', 'MCMC'])
122-
g.export(f'./results/{likelihood.name}_full.pdf')
122+
g.export(f'./results/LCDM_Omk/{likelihood.name}_full_posteriors.pdf')
123123

124124
# Print timing analysis
125125
print("DETAILED TIMING ANALYSIS")
@@ -144,7 +144,7 @@ def main():
144144
ax.set_yscale('log')
145145
ax.set_xlabel(r'Iteration')
146146
ax.set_ylabel(r'Acquisition Value')
147-
plt.savefig(f"./results/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
147+
plt.savefig(f"./results/LCDM_Omk/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
148148

149149
if __name__ == "__main__":
150150
main()

‎examples/Planck_lite_LCDM.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
def main():
1414

1515
# Set up the cosmological likelihood
16-
cobaya_input_file = './cosmo_input/LCDM_lite.yaml'
17-
likelihood_name = f'Planck_lite_LCDM'
16+
cobaya_input_file = 'cosmo_input/LCDM_lite.yaml'
17+
likelihood_name = f'Planck_lite_LCDM_z0025'
1818

1919
start = time.time()
2020
print("Starting BOBE run...")
@@ -26,28 +26,30 @@ def main():
2626
confidence_for_unbounded=0.9999995,
2727
resume=False,
2828
resume_file=f'{likelihood_name}',
29-
save_dir='./results/',
29+
save_dir='./results/LCDM_Lite/',
3030
save=True,
3131
verbosity='INFO',
3232
n_cobaya_init=4,
3333
n_sobol_init=8,
3434
use_clf=True,
3535
clf_type='svm',
36+
#clf_nsigma_threshold=15,
37+
minus_inf=-1e5,
3638
seed=10,
3739
)
3840

3941
results = bobe.run(
4042
acq='wipstd',
41-
min_evals=25,
43+
min_evals=50,
4244
max_evals=250,
4345
max_gp_size=200,
44-
fit_n_points=6,
45-
ns_n_points=6,
46-
batch_size=2,
46+
fit_n_points=4,
47+
ns_n_points=4,
48+
batch_size=4,
4749
num_hmc_warmup=256,
4850
num_hmc_samples=2048,
49-
mc_points_size=256,
50-
logz_threshold=0.1,
51+
mc_points_size=512,
52+
logz_threshold=0.025,
5153
do_final_ns=False,
5254
)
5355

@@ -107,7 +109,7 @@ def main():
107109
for j in range(i+1, ndim):
108110
ax = g.subplots[j, i]
109111
ax.scatter(points[:, i], points[:, j], alpha=0.75, color='red', s=4)
110-
g.export(f'./results/{likelihood.name}_samples.pdf')
112+
g.export(f'./results/LCDM_Lite/{likelihood.name}_samples.pdf')
111113

112114
# Print timing analysis
113115
print("DETAILED TIMING ANALYSIS")
@@ -132,7 +134,7 @@ def main():
132134
ax.set_yscale('log')
133135
ax.set_xlabel(r'Iteration')
134136
ax.set_ylabel(r'Acquisition Value')
135-
plt.savefig(f"./results/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
137+
plt.savefig(f"./results/LCDM_Lite/{likelihood.name}_acquisition.pdf", bbox_inches='tight')
136138

137139
if __name__ == "__main__":
138140
main()

‎examples/Rosenbrock.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import numpy as np
1212
from dynesty import DynamicNestedSampler
1313

14-
def loglike(X, slow=False):
14+
def loglike(X):
1515
res = (1-X[0])**2 + 100*(X[1] - X[0]**2)**2
16-
if slow: # artificial delay to simulate slow likelihood
17-
time.sleep(2)
1816
return -res
1917

2018
def prior_transform(x):
@@ -55,16 +53,16 @@ def main():
5553
min_evals=25,
5654
max_evals=250,
5755
max_gp_size=250,
58-
logz_threshold=0.01,
56+
logz_threshold=5e-2,
5957
do_final_ns=True,
60-
fit_n_points=2,
58+
fit_n_points=1,
6159
batch_size=1,
62-
ns_n_points=4,
60+
ns_n_points=2,
6361
num_hmc_warmup=256,
6462
num_hmc_samples=2048,
6563
mc_points_size=128,
6664
num_chains=4,
67-
convergence_n_iters=1,
65+
convergence_n_iters=2,
6866
)
6967

7068
end = time.time()
@@ -91,7 +89,7 @@ def main():
9189

9290
# Create Dynesty samples to compare against
9391
dns_sampler = DynamicNestedSampler(loglike,prior_transform,ndim=ndim,
94-
sample='rwalk',logl_kwargs={'slow': False})
92+
sample='rwalk')
9593

9694
dns_sampler.run_nested(print_progress=True,dlogz_init=0.01)
9795
res = dns_sampler.results

0 commit comments

Comments
 (0)