[Tutor] constructing semi-arbitrary functions

"André Walker-Loud <walksloud@gmail.com>" walksloud at gmail.com
Wed Feb 19 20:56:19 CET 2014


Hi eryksun,

Indeed, I am using iminuit to interface with Minuit.
That is where I am learning to make my own classes to set up my functions to pass into the minimizer.  I also happened to get the string-hack to work (which requires using global variables). Instead of just copying (since it works) I am also trying to improve my programming knowledge at the same time - hence this whole thread.

Minuit is a sophisticated minimizer, which means it is important to set initial values, expected uncertainties on the parameters, etc.  Minuit uses your estimate of the parameter uncertainties to set up the grid step-size it uses to search the parameter space.  So sloppiness here can screw up the minimization getting one stuck in a local min (to small error estimate) or spend too much time wondering around (too large error estimate).


Cheers,

Andre


On Feb 19, 2014, at 10:17 AM, eryksun <eryksun at gmail.com> wrote:

> On Wed, Feb 19, 2014 at 7:33 AM, Oscar Benjamin
> <oscar.j.benjamin at gmail.com> wrote:
>> I don't really understand why it works that way though.
>> Looking here
>> 
>>   http://iminuit.github.io/iminuit/api.html#function-sig-label
> 
> This API is unusual, but co_argcount and co_varnames should be
> available and defined as per the spec:
> 
> http://docs.python.org/2/reference/datamodel#index-59
> 
>    CPython/PyPy      Jython
>    =========================
>    co_name           *
>    co_argcount       *
>    co_nlocals        *
>    co_varnames       *
>    co_cellvars       *
>    co_freevars       *
>    co_filename       *
>    co_firstlineno    *
>    co_flags          *
>    co_code
>    co_consts
>    co_names
>    co_lnotab
>    co_stacksize
> 
> The last few attributes aren't relevant to Jython since it's using the JVM.
> 
> To its credit, util.better_arg_spec does fall back on
> inspect.getargspec. But then, its ultimate fallback is regex magic:
> util.arguments_from_docstring. Wow. I guess it's convenient to specify
> initial values, step size, limits, etc, as keyword arguments for named
> parameters.
> 
> I haven't read this whole thread, but here are some source links if
> the OP is using this iminuit package. The `describe` function is in
> util.py.
> 
> https://github.com/iminuit/iminuit/blob/master/iminuit/util.py
> https://github.com/iminuit/iminuit/blob/master/iminuit/_libiminuit.pyx
> 
> Some snippets from Minuit.__init__:
> 
>    args = describe(fcn) if forced_parameters is None\
>           else forced_parameters
> 
>    # ...
> 
>    self.initialvalue = {x:maplookup(kwds,x,0.) for x in args}
>    self.initialerror = \
>        {x:maplookup(kwds,'error_'+x,1.) for x in args}
>    self.initiallimit = \
>        {x:maplookup(kwds,'limit_'+x,None) for x in args}
>    self.initialfix = \
>        {x:maplookup(kwds,'fix_'+x,False) for x in args}
> 
>    # ...
> 
>    self.parameters = args
>    self.args = tuple(self.initialvalue[k] for k in args)
>    self.values = {k:self.initialvalue[k] for k in args}
>    self.errors = {k:self.initialerror[k] for k in args}



More information about the Tutor mailing list