CobayaSampler / cobaya

Code for Bayesian Analysis
http://cobaya.readthedocs.io/en/latest/
Other
126 stars 125 forks source link

Some `scipy` distributions do not have a `"scale"` parameter #361

Closed AdamOrmondroyd closed 3 months ago

AdamOrmondroyd commented 3 months ago

Some of the continuous distributions in scipy.stats do not have a "scale" parameter, but cobaya fails if it is not in the kwargs for a general distribution.

e.g:

params:
  x:
    prior:
      dist: beta
      a: 2
      b: 1

causes the following error:

Traceback (most recent call last):
  File "/Users/adam/phd/pinch/pinchihood.py", line 29, in <module>
    cobaya.run("pinch.yaml", resume=resume, force=not resume,
  File "/Users/adam/programming/cobaya/cobaya/run.py", line 120, in run
    with Model(updated_info["params"], updated_info["likelihood"],
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/programming/cobaya/cobaya/model.py", line 241, in __init__
    self.prior = Prior(self.parameterization, self._updated_info.get("prior"))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/programming/cobaya/cobaya/prior.py", line 426, in __init__
    self.pdf += [get_scipy_1d_pdf(prior)]
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/programming/cobaya/cobaya/tools.py", line 572, in get_scipy_1d_pdf
    if kwargs["scale"] < 0:
       ~~~~~~^^^^^^^^^
KeyError: 'scale'

I believe this is easily fixed by using kwargs.get("scale", 1) rather than kwargs["scale"]

codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.82%. Comparing base (c8c9b49) to head (b8802b6).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #361 +/- ## ======================================= Coverage 81.82% 81.82% ======================================= Files 146 146 Lines 11177 11177 ======================================= Hits 9146 9146 Misses 2031 2031 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.