Code Monkey home page Code Monkey logo

Comments (3)

HDembinski avatar HDembinski commented on July 29, 2024

The cost functions that accept a parametric model like ExtendedBinnedNLL use the function iminuit.util.describe(model, annotations=True) to detect the parameters of the model (the first argument is skipped).

You can override self._parameters in the cost function, but the intention is to add the special attribute _parameters to your model function. This can be done even if that function is a normal Python function or a lambda, because in Python everything is an object.

def my_model(x, *args): ...

# use my model with 3 parameters
my_model._parameters = {x: None, a: None, b: None, c: None}
nll = ExtendedBinnedNLL(counts, bin_edges, my_model)
Minuit(nll, ...).migrad()  # get results for 3 parameters

# use my model with 2 parameters
my_model._parameters = {x: None, a: None, b: None}
nll = ExtendedBinnedNLL(counts, bin_edges, my_model)
Minuit(nll, ...).migrad()  # get results for 2 parameters

Your solution works as well, but I don't think it is a good idea to add a public interface for this.

I don't want normal users to set parameters manually, because this is supposed to be handled behind the scenes by iminuit. For experts like you who need this, there is the option to provide the special _parameters attribute. This is documented in iminuit.util.describe.

from iminuit.

HDembinski avatar HDembinski commented on July 29, 2024

Adding a name keyword to the constructor of the cost functions seems like a possibility to me, but I need to think about the possible consequences.

from iminuit.

lvarriano avatar lvarriano commented on July 29, 2024

Thanks for the detailed explanation and for pointing me towards iminuit.utils.describe!

from iminuit.

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.