Parameters in appletree
In general, all parameters including fixed parameters and fit parameters are handled by appletree.Parameter, which has many useful attributes
- class appletree.Parameter(parameter_config)[source]
Bases:
objectParameter handler to update parameters and calculate prior.
- __init__(parameter_config)[source]
Initialization.
- Parameters
parameter_config – can be either * str: the json file name where the config is stored. * dict: config dictionary.
- check_parameter_exist(keys, return_not_exist=False)[source]
Check whether the keys exist in parameters.
- Parameters
keys – Parameter names. Can be a single str, or a list of str.
return_not_exist – If False, function will return a bool if all keys exist. If True, function will additionally return the list of the not existing keys.
- get_parameter(keys)[source]
Return parameter values.
- Parameters
keys – Parameter names. Can be a single str, or a list of str.
- init_parameter(seed=None)[source]
Initializing parameters by sampling prior. sampling from the. initial guess. If the prior is free, then.
- Parameters
seed – integer, sent to np.random.seed(seed)
- property log_prior
Return log prior.
If any parameter is out of allowed_range return -np.inf.
- property parameter_fit
Return sorted list of parameters name waiting for fitting.
- property parameter_fit_array
Return non-fixed parameters, ordered by self._parameter_fit.
- sample_init()[source]
Samping parameters from initial guess clipped by the allowed_range and set self._parameter_dict.
We recommend to initialize Parameter from a json file. An example of parameter config file is the ER parameter file, in which the dictionary is structured as
{
param_name_0: config_of_param_0,
param_name_1: config_of_param_1,
...
}
For each config_of_param, it should be a dictionary containing the following items:
“prior_type”: can be either
“norm”: normal prior, prior_args are mean and std.
“uniform”: uniform prior, prior_args are lower and upper.
“free”: free prior, no prior_args required.
“fixed”: it won’t be considered as a fit parameter, prior_args is val.
“prior_args”: a dictionary like {arg_name : arg_value} which goes into prior.
“allowed_range”: a list like [lower_boundary, upper_boundary], above which parameters will be clipped and have -np.inf log prior.
“init_mean”: the gaussian mean as the initial guess of the MCMC walkers. The random initialzation of MCMC will be clipped by “allowed_range”.
“init_std”: the gaussian std as the initial guess of the MCMC walkers.
“unit”: the unit of the parameter, only for documentation purpose.
“doc”: the addtional docstring for the parameter.
For example,
{
"w": {
"prior_type": "norm",
"prior_args": {
"mean": 0.0137,
"std": 0.0002
},
"allowed_range": [
0,
1.0
],
"init_mean": 0.0137,
"init_std": 0.0002,
"unit": "keV",
"doc": "Mean energy to generate a quanta in liquid xenon"
},
"fano": {
"prior_type": "fixed",
"prior_args": {
"val": 0.059
},
"allowed_range": null,
"init_mean": null,
"init_std": null,
"unit": "1",
"doc": "Fano factor which describes the fluctuation of num of quanta"
},
}
All non-fixed parameters are called fit parameters in appletree, and will be the parameters that MCMC samples. appletree.Plugin needs a dictionary of parameters. With the Parameter class, it can be simply obtained by Parameter.get_all_parameter().