Skip to content

Commit

Permalink
Adding Bayesian evidence support for numcosmo app. (#152)
Browse files Browse the repository at this point in the history
* Adding Bayesian evidence support for numcosmo app.
* Removed black version restriction.
  • Loading branch information
vitenti committed Apr 14, 2024
1 parent 1efaffe commit 99a7de8
Show file tree
Hide file tree
Showing 5 changed files with 695 additions and 55 deletions.
2 changes: 1 addition & 1 deletion devel_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
- astropy
- black<24
- black
- c-compiler
- cfitsio
- fftw
Expand Down
49 changes: 46 additions & 3 deletions numcosmo_py/app/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@
class AnalyzeMCMC(LoadCatalog):
"""Analyzes the results of a MCMC run."""

info: Annotated[
evidence: Annotated[
bool,
typer.Option(
help="Prints information about the MCMC file.",
help=(
"Computes the ln-Bayesian evidence and the 1sigma parameter "
"space ln-volume."
),
),
] = True
] = False

def __post_init__(self) -> None:
"""Analyzes the results of a MCMC run."""
super().__post_init__()

mcat = self.mcat
Expand Down Expand Up @@ -317,6 +321,43 @@ def __post_init__(self) -> None:
covariance_matrix.add_row(*row)

main_table.add_row(covariance_matrix)

if self.evidence:
evidence_table = Table(title="Posterior Analysis", expand=False)
evidence_table.add_column("Evidence Type", justify="left", style=desc_color)
evidence_table.add_column(
"Value +/- 1-sigma", justify="left", style=values_color
)
evidence_table.add_column(
"1-sigma volume", justify="left", style=values_color
)
evidence_table.add_column(
"2-sigma volume", justify="left", style=values_color
)

be, be_sd = mcat.get_post_lnnorm()
lnevol_1s, glnvol_1s = mcat.get_post_lnvol(0.682689492137086)
lnevol_2s, glnvol_2s = mcat.get_post_lnvol(0.954499736103642)

evidence_table.add_row(
"Bayesian ln-Evidence", f"{be:.5g} +/- {be_sd:.5g}", "--", "--"
)

evidence_table.add_row(
"Posterior ln-volume",
"--",
f"{lnevol_1s:.5g}",
f"{lnevol_2s:.5g}",
)
evidence_table.add_row(
"Posterior ln-volume (Gaussian approx.)",
"--",
f"{glnvol_1s:.5g}",
f"{glnvol_2s:.5g}",
)

main_table.add_row(evidence_table)

self.console.print(main_table)

self.end_experiment()
Expand Down Expand Up @@ -428,6 +469,7 @@ class CalibrateCatalog(LoadCatalog):
] = False

def __post_init__(self) -> None:
"""Calibrate the APES sampler using a given catalog."""
super().__post_init__()

mcat = self.mcat
Expand Down Expand Up @@ -598,6 +640,7 @@ class PlotCorner(LoadCatalog):
] = 0

def __post_init__(self) -> None:
"""Corner plot of the catalog."""
super().__post_init__()

mcat = self.mcat
Expand Down

0 comments on commit 99a7de8

Please sign in to comment.