Giter Club home page Giter Club logo

Comments (4)

matthewfeickert avatar matthewfeickert commented on June 5, 2024

Hi @andrewfowlie. This is a bug of documentation and another reason we need to get types in at some point. The v0.7.5 pyhf.infer.hypotest docs give fixed_params as

fixed_params (:obj:`tensor` of :obj:`bool`): The flag to set a parameter constant to its starting
value during minimization.

but it should be a tuple or list of bool.

Here's your example, but working:

import pyhf

pyhf.set_backend("numpy")

model = pyhf.simplemodels.uncorrelated_background(
    signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
)
observations = [51, 48]
data = pyhf.tensorlib.astensor(observations + model.config.auxdata)
mu_test = 1.0

fixed_params = model.config.suggested_fixed()
fixed_params[1:] = True, True  # The POI can't be fixed and still perform inference
print(f"Fixed parameters: {fixed_params}")

cls_obs, cls_exp_band = pyhf.infer.hypotest(
    mu_test,
    data,
    model,
    fixed_params=fixed_params,
    return_expected_set=True,
    test_stat="qtilde",
)

print(f"Observed CLs: {cls_obs}")
print(f"Expected CLs band: {cls_exp_band}")

# tuple is valid too
fixed_params = tuple(fixed_params)
pyhf.infer.hypotest(
    mu_test,
    data,
    model,
    fixed_params=fixed_params,
    return_expected_set=True,
    test_stat="qtilde",
)
Fixed parameters: [False, True, True]
Observed CLs: 0.02127891847130824
Expected CLs band: [array(0.00080112), array(0.00552974), array(0.03326288), array(0.15388567), array(0.45916615)]

from pyhf.

andrewfowlie avatar andrewfowlie commented on June 5, 2024

Thanks Matthew, using a list or tuple works for me. Yes it's a small bug in the docs.

from pyhf.

matthewfeickert avatar matthewfeickert commented on June 5, 2024

@andrewfowlie This is now corrected in the pyhf v0.7.6 docs.

from pyhf.

andrewfowlie avatar andrewfowlie commented on June 5, 2024

Thanks Matthew. I think that this affects the init_pars and par_bounds docs too.

from pyhf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.