cobaya icon indicating copy to clipboard operation
cobaya copied to clipboard

Simple implementation for vector parameters

Open JesusTorrado opened this issue 3 years ago • 5 comments

JesusTorrado avatar Aug 12 '21 15:08 JesusTorrado

@cmbant do you want to take a look before merge? Should be done.

It's just documentation and better error control.

Only actual change needed is in getdist (see https://github.com/cmbant/getdist/pull/68)

Minimal working example:

from scipy import stats


def gauss_band(x_vector):
    return stats.norm.logpdf(
        x_vector[0] + x_vector[1], loc=1, scale=0.02)

# NB: don't forget the 'drop: True' in the individual parameters
#     and 'derived: False' in the vector parameters

info = {
    "likelihood": {"band": gauss_band},
    "params": {
        "x": {"prior": {"min": 0, "max": 2}, "proposal": 0.1, "drop": True},
        "y": {"prior": {"min": 0, "max": 2}, "proposal": 0.1, "drop": True},
        "x_vector": {"value": lambda x, y: [x, y], "derived": False}},
    "sampler": {"mcmc": None}}

info["force"] = True
info["output"] = "chains/band"

from cobaya.run import run
updated_info, sampler = run(info)

JesusTorrado avatar Aug 12 '21 16:08 JesusTorrado

Interesting that just works, looks OK to me though have not tested.

cmbant avatar Aug 12 '21 19:08 cmbant

Yeah, surprisingly easy. I vaguely remember seeing this applied to some weird "vector is string form" of CLASS by @nataliehogg in some issue that I cannot find at the moment (so @nataliehogg, if you see this and can confirm, I am happy to give you credit in the changelog). (EDIT: it was actually @lukashergt, sorry!)

As for mergning, I would wait until the next GetDist release, since it's a requirement.

JesusTorrado avatar Aug 13 '21 12:08 JesusTorrado

Yeah, surprisingly easy.

To a big part that is down to the nice flexible input setup of Cobaya. Glad #110 proved helpful.

lukashergt avatar Aug 16 '21 21:08 lukashergt

Codecov Report

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

Project coverage is 81.82%. Comparing base (50309b2) to head (cf0cbd8).

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #191      +/-   ##
==========================================
+ Coverage   81.81%   81.82%   +0.01%     
==========================================
  Files         146      146              
  Lines       11172    11173       +1     
==========================================
+ Hits         9140     9142       +2     
+ Misses       2032     2031       -1     

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

codecov-commenter avatar Feb 24 '22 12:02 codecov-commenter