< Double fit in Ver. 2.0 | Index | How to recompile the *load.mex* routines >
There is a newer version of these instructions here
How to use Linear Relations
=4
and +p(4)
are synonims, in Ver.1.05 (in Ver. 2.0 the only syntax is =p(4)
How shared are implemented in v. 1.04
Linear Relations '+' are detected but not implemented.
Remember that inside mulab four types of indices are used for different functions on each parameter:
- the index n in the Fit Parameters Menu list (the panel in the gui), that identifies it for the user
- the index m in the list of parameters actually passed to fminuit (fminuit parameter list, only ~ and ! parameters included), to retrieve the chi squared value from each MINUIT iteration
- the component index
c
in the model name and the parameter position p
in that component, (e.g muAmp
in damu
is kc=2, for second component, and kp=1 for its first parameter, and all of its features (NAME, VALUE, FLAG, PLOT, ERROR) are stored in MU_MODEL.COMPONENT(kc).PARAMETER(kp)
- the component index k in MU_COMPONENT.PARAMETER and the parameter position j in that component, e.g. k=3 and j=1 for muAmp, to get e.g. stepbounds in MU_COMPONENT.PARAMETER(k).STEPBOUNDS(j,:)
To share the same value among more parameters, a SOURCE and one or more TARGETS, the TARGET parameter flags must be set to
=n
, where integer n
is the Fit Menu index of the SOURCE parameter, or, alternatively +p(n)
(Ver. 1.05)
=p(n)
new syntax in Ver. 2.0 dismisses the concept of shared parameters and uses the linear relations throughout.
The component index of the TARGET, c
, and its parameter index, p
, within the present model are retrieved by mucomp
.
The SOURCE index n is stored temporarily in MU_MODEL.COMPONENT(c).PARAMETER(p).SHARE by
muextractflag
. Then before invoking fminuit mufit
generates the array MU_MODEL.COMPONENT(c).SHARE
for each component c in the model. When mufcn
receives the fminuit parameters par the equation
p=par(MU_MODEL.COMPONENT(k).SHARE);
generates exactly the parameters p needed by the component function, e.g. muprecession(p,data)
eval(['f=[f; ' char(MU_COMPONENT.DEFINITION(kk)) '];'])
How to implement Linear Relations in v 1.05
Example of fit with two linear relations
Menu | fminuit | Parsed as |
1 | 1~ | p(1) |
2 | 2~ | p(2) |
3 | 3! | p(3) |
4 | +p(1)*0.666 | p(1)*0.666 |
5 | 4~ | p(4) |
6 | 5~ | p(5) |
7 | 6~ | p(6) |
8 | +p(5)/2-p(1)*0.333 | p(4)/2-p(1)*0.333 |
9 | 7~ | p(7) |
Parsing correct syntax: the string must be a valid matlab expression
once the occurences of 'p(k)' with k any integer are replaced
by 'p(kk)', (k refers to the Fit Parameters Menu list, whereas kk
refers to the fminuit list).
muparse
must do this in a dry, validation run and then again in a
final run, within mufit
, before invoking fminuit. In this second run
mufit
must store in MU_MODEL.COMPONENT(c).PARAMETER(p).MENU2MINUIT
a distinct executable right hand side for each type of flag:
for '~' and '!' it must be 'p(m)' for parameter n (m is the fminuit index of Menu n)
for '=' it must be 'p(k)' for TARGET parameter n (k is the fminuit index of the SOURCE parameter)
for '+' it must translate with a similar recipe a more complex statement, see the example above
The translation makes use of the local shareglobal array to remap indices. Two passages to allow
reference also to following parameters.
The local array share, saved in MU_MODEL.COMPONENT(kc).SHARE, is still used in extracting values,
although shares AND normal parameters are handled anyways via the MENU2MINUIT string, for which
MU_MODEL.COMPONENT(kc).PARAMETER(kp).SHARE is sufficient.
Finally mufcn
will simply execute for each component kc
command='[';
p=par; % restarts from fminuit input
for kp=1:MU_MODEL.COMPONENT(kc).PARAMETERNUMBER
command=[command MU_MODEL.COMPONENT(kc).PARAMETER(kp).MENU2MINUIT ' '];
end
command=[command '];']; % command contaiNs something like '[p(4) p(1)*0.333 p(2) ];'
p=eval(command); % now p contains the right parameters for component kc
prior to
eval(['f=[f; ' char(MU_COMPONENT.DEFINITION(kc)) '];']) %calculates the component
All the routines involved
muparse
checks that
as many 'p(' and ')' appear,
the intervening characters represent an integer
all integers correspond to existing variable parameters
called by
muextractflag
called by
mufit
called by
mufit_gui
< Double fit in Ver. 2.0 | Index | How to recompile the *load.mex* routines >