-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reorgnize somse stuff * more stuff to organize * refactor * figures for exp1 * exp1 readme * scripts to obtain figures for exp1 * correction * generalize so the same function works in fixed flux case and not * use generalized version * set of figures for experiment 1 * corrections add multiplicative bias histogram * being careful * the angle domain should be between (0, pi) * added new test on scaling of scatter * name as a test * fix test * command to make functions * remove line * sometimes it is useful to split them up * when inferring f, need to pop lf * return info in separate functions * absorb into single script via booleans * this is how we fixed certain parameters during inference * draft of exp 2 with galaxies between snr (8, 100) * correction * dictionary missing * small corrections and additions for final script * more experiments * adapt info might be interesteing * check std * add shell script * will berak it * ruff * draft figures * add timing results * reorganize a b it * improvements * improvements * first set of figures, might run for more samples and see if 2000 chains breaks it * determinism and outliers * seed * determinism elsewhere * readme * might need to revisit adding this kwarg * a little more data could be interesting * redo script, now fix everything except shapes * rename * move script * expanding details * take long enough that slurm script is helpful * need to overwrite by default * figs exp 3 * notebooks * need more time * reduce shape * notebooks * small note
- Loading branch information
1 parent
0409d02
commit 68e15c8
Showing
40 changed files
with
1,932 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Experiment 1 | ||
|
||
This folder contains scripts to reproduce results on the first experiment. The scope of this | ||
experiment is posteriors, biases, and calibration on toy ellipticities in the low noise setting. | ||
|
||
The convergence tests are in the form of unit tests for this experiment in `test_convergence.py` | ||
|
||
## Scripts | ||
|
||
* `get_posteriors.sh`: Get 1000 shear posteriors using the slurm script. | ||
* `get_figures_shear.sh`: Obtain all relevant diagnostic plots and save to `figs` folder. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
./make_figures.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
../../scripts/slurm_toy_shear_vectorized.py 42 toy_shear_42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
os.environ["CUDA_VISIBLE_DEVICES"] = "" | ||
os.environ["JAX_PLATFORMS"] = "cpu" | ||
os.environ["JAX_ENABLE_X64"] = "True" | ||
|
||
import jax.numpy as jnp | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from jax import Array | ||
from matplotlib.backends.backend_pdf import PdfPages | ||
from tqdm import tqdm | ||
|
||
from bpd import DATA_DIR | ||
from bpd.diagnostics import get_contour_plot, get_gauss_pc_fig, get_pc_fig | ||
|
||
|
||
def make_trace_plots(g_samples: Array, n_examples: int = 10) -> None: | ||
"""Make example figure showing example trace plots of shear posteriors.""" | ||
# by default, we choose 10 random traces to plot in 1 PDF file. | ||
fname = "figs/traces.pdf" | ||
with PdfPages(fname) as pdf: | ||
assert g_samples.ndim == 3 | ||
n_post = g_samples.shape[0] | ||
indices = np.random.choice(np.arange(n_post), (n_examples,)) | ||
|
||
for ii in tqdm(indices, desc="Saving traces"): | ||
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 5)) | ||
g1 = g_samples[ii, :, 0] | ||
g2 = g_samples[ii, :, 0] | ||
|
||
ax1.plot(g1) | ||
ax2.plot(g2) | ||
ax1.set_title(f"Index: {ii}") | ||
|
||
pdf.savefig(fig) | ||
plt.close(fig) | ||
|
||
|
||
def make_contour_plots(g_samples: Array, n_examples=10) -> None: | ||
"""Make example figure showing example contour plots of shear posterios""" | ||
# by default, we choose 10 random contours to plot in 1 PDF file. | ||
fname = "figs/contours.pdf" | ||
with PdfPages(fname) as pdf: | ||
assert g_samples.ndim == 3 | ||
n_post = g_samples.shape[0] | ||
indices = np.random.choice(np.arange(n_post), (n_examples,)) | ||
|
||
truth = {"g1": 0.02, "g2": 0.0} | ||
|
||
for ii in tqdm(indices, desc="Saving contours"): | ||
g_dict = {"g1": g_samples[ii, :, 0], "g2": g_samples[ii, :, 1]} | ||
fig = get_contour_plot([g_dict], [f"post_{ii}"], truth) | ||
plt.suptitle(f"Index: {ii}") | ||
pdf.savefig(fig) | ||
plt.close(fig) | ||
|
||
|
||
def make_posterior_calibration(g_samples: Array) -> None: | ||
"""Output posterior calibration figure.""" | ||
# make two types, assuming gaussianity and one not assuming gaussianity. | ||
fname = "figs/calibration.pdf" | ||
with PdfPages(fname) as pdf: | ||
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5)) | ||
get_gauss_pc_fig(ax1, g_samples[..., 0], truth=0.02, param_name="g1 (gauss)") | ||
get_pc_fig(ax2, g_samples[..., 0], truth=0.02, param_name="g1 (full)") | ||
pdf.savefig(fig) | ||
plt.close(fig) | ||
|
||
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5)) | ||
get_gauss_pc_fig(ax1, g_samples[..., 1], truth=0.0, param_name="g2 (gauss)") | ||
get_pc_fig(ax2, g_samples[..., 1], truth=0.0, param_name="g2 (full)") | ||
pdf.savefig(fig) | ||
plt.close(fig) | ||
|
||
|
||
def make_histogram_mbias(g_samples: Array) -> None: | ||
fname = "figs/multiplicative_bias_hist.pdf" | ||
with PdfPages(fname) as pdf: | ||
g1 = g_samples[:, :, 0] | ||
mbias = (g1.mean(axis=1) - 0.02) / 0.02 | ||
fig, ax = plt.subplots(1, 1, figsize=(7, 7)) | ||
ax.hist(mbias, bins=31, histtype="step") | ||
|
||
pdf.savefig(fig) | ||
plt.close(fig) | ||
|
||
|
||
def main(): | ||
pdir = DATA_DIR / "cache_chains" / "toy_shear_42" | ||
assert pdir.exists() | ||
all_g_samples = [] | ||
for fpath in pdir.iterdir(): | ||
if "g_samples" in fpath.name: | ||
_g_samples = jnp.load(fpath) | ||
all_g_samples.append(_g_samples) | ||
g_samples = jnp.concatenate(all_g_samples, axis=0) | ||
assert g_samples.shape == (1000, 3000, 2) | ||
|
||
# make plots | ||
make_trace_plots(g_samples) | ||
make_contour_plots(g_samples) | ||
make_posterior_calibration(g_samples) | ||
make_histogram_mbias(g_samples) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.