Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/model cosmology #193

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 61 additions & 30 deletions autogalaxy/config/priors/cosmology.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,63 @@
model.Planck15FlatwCDM:
model.LambdaCDMWrap:
H0:
type: Constant
value: 67.66
Om0:
type: Uniform
lower_limit: '0.0486'
upper_limit: '1.0'
width_modifier:
type: Absolute
value: 0.3
gaussian_limits:
lower: '0.0486'
upper: '1.0'
w0:
type: Uniform
lower_limit: '-2.0'
upper_limit: '0.0'
width_modifier:
type: Absolute
value: 0.5
gaussian_limits:
lower: '-2.0'
upper: '0.0'
model.Planck15Om0:
type: Constant
value: 0.30966
Ode0:
type: Constant
value: 0.69034
Tcmb0:
type: Constant
value: 2.7255
Neff:
type: Constant
value: 3.046
m_nu:
type: Constant
value: 0.06
Ob0:
type: Constant
value: 0.04897
model.FlatLambdaCDMWrap:
H0:
type: Constant
value: 67.66
Om0:
type: Constant
value: 0.30966
Tcmb0:
type: Constant
value: 2.7255
Neff:
type: Constant
value: 3.046
m_nu:
type: Constant
value: 0.06
Ob0:
type: Constant
value: 0.04897
model.FlatwCDMWrap:
H0:
type: Constant
value: 67.66
Om0:
type: Uniform
lower_limit: '0.0486'
upper_limit: '1.0'
width_modifier:
type: Absolute
value: 0.3
gaussian_limits:
lower: '0.0486'
upper: '1.0'
type: Constant
value: 0.30966
w0:
type: Constant
value: -1.0
Tcmb0:
type: Constant
value: 2.7255
Neff:
type: Constant
value: 3.046
m_nu:
type: Constant
value: 0.06
Ob0:
type: Constant
value: 0.04897
6 changes: 3 additions & 3 deletions autogalaxy/cosmology/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .lensing import LensingCosmology
from .wrap import LambdaCDM
from .wrap import FlatLambdaCDM
from .wrap import Planck15
from . import model
from .model import LambdaCDMWrap
from .model import FlatwCDMWrap
from .model import FlatLambdaCDMWrap
157 changes: 137 additions & 20 deletions autogalaxy/cosmology/model.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,152 @@
from astropy import cosmology as cosmo

from autogalaxy.cosmology.wrap import FlatLambdaCDM
from autogalaxy.cosmology.wrap import FlatwCDM
from autogalaxy.cosmology.lensing import LensingCosmology


class Planck15Om0(FlatLambdaCDM):
def __init__(self, Om0: float = 0.3075):
Planck15 = cosmo.Planck15
class LambdaCDMWrap(cosmo.LambdaCDM, LensingCosmology):
def __init__(
self,
H0: float = 67.66,
Om0: float = 0.30966,
Ode0: float = 0.69034,
Tcmb0: float = 2.7255,
Neff: float = 3.046,
m_nu: float = 0.06,
Ob0: float = 0.04897,
):
"""
A wrapper for the astropy `LambdaCDM` cosmology class, which allows it to be used for modeling such
that the cosmological parameters are free parameters which can be fitted for.

The interface of this class is the same as the astropy `LambdaCDM` class, it simply overwrites the
__init__ method and inherits from it in a way that ensures **PyAutoFit** can compose a model from it
without issue.

The class also inherits from `LensingCosmology`, which is a class that provides additional functionality
for calculating lensing specific quantities in the cosmology.

Parameters
----------
H0
The Hubble constant at z=0.
Om0
The total matter density at z=0.
Ode0
The dark energy density at z=0.
Tcmb0
The CMB temperature at z=0.
Neff
The effective number of neutrinos.
m_nu
The sum of the neutrino masses.
Ob0
The baryon density at z=0.
"""
super().__init__(
H0=H0,
Om0=Om0,
Ode0=Ode0,
Tcmb0=Tcmb0,
Neff=Neff,
m_nu=m_nu,
Ob0=Ob0,
name="FlatLambdaCDM",
)


