Index
Many run multi group fit
This is the flow of information in mujpy to produce the fit.
Back to Fit Types
Glossary:
- G indicates a parameter that is global with respect to both runs and group (e.g. muon fraction)
- gr indicates a parameter that is global with respect to run but varies with group (e.g. total asymmetry, A21 and A34, or phase, φ21 and φ34). They are dealt with by "function_multi"
- local or gg indicates a parameter that is global with respect to group, but varies with run (e.g. field or relaxation rates). They are dealt with by userpardicts lists.
The C2 fit is always preceded by a sequential B2 fit of the same multigroups, to obtain optimized guesses of the local parameters.
In dashboard, a json file containing a dict,
- key "userpardicts_guess" contains a list of use inserted parameters, each a dict with keys
- "name", the parameter name
- "value", the initial guess
- "error", the initial step
- "flag", "~" or "!"
- limits, a list [maxvalue,minvalue] (json's null is automatically translated to None)
- key "model_guess" contains a list, in the order of their appearance in the model-name string, of
- component dicts, each with keys "name", component two letter name, "label", specific name suffix, "pardicts", a dict of
- parameter dicts, each with keys
- "name", standard parameter name,
- "value", guess value,
- "flag", "=" (the only admitted value)
- "function", "" or "p[k]" or calculable expression in terms of p, where p = Minuit parameter array
- "error_propagation", a string that evaluates as the error of this component parameter, as a function of Minuit parameters
p
and errors e
; typical example: amplitude as product of two Minuit parameters, fraction (p[0]
) and total asymmetry (p[1]
), the error string is "sqrt((e[0]*p[1])**2+(p[0]*e[1])**2)"
.
- "function_multi", a list of as many strings as the groups, with a different assignment for each group
- "error_propagation_multi", a list of as many strings as the groups, with different error evaluation assignment for each group (needed if
- "error", not used
- "limits", not used
The dashboard is modified in the code after the preliminary sequential B2 fit. This modification is not saved, in order to start always from a guess dashboard.
- First of all each parameters of the original "userpardicts_guess" list is identified by its index k.
Then a new key is added
- "userpardicts", containing an augmented list of user parameters, each a list of dicts (as many as the runs), so that each dict corresponds to a Minuit parameter.
- G and gr parameters correspond to a one-member list with the original dict
- local gr parameters get replicas, as many dict items as the number of runs. In each replica
- the "value" item of the original pardict is updated to the corresponding best fit value of the B2 fit for this run;
- nmin is the index of this (first) local parameter in the Minuit list and it is initially decremented by one;
- a "function_local":[] key is added to to the corresponding "model_guess" parameters. These parameters (can be ore than one, e.g. shared field) are identified as all those whose "function" is equal to the simple string "p["+str(k)+"]" (local parameters cannot be linear functions of several Minuit parameters).
- nmin is incremented by one for each run and a list per run is appended to the "function_local" key, containing as many replica of the string "p["+str(nmin)+"]" as there are groups
The general rule for parameter evaluation, implemented by int2_multigroup_multirun_method_key, is simple
- the model is scanned and a list of lists of function strings is produced, one list per run, with as many items as groups
- for each G parameter, recognized by a non empty "function" string, all the elements in the inner and middle list is a replica of this "function" (same value for all)
- for each gr parameter, recognized by a "function_multi" key corresponding to list of strings, all the inner lists are equal to this list of strings.
- for each local parameter, there is a "function_local" key corresponding to this list of lists
The rest has to be implemented
For example model "mgml" contains two components, "mg", a Gaussian-relaxing precession, and "ml" a Lorentzian-relaxing precession, each with four parameters. If "mg" "label" is "_fast", its parameters have "_fast" appended to their names.
aux int2min_multigroup_multirun produces the Minuit list of guess parameter values by scanning the model components, in the order in which they appear in "mgml". It
- scans the "userpardicts" list, looking for lists of len>1; e.g. "B", for each k-th item it produces a replica "B", unique name "B_"+str(k)
- parameters with key "function_multi" are already taken care of by the userpars they refer to.
aux int2_multigroup_multirun_method_key takes care of passing the right parameter to the right component method. It produces a list of [method, keys], one per method, where keys is a list of lists of lists. The inner correspons to groups, the middle to runs, the outer to parameters of that component
- method is the python function from mucomponents mumodel that calculates the component, as in
f = method(t,*argv)
, where t is the 1-d time array, argv is a list of the dashboard parameter values for that component, and f is an array with the same shape as t
- argv is calculated as
[eval(key) for key in keypar for keypar in keyruns for keyruns in keygroups]
, therefore key is a string like "p[3]" (assuming that p
is the array of parameter values passed by Minuit at this iteration)
aux min2int translates back bet fit values to component parameters
mumodel _load_data_multigroup_multirun_ preloads 1-d time, 3-d asymmetry and 3-d asymmetry errors, methods and key lists.
mumodel _chisquare_ is the cost function; the same works also for multidimensional asymmetries, because np.sum adds by default over all dimensions.
mumodel _add_multigroup_multirun_ assigns the correct parameters to each component, calculated from the Minuit array of parameters. It must produce a three dimensional f function, with as many bins as time, as many groups and runs as asymmetry
the_model._load_data_(time,asymmetry,...)
,
m = Minuit(the_model._chisquare_,names,*values)
m.errors = errors
, etc
m.migrad()
Minuit migrad()
method calls
the_model._chisquare_
, which in turns calls
the_model._add_multigroup_multirun_(x,*argv)
, where argv
is the Minuit array of parameters. Their assignment to component methods is performed
- scanning the method list
- scanning the keys list of each method and evaluating each key
Back to Fit Types
Index