Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99a7de8

Browse files
authored
Adding Bayesian evidence support for numcosmo app. (#152)
* Adding Bayesian evidence support for numcosmo app. * Removed black version restriction.
1 parent 1efaffe commit 99a7de8

5 files changed

Lines changed: 695 additions & 55 deletions

File tree

devel_environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
dependencies:
55
- astropy
6-
- black<24
6+
- black
77
- c-compiler
88
- cfitsio
99
- fftw

numcosmo_py/app/catalog.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,18 @@
5050
class AnalyzeMCMC(LoadCatalog):
5151
"""Analyzes the results of a MCMC run."""
5252

53-
info: Annotated[
53+
evidence: Annotated[
5454
bool,
5555
typer.Option(
56-
help="Prints information about the MCMC file.",
56+
help=(
57+
"Computes the ln-Bayesian evidence and the 1sigma parameter "
58+
"space ln-volume."
59+
),
5760
),
58-
] = True
61+
] = False
5962

6063
def __post_init__(self) -> None:
64+
"""Analyzes the results of a MCMC run."""
6165
super().__post_init__()
6266

6367
mcat = self.mcat
@@ -317,6 +321,43 @@ def __post_init__(self) -> None:
317321
covariance_matrix.add_row(*row)
318322

319323
main_table.add_row(covariance_matrix)
324+
325+
if self.evidence:
326+
evidence_table = Table(title="Posterior Analysis", expand=False)
327+
evidence_table.add_column("Evidence Type", justify="left", style=desc_color)
328+
evidence_table.add_column(
329+
"Value +/- 1-sigma", justify="left", style=values_color
330+
)
331+
evidence_table.add_column(
332+
"1-sigma volume", justify="left", style=values_color
333+
)
334+
evidence_table.add_column(
335+
"2-sigma volume", justify="left", style=values_color
336+
)
337+
338+
be, be_sd = mcat.get_post_lnnorm()
339+
lnevol_1s, glnvol_1s = mcat.get_post_lnvol(0.682689492137086)
340+
lnevol_2s, glnvol_2s = mcat.get_post_lnvol(0.954499736103642)
341+
342+
evidence_table.add_row(
343+
"Bayesian ln-Evidence", f"{be:.5g} +/- {be_sd:.5g}", "--", "--"
344+
)
345+
346+
evidence_table.add_row(
347+
"Posterior ln-volume",
348+
"--",
349+
f"{lnevol_1s:.5g}",
350+
f"{lnevol_2s:.5g}",
351+
)
352+
evidence_table.add_row(
353+
"Posterior ln-volume (Gaussian approx.)",
354+
"--",
355+
f"{glnvol_1s:.5g}",
356+
f"{glnvol_2s:.5g}",
357+
)
358+
359+
main_table.add_row(evidence_table)
360+
320361
self.console.print(main_table)
321362

322363
self.end_experiment()
@@ -428,6 +469,7 @@ class CalibrateCatalog(LoadCatalog):
428469
] = False
429470

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

433475
mcat = self.mcat
@@ -598,6 +640,7 @@ class PlotCorner(LoadCatalog):
598640
] = 0
599641

600642
def __post_init__(self) -> None:
643+
"""Corner plot of the catalog."""
601644
super().__post_init__()
602645

603646
mcat = self.mcat

0 commit comments

Comments
 (0)