|
Dispense
Navigation
Tips - Dritte
PmWiki
pmwiki.org
edit SideBar
|
Index
Back to Mujpy
Debug
12/05/26 trying to run python scripts and jupyter-lab in parallel (use gedit or gvim, not text editor!)
- PARTIALLY SOLVED clarify syntax for json input file names: model. group, version (done with tools version_flag, CHECK THROUGH MODES)
- DONE cvs in each fitting mode (A1, etc.) should have its distinct csv
- DONE added offset to log terminal and cache
- DONE log dt now includes pack
- DONE simplified write_csv using init_csv_row and prepare_csv_row in summary,
- WARNING wrong header in A21 (prepare_csv_row)
- init_csv_row does not consider root data, now read make a test for a single run single group fit
- still chi three digits B1 skips one field before chi_r
- DONE test.py script including all DONE cases below
- DONE A1, A20, A1_calib, A20_calib, A21,A21_calib, B1, B1 calib
- DONE B20, B20 calib, B21, B21 calib, C1, C1 calib, C2, C2 calib
- '#' is limited to C1 and C2
- model parameter flag can only be '=' in global fits A21, B21, C1 and C2
- 'function-multi' is limited to A21, B21, C2
- 'function' is used by all, in A1, A20, B1, B20 to share parameters, in the global fits A21, B21, C2 to define the same behaviour for the different groups
- 'function' and 'function-multi' are mutually exclusive
New fit
- all have own _calib version, logging see below
- A1, A20, B1, B20 use only model parameters (no userpardicts_guess), fit is like now, only standardized
- A1 is true single run single group, A20, B1, B20 group, run, and group/run sequential use the same fit methods (slightly different logs)
- Only model parameters, identified by internal index k (listed in dash), with json assigned 'values', errors', limits','positive_parity' and 'flag': '~','!' or
- '=' 'function':'p[k]' for sharing model parameters
- A21, B21, C1, C2 minuit parameters are only userpardicts, with 'value','error','limits','positive_parity' and
- 'flag':
- '~' global
- '!' fixed
- '#' local run replicas
- model parameters can only have flag '=' and either function or function_multi)
int2min_multirun_multigroup assigns 'values', errors', 'fix','limits', 'names', 'positive_parity' for all global fits
- A1, A20, B1, B20 if not 'userpardicts_guess' int2min, else the present code
int2_multirun_multigroup_method_key cares for all fits (including A1, A20, B1, B20) by choosing among nostack, cstack, ccstack
- no need for 'error_propagate' in json, it will be calculated by error_propagation and sympy.
- identification in mufit - self.A1() ... self.C2() - must be rechecked, use:
- suite.multirun(), suite.multigroup(), suite.single(),
- mufit.tilde_in_component(), mufit.userpar(), mufit.calib()
- mufit.hash_in_component() becomes always False, turn it into mufit.hash_in_userpar()
New fit logging
- filenames based on
mname: 'almgml', 'mgbl', etc
-
run: '822', '822+' (*) plus is reserved for multirun, the first is listed
strgrp: '3-4', '3.4.2-1', '3-4_2-1' ('_' stands for global groups)
version: '1_A1', '2B_C1'
- fit model saved in mname.run.strgrp.'1_fit'.json (guess), '1_C2' (guess and results)
- terminal or jupiter,
- header + model components for A1
- common header, per group header + model components, A20, A21
- common header, per run header + model components, B1, C1
- common header, per group header, per run header + model components, B20, B21, C2
- file log replica of the above in folder cache/filename
mname.run.strgrp.version.log
- csv in folder csv/filename:
mname.strgrp.version.csv with model component list, for A1, B1, C1
mname.version.csv with group, model component list, for A20, B20, A21, B21, C2
M_mname.version.csv with minuit parameters, for A21, B21, C1, C2
C2_calib Eventually all fits could be dealt like this. For instance A1 data would become [asymm, asyme?], userpars would be present, but empty, group would contain only one, etc.
- e.g. groups 34, 12, TF mgml fit on runs 822, 834:823:-1 (13 runs). The fit has 13*3+6 = 45 parameters
- 6 userpars [0:5]: 0-{$\alpha$}34, 1-{$\alpha$}21, 2-f, 3-A34, 4-A21, 5-{$\phi$}
- guess almgml: the dash presents parameter (internal) indices: 6-α, 7-A0, 8-B0, 9-φ0, 10-σ0, 11-A1, 12-B1, 13-φ1, 14-λ1
- "=" "function multi": 6-α ['p[0]','p[1]'], 7-A0 ['p[2]*p[3]','p[2]*p[4]'], 9-φ0 ['p[5]','p[5]-90'], 11-A1 ['(1-p[2])*p[3]','(1-p[2])*p[4]'],13-φ1 ['p[5]','p[5]-90']
- "#" (local): 8-B0, 10-σ0, 14-λ1, run replicas see below, , all get renumbered with 834, 833 etc
- "=" "function": 12-B1 ["p[7]"] (which is redirected to run replicas)
- "=": "error-propagate-multi": 7-A0 ["sqrt((e[2]*p[3])**2+(p[2]*e[3])**2)","sqrt2(e[2]*p[4])**2+(p[2]*e[4])**2)"] simil for 11-A1
- "=": "error-propagate-multi": 9-φ0 ["e[5]","e[5]"] same for 13-φ1
- int2_multirun_multigroup_global replicates local parameters, B0, σ0, λ1 over runs, the same for all groups, attaching a label eg _822 to distinguish them (musrfit style).
- not a great fit across paramagnetic through ordered ranges, but it should converge
- helps to run fit type B1 (multirun sequential) first and extract local parameter values, B, {$\sigma$}, {$\lambda$} as guess. Could be automatized.
- e.g. ZF spin rotated mgmgbl on 34,21
- 5 userpars [0:4]: {$\alpha$}34, {$\alpha$}21, f, A34, A21. The fit has 13*3+5 = 41 parameters
- guess almgmgbl: the dash presents parameter indices: 5-A0, 6-B0, 7-φ0, 8-σ0, 9-A1, 10-B1, 11-φ1, 12-σ1, 13-Al, 14-λ
- "=" "function multi": α ['p[0]','p[1]'], A0 ['2/3*p[2]*p[3]','2/3*p[2]*p[4]'], A1 ['2/3*(1-p[2])*p[3]','2/3*(1-p[2])*p[4]'], Al ['p[3]/3','p[4]/3']
- "!": φ0 "value": 0. "flag": "!", φ1 "value": 0. "flag": "!"
- "#" (local): B0_822 (run replicas, same on both group)
- σ0_822 (run replicas, same on both group)
- B1_822 (run replicas, same on both group)
- σ1_822 (run replicas, same on both group)
- λ_822, (run replicas, same on both group), all get renumbered with 834, 833 etc
- val,err, fix, lim, name, pospar = int2min_xxx(pardicts) # or (dashboard,runs)
- must produce a single list of min indices-parameters, in the almgml example above 0-44:
- 0-α34, 1-α21, 2-f, 3-A34, 4-A21, 5-φ, 6-B0_822, 7-σ_822, 8-λ_822, 9-B0_834, 10-σ_834, 11-λ_834, ... 41-B0_823, 43-σ_823, 44-λ_823
- with values 0-5 from userpardicts, values 6-44 from a B2 prefit.
- construct the B2 prefit, chain, with all "#" parameters transformed in "~", in the example 6-B, 7-σ, 8-λ become userpars, the model internal index are renumbered 9-α, 10-A0, 11-B0 "flag" "=" "function" ["p[6]"], 12-φ0 13-σ0 "flag" "=" "function" ["p[7]"], 14-A1, 15-B1, 16-φ1 17-λ1 "flag" "=" "function" ["p[8]"]
- run it and distribute the las, t three userpar best values in the sequential fit to guess values of corresponding "#" parameters
- C2_calib almgml fit in TF at GPS
- flag ~,!,=,g,G,& for local, fixed, function, global group, global run, global all
- do first the B1_calib multirun sequential singlegroup fit for the two groups, 3-4 and 2-1
- then do the B21_calib multirun sequential multigroup global fit, with global {$B_0, B_1, \sigma, \lambda$}
- plot the G and & parameters from the almgml.1_B21.csv run ({$\alpha_i,A_{0i}, A_{1i}$}) or run-group global ({$\phi,(\phi+90)$})
- initialize C2_calib g values ({$B_{0x}, B_{1x} \sigma_x, \lambda_x$}) that have run-local values, from the B21 csv
- dash
fit csv
- init_csv_row prints csv of run #, temperatures, nominal field [, group (multigroup fits)]
- chi2_csv prints chi2 low_chi, high_chi, offset, datetime
- same scheme for calib fits
- A1 (manual), B1 (auto): one line per run with init_csv_row + model component values, stds + chi2_csv.
- A20, B20: more lines per run, one per group, each same as A1, B1
- A21, B21: minuit parameters coincide with user parameters. Two alternatives: same as A20, B20, with function and function_multi translation, or print just minuit parameters. Could do both?
- C1, C2: same alternatives.
set_key
def sk(string):
code = """
from numpy import pi
def foo():
string = " key = eval('"+'lambda p: '+string+"')"
code = code + string + """
return key
"""
exec(code,globals(),globals())
return (eval('foo()')
Execution
p = [10,11,12,13]
key = sk('p[2]')
# to obtain the result, 12
key(p)
- include deg2rad in set_key scope: A21, B21 and C2 ZF fits may require function_multi projections along 2-1 and 3-4 detector axes, say A34 = p[2], A21= p[3], {$\phi$}[deg] = p[4], e.g.
2*p[2]/3*cos(deg2rad(p[4])),2*p[3]/3*sin(deg2rad(p[4]))
Asymmetry error
- mucomponents:
_add_norebin_ is exclusively used by mufitplot to obtain well sampled function (never used for errors)
_asymmetry_ recalculates asymmetries for all calib fits, where alpha is a minuit parameter
- asyme can be calculated in two way, which turn out to be equivalent for the rebinned asymmetry, under the hyp of independent stds:
- on rebinned asymm, where {$e_A^2 = \sum_{i=1}^n e_{Ai}^2$} with {$e_{Aì}^2 = (dA_i/dy_{fi})^2 e_{yfi}^2 + (dA_i/dy_{bi})^2 e_{ybi}^2$}
- on rebinned data, where {$e_A^2 = (dA/dy_{f})^2 e_{yf}^2 + (dA/dy_{b})^2 e_{yb}^2$} and {${e_{y\phi}}^2= \sum_{i=1}^n e_{y\phi i}^2$}, {$\phi=f,b$}
- 1. and 2. are equivalent if {$dA_i/dy_{\phi i} = dA/dy_{\phi}, \forall i \in (1,n)$}, which means that, given time bin {$dt$}, a cut-off frequency {$1/ndt$} distinguishes high frequency components, whose noise is averaged out, from low frequency components, whose noise is evaluated correctly by both expressions.
- in non calib fits asymm, asyme are calculated in
musuite and rebinned in mufit, muplotfit, implementing 1.
- in calib fits the asymmetry is recalculated in mucomponents (inside minuit) with updated alpha and then rebinned, implementing 1. again.
Back to Mujpy
Index
|