Could not find random point giving finite posterior after 10000 tries

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Nikolai Kozameh
Posts: 3
Joined: August 28 2024
Affiliation: IATE - CONICET - UNC

Could not find random point giving finite posterior after 10000 tries

Post by Nikolai Kozameh »

Hello everyone!
In this my first time running cobaya for a cosmological likelihood. I want to get the plot Omega_m vs Omega_dark energy. I am goint to describe my steps:
I got my measured Cls from a cmb-map done by synfast with the CAMB input.
My cosmological parameters for CAMB are pars = camb.set_params(H0=67.5, ombh2=0.0221, omch2=0.121, tau=0.06, As=2.09e-9, ns=0.963, halofit_version='mead', lmax=2500). Then. I prepare my likelihood and dictionary,

Code: Select all

from cobaya.likelihood import Likelihood
import numpy as np

class MyLikelihood(Likelihood):
    
    def initialize(self):
        """
        Prepare any computation, importing necessary code, files, etc.
        Here, we load the Cls data.
        """
        # Load your data file, for example, experimental Cls
        self.data = np.loadtxt("Cls")  # Replace "Cls.txt" with your actual file
        
        # If you have associated errors, load them similarly (uncomment below if needed)
        # self.errors = np.loadtxt("sigma.txt")
    
    def get_requirements(self):
        """
        Return dictionary specifying quantities calculated by a theory code.
        Here, we request C_l^{tt} (temperature) up to lmax = 2552.
        """
        return {'Cl': {'tt': 2554}}  # You can request other spectra like 'ee', 'te' if needed.
    
    def logp(self, **params_values):
        """
        Compute the log-likelihood given a set of parameter values.
        """
        # Get the theoretical Cls from the theory code (e.g., CAMB or CLASS)
        cls = self.provider.get_Cl(ell_factor=True)

        # Calculate chi-squared: sum of squared differences between data and theory Cls
        chi2 = np.sum((self.data - cls['tt'][2:]) ** 2)  # Skipping ell=0,1 as usual

        # Return the log-likelihood (-0.5 * chi2)
        return -0.5 * chi2

info = {
    "likelihood": {
        "My_custom_likelihood": MyLikelihood
    },
    # Theory block for CAMB
    "theory": {
        "camb": {
            "extra_args": {
                "lmax": 2554,
                "lens_potential_accuracy": 0
            }
        }
    },
    # Parameters
    "params": {
        "ombh2": {
            "prior": {"min": 0.005, "max": 0.1}, 
            "ref": {
                "dist": "norm",
                "loc": 0.0221,
                "scale": 0.0001
            },
            "proposal": 0.0001,
            "latex": r"\Omega_b h^{2}"
        },
        "omch2": {
            "prior": {"min": 0.001, "max": 0.99}, 
            "ref": {
                "dist": "norm",
                "loc": 0.121,
                "scale": 0.001
            },
            "proposal": 0.0005,
            "latex": r"\Omega_c h^{2}"
        }
    },
    
    # Sampler
    "sampler": {
        "mcmc": {
            "Rminus1_stop": 0.001,
            "max_tries": 10000
        }
    },
    # Output and resuming settings
    
    "resume": False  # Disable resuming
}
updated_info, sampler=run(info)
camb] `camb` module loaded successfully from /home/akozameh/miniconda3/envs/CMB/lib/python3.10/site-packages/camb
[mcmc] Getting initial point... (this may take a few seconds)
[model] *ERROR* Could not find random point giving finite posterior after 10000 tries.
’m not sure how to resolve this issue and would appreciate any advice or suggestions. Has anyone run into a similar error when running a cosmological likelihood in Cobaya?

Thanks in advance!
Antony Lewis
Posts: 1983
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Could not find random point giving finite posterior after 10000 tries

Post by Antony Lewis »

Just with --debug to get more detailed trace. (your likelihood seems not to use any error model)
Nikolai Kozameh
Posts: 3
Joined: August 28 2024
Affiliation: IATE - CONICET - UNC

Re: Could not find random point giving finite posterior after 10000 tries

Post by Nikolai Kozameh »