class FlatLambdaCDMWrap(cosmo.FlatLambdaCDM, LensingCosmology):
def __init__(
self,
H0: float = 67.66,
Om0: float = 0.30966,
Tcmb0: float = 2.7255,
Neff: float = 3.046,
m_nu: float = 0.06,
Ob0: float = 0.04897,
):
"""
A wrapper for the astropy `FlatLambdaCDM` cosmology class, which allows it to be used for modeling such
that the cosmological parameters are free parameters which can be fitted for.

The interface of this class is the same as the astropy `FlatLambdaCDM` class, it simply overwrites the
__init__ method and inherits from it in a way that ensures **PyAutoFit** can compose a model from it
without issue.

The class also inherits from `LensingCosmology`, which is a class that provides additional functionality
for calculating lensing specific quantities in the cosmology.

Parameters
----------
H0
The Hubble constant at z=0.
Om0
The total matter density at z=0.
Tcmb0
The CMB temperature at z=0.
Neff
The effective number of neutrinos.
m_nu
The sum of the neutrino masses.
Ob0
The baryon density at z=0.
"""
super().__init__(
H0=Planck15.H0,
H0=H0,
Om0=Om0,
Tcmb0=Planck15.Tcmb0,
Neff=Planck15.Neff,
m_nu=Planck15.m_nu,
Ob0=Planck15.Ob0,
name=Planck15.name,
Tcmb0=Tcmb0,
Neff=Neff,
m_nu=m_nu,
Ob0=Ob0,
name="FlatLambdaCDM",
)


class Planck15FlatwCDM(FlatwCDM):
def __init__(self, Om0: float = 0.3075, w0: float = -1.0):
Planck15 = cosmo.Planck15
class FlatwCDMWrap(cosmo.FlatwCDM, LensingCosmology):
def __init__(
self,
H0: float = 67.66,
Om0: float = 0.30966,
w0: float = -1.0,
Tcmb0: float = 2.7255,
Neff: float = 3.046,
m_nu: float = 0.06,
Ob0: float = 0.04897,
):
"""
A wrapper for the astropy `FlatwCDM` cosmology class, which allows it to be used for modeling such
that the cosmological parameters are free parameters which can be fitted for.

The interface of this class is the same as the astropy `FlatwCDM` class, it simply overwrites the
__init__ method and inherits from it in a way that ensures **PyAutoFit** can compose a model from it
without issue.

The class also inherits from `LensingCosmology`, which is a class that provides additional functionality
for calculating lensing specific quantities in the cosmology.

Parameters
----------
H0
The Hubble constant at z=0.
Om0
The total matter density at z=0.
w0
The dark energy equation of state at z=0.
Tcmb0
The CMB temperature at z=0.
Neff
The effective number of neutrinos.
m_nu
The sum of the neutrino masses.
Ob0
The baryon density at z=0.
"""
super().__init__(
H0=Planck15.H0,
H0=H0,
Om0=Om0,
w0=w0,
Tcmb0=Planck15.Tcmb0,
Neff=Planck15.Neff,
m_nu=Planck15.m_nu,
Ob0=Planck15.Ob0,
name=Planck15.name,
Tcmb0=Tcmb0,
Neff=Neff,
m_nu=m_nu,
Ob0=Ob0,
name="FlatwCDM",
)
36 changes: 4 additions & 32 deletions autogalaxy/cosmology/wrap.py
Original file line number Diff line number Diff line change
@@ -3,42 +3,14 @@
from autogalaxy.cosmology.lensing import LensingCosmology


class LambdaCDM(cosmo.LambdaCDM, LensingCosmology):
"""
A wrapper for the astropy `LambdaCDM` cosmology class.

This can be inherited from when creating cosmologies as a `af.Model` object for model-fitting.
"""

pass


class FlatLambdaCDM(cosmo.FlatLambdaCDM, LensingCosmology):
"""
A wrapper for the astropy `FlatLambdaCDM` cosmology class.

This can be inherited from when creating cosmologies as a `af.Model` object for model-fitting.
"""

pass


class FlatwCDM(cosmo.FlatwCDM, LensingCosmology):
"""
A wrapper for the astropy `FlatwCDM` cosmology class.

This can be inherited from when creating cosmologies as a `af.Model` object for model-fitting.
"""

pass


class Planck15(FlatLambdaCDM, LensingCosmology):
class Planck15(cosmo.FlatLambdaCDM, LensingCosmology):
def __init__(self):
"""
A wrapper for the astropy `Planck15` cosmology class.

This can be inherited from when creating cosmologies as a `af.Model` object for model-fitting.
The only role of this class is to instantiate the `Planck15` cosmology class from astropy, but to additionally
inherit from `LensingCosmology`, which is a class that provides additional functionality for calculating lensing
specific quantities in the cosmology.
"""
Planck15 = cosmo.Planck15

4 changes: 2 additions & 2 deletions docs/general/model_cookbook.rst
Original file line number Diff line number Diff line change
@@ -183,10 +183,10 @@ We can customize the model parameters in a number of different ways, as shown be
# Assert that the effective radius of the bulge is larger than that of the disk.
# (Assertions can only be added at the end of model composition, after all components
# have been bright together in a `Collection`.
model.add_assertion(model.galaxies.bulge.effective_radius > model.galaxies.disk.effective_radius)
model.add_assertion(model.galaxies.galaxy.bulge.effective_radius > model.galaxies.galaxy.disk.effective_radius)

