Dispense
Navigation
Tips - Dritte
PmWiki
pmwiki.org
edit SideBar
|
< Different ways of parameter indexing | Index | Mujpy.FitRebinned >
Check the following code for evaluating "function" strings:
p = np.array([1,2,3,4,5])
key ='p[3]'
p_as_l = eval ('lambda :'+key)
def p_as_lambda(k):
pasl = eval ('lambda :'+k)
return pasl
%timeit eval(key)
5.18 µs ± 37 ns 10^5 iters
%timeit p_as_l()
150 ns +- 3 ns 10^7 iters
%timeit p_as_lambda(key)
8.29 µs ± 84 ns 10^5 iters
The plain lambda wins but is hard encoded with a given key.
One must hard encode one function per key.
fun = eval ('lambda p:'+key)
fun1(p)
4
%timeit fun1(p)
153 ns ± 1.25 ns over 10^7 iters
A improvement by over a factor 30.
|
|
In mucomponent
- _load_data_ identifies the six (?) types of fits by their flag and assigns the self._add_component_ method accordinglyto one of six replicas of the method, tailored for that type:
- fit results depend on number of calculated chi2, i.e. A1, A2, C1, C2 only one, while B! and B2 as many as the runs in the suite.
- A2, C1, C2 require new post-processing methods to compute their partial chi2, restricted to the group or run, or group and runrespectively, using only the subset of relevant parameters. Maybe a clever layout of the their replicas can achieve this: the parametersare distributed to partial functions, the total chi2 is the sum of the partial chi2, so that partial chi2 can be calculated with another switchyard
In mugui mani structures must be addressed:
- asymmetry can define a 3d array, with shape (nbins,ngroups,nruns)
- fit layout depends on type, below an if structure
- this is progressively recognized. Can each be a method of its own?
- draw_top_fit_box
- draw_external_box conditional for external global (C1, C2)
- draw_forward_backward_alpha box conditional for no multi (A1,B1,C1)
- draw_forward_backward_alpha_multi box alternative for (A2,B2,C2) with DO GROUPS button
- draw group G1 box
- check C1 for rlocal tick
- check A2 for glocal tick
- check C2 for rlocal/glocal/none dropdown
- on DO GROUPS draw_other_groups_box
- minuit results is the ex fitargs, now a structure made of a list of lists (one per fit) of four lists (fitval, fiterr, fitfix and fitlim)
- keeping the structure allows to have a single procedure with
if s, complicated. Otherwise one can switchyard (with longer code)
- debug-wise the longer code means better readability but a bug in a generic, replicated part, must be chased six times
- list of parts that are best switchyarded just before launching the fit, in
on_fit_request
min2int , int2min , back and forth parameter value dispatch between mugui and mumodel
- relie on
self.model_components , reading the dashboard (internal) parameters, and on self.flag plus aux.translate
self.model_components must be refactored, old version is:
- it is reset to
[] in create_model
- it is initialized by
addcomponent appending a dictionary for each component,{'name':name,'pars':{'name':parname+label,'value':0.0,'flag','~',function':'',}
- it is saved in
save_fit and loaded in load_fit to/from the pickle dictionary key'self.model_components' and saved to a similar dictionary.
- new version must make way for
- A1, B1 same
- A2, B2 same with additional
pars key 'local':'None' (internal parameters can be group local)
- A2, B2 on DO GROUPS replicate all components for each group
- composing new names, copying functions for '=' parameters and translating their indices
- adding function '=P[n]' for each non glocal parameter equivalent to n, both '~' and '!' ones
- B1,B2 either start from a common point or perform chain-fit (the values are updated before moving to the next run in the suite)
- C1, C2 start with additional external parameters,
{'name':'xt','pars':{'name':name,'value':0.0,'flag','~','local':'None',} and with additional pars key 'local':'None' (internal parameters can be group/run local)
- C2 replicates external parameters that are set glocal as many times as the number of group
- C2 on DO GROUPS replicate all components for each group
- for each non glocal composing new names, copying functions for '=' parameters, adding function '=P[n]' parameter equivalent to n, both '~' and '!' ones
- copying names and adding function '=P[n]' for each rlocal parameter equivalent to n, both '~' and '!' ones
- C2 finally replicates rlocal parameters
- in all cases the dashboard allows the user to modify values, fit flags, functions and glocal, rlocal flags
int2_int for method and parameter distribution inside class mumodel, can follow same switch as in mucomponent (the library of mumodel)
save_fit , load_fit , write_csv to save, load results in files and write on console, csv summary file.
- the pickled dictionary contains keys that reproduce fit methods (variables):
- self.alpha.value (rethink), self.offset.value, self.grouping (rethink)
- model.value, self.model_components, version, nint (remove?), self.fit_range.value, self.plot_range.value, self._global_, self._single_ (rethink)
fitplot
|
|
- list of switch condition method, used in mufit.choosefit, mufitplot.chooseplot and elsewhere:
suite.single() : single run vs. multiple runs, True for A1, A2 fit
suite.calib() : special calibration fit (alpha is first Minuit parameter p[0] ), additinal option, can be True only for A1, A2
suite.multi_groups() : in True for A2,B2,C2 coincides with the suffix 2, (further distinction A2_0 (fit performed sequentially) and A2_1 (see next)
aux.multigroup_in_components(dashboard) : checks for "function_multi", indicating multigroup fit (must have allcomponent parameters set to functions (no "flag":"~" ), with those that are different by group dealt with "function_multi" ; fits
tilde_in_components(self.dashboard) , checks the presence of component parameter "flag":"~" the equivalent of musrfit global+, i.e.multirun [possibly multigroup] global fit, True in C1, C2
- list of
mufit.dofit_ methods:
dofit_singlerun_singlegroup : A1
dofit_calib_singlerun_singlegroup : A1_calib (possibly to be used by A2_0.calib sequential)
dofit_singlegroup_sequential : B1
dofit_singlerun_multigroup_sequential : A2_0
dofit_singlerun_multigroup_userpardicts : A2
dofit_calib_singlerun_multigroup : A2 calib
dofit_singlegroup_userpardicts : C1
dofit_sequentialrun_multigroup_userpardicts : B2
dofit_multirun_multigroup_userpardicts : C2
|
Table of switch values: each type of fit must have a unique switch signature
| A1
| A1_calib
| A20
| A20_calib
| A21
| A21_calib
| B1
| B2_0
| B2_1
| C1
| C2
| suite.single()
| True
| True
| True
| True
| True
| True
|
|
|
|
|
| suite.calib()
|
| True
|
| True
|
| True
|
|
|
|
|
| suite.multi_groups()
|
|
| True
| True
| True
| True
|
| True
| True
|
| True
| userpar
|
|
|
|
| True
| True
|
|
| True
| True
| True
| tilde_in_components
| True
| True
| True
| True
|
|
| True
| True
|
| True
| True
|
< Different ways of parameter indexing | Index | Mujpy.FitRebinned >
|