Hello Anthony!
I put debug and I got this:
[outputdummy] No output requested. Doing nothing.
[run] Input info updated with defaults (dumped to YAML):
theory:
camb:
version: null
path: null
speed: 0.3
stop_at_error: false
extra_args:
stop_at_error: true
lmax: 2552
lens_potential_accuracy: 0
ignore_obsolete: false
use_renames: false
external_primordial_pk: false
renames:
omegabh2: ombh2
omegach2: omch2
omegal: omega_de
omegak: omk
yhe: YHe
yheused: YHe
YpBBN: Y_p
likelihood:
My_custom_likelihood:
type: []
speed: -1
stop_at_error: false
version: null
external: !!python/name:__main__.MyLikelihood ''
params:
ombh2:
prior:
min: 0.005
max: 0.1
ref:
dist: norm
loc: 0.0221
scale: 0.0001
proposal: 0.0001
latex: \Omega_b h^{2}
renames:
- omegabh2
omch2:
prior:
min: 0.05
max: 0.5
ref:
dist: norm
loc: 0.121
scale: 0.001
proposal: 0.0005
latex: \Omega_c h^{2}
renames:
- omegach2
sampler:
evaluate:
N: 1
override:
omch2: 0.121
seed: null
version: null
debug: true
resume: false

[camb] Attempting import of Cobaya-installed version, but defaulting to global import if not found.
[camb] 'camb' to be imported from (sub)directory /home/akozameh/cmblss/code/cmblss-main/code/CAMB
[camb] Could not import 'camb' from /home/akozameh/cmblss/code/cmblss-main/code/CAMB: Module camb successfully loaded, but not from requested path: /home/akozameh/cmblss/code/cmblss-main/code/CAMB, but instead from /home/akozameh/miniconda3/envs/CMB/lib/python3.10/site-packages/camb
[camb] Defaulting to global import.
[camb] `camb` module loaded successfully from /home/akozameh/miniconda3/envs/CMB/lib/python3.10/site-packages/camb
[model] Parameters were assigned as follows:
[model] - My_custom_likelihood:
[model] Input: []
[model] Output: []
[model] - camb.transfers:
[model] Input: ['ombh2', 'omch2']
[model] Output: []
[model] - camb:
[model] Input: []
[model] Output: []
[model] Components will be computed in the order:
[model] - [camb.transfers, camb, My_custom_likelihood]
[model] Requirements will be calculated by these components:
[model] - Cl: camb
[model] - CAMB_transfers: camb.transfers
[evaluate] Initialized!
[evaluate] Looking for a reference point with non-zero prior.
[prior] Evaluating prior at array([0.0220815 , 0.12029963])
[prior] Got logpriors (internal) = 3.152386083599368
[evaluate] Reference point:
ombh2 = 0.0220815
omch2 = 0.121
[evaluate] Evaluating prior and likelihoods...
[model] Posterior to be computed for parameters {'ombh2': 0.022081503769715072, 'omch2': 0.121}
[prior] Evaluating prior at array([0.0220815, 0.121 ])
[prior] Got logpriors (internal) = 3.152386083599368
[model] Got input parameters: {'ombh2': 0.022081503769715072, 'omch2': 0.121}
[camb.transfers] Got parameters {'ombh2': 0.022081503769715072, 'omch2': 0.121}
[camb.transfers] Computing new state
[camb] Setting parameters: {'ombh2': 0.022081503769715072, 'omch2': 0.121} and {'stop_at_error': True, 'lmax': 2552, 'lens_potential_accuracy': 0}
[model] Calculation failed, skipping rest of calculations
[evaluate] log-posterior = -inf
[evaluate] log-prior = 3.15239
[evaluate] logprior_0 = 3.15239
[evaluate] log-likelihood = -inf
[evaluate] chi2_My_custom_likelihood = inf
[evaluate] Derived params:
Antony Lewis
Posts: 1983
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Could not find random point giving finite posterior after 10000 tries

Post by Antony Lewis »

Right, so then use it to debug (why you are getting infs)
Nikolai Kozameh
Posts: 3
Joined: August 28 2024
Affiliation: IATE - CONICET - UNC

Re: Could not find random point giving finite posterior after 10000 tries

Post by Nikolai Kozameh »

Thank you Anthony!
Post Reply