How to define your own models in ISIS

From Remeis-Wiki
Jump to navigation Jump to search
Define a function

Models (additive and multiplicative) are just usual functions in ISIS, which require three specific input arrays: bin_lo, bin_hi, and parameters and whose names end in _fit.

define myfun_fit (lo,hi,par) 
{
   return par[0] +  (lo + hi)/2.*par[1] ;
}

Obviously bin_lo and bin_hi is just the grid on which your data is defined and on which your model will be evaluated. If you do not need the width of the bin, i.e. you are not using bin-integrated data, you can of course use only bin_lo (or bin_hi (or none of them, if your model shall be independend of the grid...)) in your function, but you still need to define the unused variables the function header as a possible input value.

define myfun2_fit (lo,hi,par)
{
   return 7 ;
}
Tell ISIS to use this function as a model

If you defined your function myfun_fit correclty, one simple command is all that is needed to make the function a model

add_slang_function("myfun", ["offset", "slope"]);

which needs two arguments:

  • first, the name of the function, without the _fit as a string
  • second, an array of strings, one for each parameter, i.e., entry in the array par, naming each of those parameters

An optional third parameter let's you specify which of these parameters are norms and will be fitted when using renorm_counts. See the help for more details.

Give start values for the parameters

If you want to be more fancy or if some of the parameters make only sense in a certain range, you can easily define the start values of each parameter, as well if it should be frozen in the beginning or not and its (soft) boundaries.

define myfun_default(i)
{
   switch(i)
   { case 0: return ( 10, 0, -100, 100 ); }
   { case 1: return (  0, 1,   -1,   1 ); }
}

set_param_default_hook("myfun", "myfun_default") ;

The function myfun_default needs to be defined as shown above, with a switch-case statement to distinguish between the parameters. The name of the function is arbitrary, but good style is to replace _default for _fit. Each case of the switch-case represents one parameter, the number corresponding to the respective index of the parameter array. The returned values are, in that order: value, frozen (1 or 0), lower boundary, upper boundary -- i.e. the same as in set_par.

The function set_param_default_hook finally attaches its second argument (a string) as default values to the before defined model of the first argument (also a string).

That's it!


For a possible way to pass additional information to the fit function, see set/get_dataset_metadata