# Assert that the bulge effetive radius is below 3.0":
model.add_assertion(model.galaxies.bulge.effective_radius < 3.0)
model.add_assertion(model.galaxies.galaxy.bulge.effective_radius < 3.0)

Available Model Components
--------------------------
23 changes: 20 additions & 3 deletions files/citations.bib
Original file line number Diff line number Diff line change
@@ -125,6 +125,23 @@ @article{matplotlib
doi = {10.1109/MCSE.2007.55},
year = 2007
}
@ARTICLE{nautilus,
author = {{Lange}, Johannes U.},
title = "{NAUTILUS: boosting Bayesian importance nested sampling with deep learning}",
journal = {\mnras},
keywords = {methods: data analysis, methods: statistical, software: data analysis, Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - Cosmology and Nongalactic Astrophysics, Astrophysics - Earth and Planetary Astrophysics, Astrophysics - Astrophysics of Galaxies, Computer Science - Machine Learning},
year = 2023,
month = oct,
volume = {525},
number = {2},
pages = {3181-3194},
doi = {10.1093/mnras/stad2441},
archivePrefix = {arXiv},
eprint = {2306.16923},
primaryClass = {astro-ph.IM},
adsurl = {https://ui.adsabs.harvard.edu/abs/2023MNRAS.525.3181L},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
@article{numba,
abstract = {Dynamic, interpreted languages, like Python, are attractive for domain-experts and scientists experimenting with new ideas. However, the performance of the interpreter is of-ten a barrier when scaling to larger data sets. This paper presents a just-in-time compiler for Python that focuses in scientific and array-oriented computing. Starting with the simple syntax of Python, Numba compiles a subset of the language into efficient machine code that is comparable in performance to a traditional compiled language. In addi-tion, we share our experience in building a JIT compiler using LLVM[1].},
author = {Lam, Siu Kwan and Pitrou, Antoine and Seibert, Stanley},
@@ -299,7 +316,7 @@ @article{zeus2
primaryClass={stat.ML}
}

@INPROCEEDINGS{dynesty1,
@INPROCEEDINGS{multinest1,
author = {{Skilling}, John},
title = "{Nested Sampling}",
keywords = {02.50.Tt, Inference methods},
@@ -316,7 +333,7 @@ @INPROCEEDINGS{dynesty1
}


@article{dynesty2,
@article{multinest2,
abstract = {Nested sampling estimates directly how the likelihood function relates to prior mass. The evidence (alternatively the marginal likelihood, marginal density of the data, or the prior predictive) is immediately obtained by summation. It is the prime result of the computation, and is accompanied by an estimate of numerical uncertainty. Samples from the posterior distribution are an optional by-product, obtainable for any temperature. The method relies on sampling within a hard constraint on likelihood value, as opposed to the softened likelihood of annealing methods. Progress depends only on the shape of the "nested"contours of likelihood, and not on the likelihood values. This invariance (over monotonic relabelling) allows the method to deal with a class of phasechange problems which effectively defeat thermal annealing. {\textcopyright} 2006 International Society for Bayesian Analysis.},
archivePrefix = {arXiv},
arxivId = {arXiv:1011.1669v3},
@@ -336,7 +353,7 @@ @article{dynesty2
year = {2006}
}

@article{dynesty3,
@article{multinest3,
abstract = {We present further development and the first public release of our multimodal nested sampling algorithm, called MultiNest. This Bayesian inference tool calculates the evidence, with an associated error estimate, and produces posterior samples from distributions that may contain multiple modes and pronounced (curving) degeneracies in high dimensions. The developments presented here lead to further substantial improvements in sampling efficiency and robustness, as compared to the original algorithm presented in Feroz and Hobson, which itself significantly outperformed existing Markov chain Monte Carlo techniques in a wide range of astrophysical inference problems. The accuracy and economy of the MultiNest algorithm are demonstrated by application to two toy problems and to a cosmological inference problem focusing on the extension of the vanilla $\Lambda$ cold dark matter model to include spatial curvature and a varying equation of state for dark energy. The MultiNest software, which is fully parallelized using MPI and includes an interface to CosmoMC, is available at http://www.mrao.cam.ac.uk/software/multinest/. It will also be released as part of the SuperBayeS package, for the analysis of supersymmetric theories of particle physics, at http://www.superbayes.org. {\textcopyright} 2009 RAS.},
archivePrefix = {arXiv},
arxivId = {0809.3437},
Loading