How to use the iminuit.util function in iminuit

To help you get started, we’ve selected a few iminuit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flav-io / flavio / flavio / math / optimize.py View on Github external
def minimize_migrad(fun, x0, args=(), dx0=None, **kwargs):
    """Minimization function using MINUIT's MIGRAD minimizer."""
    import iminuit
    mfun = MinuitFunction(f=fun, dim=len(x0), args=args)
    # bring the parameters in a suitable form
    par = iminuit.util.describe(mfun)
    x0_dict = {par[i]: x0i for i, x0i in enumerate(x0)}
    if dx0 is None:
        dx0 = np.ones(len(x0))
    dx0_dict = {'error_' + par[i]: dx0i for i, dx0i in enumerate(dx0)}
    # run
    minuit_args={'errordef': 1}
    minuit_args.update(kwargs)
    minuit = iminuit.Minuit(mfun, **x0_dict, **dx0_dict, **minuit_args)
    fmin, param = minuit.migrad()
    # cast migrad result in terms of scipy-like result object
    res = scipy.optimize.OptimizeResult()
    res.success = fmin['is_valid']
    res.fun = fmin['fval']
    res.x = np.array([p['value'] for p in param])
    res.nfev = fmin['nfcn']
    return res
github phoebe-project / phoebe2 / phoebe / backend / fitting.py View on Github external
self.param_names = []
        for parset in system.walk():
            #-- for each parameterSet, walk to all the parameters
            for qual in parset:
                #-- extract those which need to be fitted
                if parset.get_adjust(qual) and parset.has_prior(qual):
                    #-- ask a unique ID and update the value of the parameter
                    this_param = parset.get_parameter(qual)
                    myid = this_param.get_unique_label().replace('-','_')
                    if myid in had: continue
                    id_for_minuit = '{}_{}'.format(qual,myid)
                    setattr(self,id_for_minuit,this_param.get_value())
                    had.append(myid)
                    self.param_names.append(id_for_minuit)
                    
        self.func_code = iminuit.util.make_func_code(self.param_names)
        self.func_defaults = None
        #-- construct the iminuit Minimizer

iminuit

Jupyter-friendly Python frontend for MINUIT2 in C++

MIT
Latest version published 1 month ago

Package Health Score

84 / 100
Full package analysis

Similar packages