utils
This module provides some functions that may be useful in other modules.
- check_positive_definite(m)[source]
check if matrix m is postive definite
>>> check_positive_definite([[1.0,0.0],[0.0, 0.1]]) True
>>> check_positive_definite([[1.0,0.0],[1.0,-0.1]]) eigvalues: [-0.1 1. ] False
- combine_asym_error(errs, N=10000)[source]
combine asymmetry uncertanties using convolution
>>> a, b = combine_asym_error([[-0.4, 0.4], 0.3]) >>> assert abs(a+0.5) < 0.01 >>> assert abs(b-0.5) < 0.01
- error_print(x, err=None, dig=None)[source]
It returns a format string “value +/- error”. The precision is modified according to
err
- Parameters:
x – Value
err – Error
- Returns:
String
- fit_normal(data, weights=None)[source]
Fit data distribution with Gaussian distribution. Though minimize the negative log likelihood function
\[- \ln L = \frac{1}{2}\sum w_i \frac{(\mu - x_i )^2}{\sigma^2} + (\sum w_i) \ln (\sqrt{2\pi} \sigma )\]the fit result can be solved as
\[\frac{\partial (-\ln L)}{\partial \mu} = 0 \Rightarrow \bar{\mu} = \frac{\sum w_i x_i}{ \sigma^2 \sum w_i}\]\[\frac{\partial (-\ln L)}{\partial \sigma} = 0 \Rightarrow \bar{\sigma} = \sqrt{\frac{\sum w_i (\bar{\mu} - x_i)^2}{\sum w_i}}\]From hessian
\[\frac{\partial^2 (-\ln L)}{\partial \mu^2} = \frac{\sum w_i}{\sigma^2}\]\[\frac{\partial^2 (-\ln L)}{\partial \sigma^2} = 3\sum \frac{\sum w_i (\mu - x)^2}{\sigma^4} - \frac{\sum w_i}{\sigma^2}\]the error matrix can wrotten as [[ \(\bar{\sigma}^2/N\) , 0], [0, \(\bar{\sigma}^2/(2N)\) ]] .
- flatten_dict_data(data, fun=<built-in method format of str object>)[source]
Flatten nested dictionary data into one layer dictionary.
- Returns:
Dictionary
- flatten_np_data(data)
- load_config_file(name)[source]
Load config file such as Resonances.yml.
- Parameters:
name – File name. Either yml file or json file.
- Returns:
Dictionary read from the file.
- search_interval(px, cl=0.6826894921370859, xrange=(0, 1))[source]
Search interval (a, b) that satisfly \(p(a)=p(b)\) and
\[\frac{\int_{a}^{b} p(x) dx}{\int_{x_{min]}^{x_{max}} p(x) dx} = cl\]>>> x = np.linspace(-10, 10, 10000) >>> a, b = search_interval(np.exp(-x**2/2), xrange=(-10, 10)) >>> assert abs(a+1) < 0.01 >>> assert abs(b-1) < 0.01
- std_periodic_var(p, mid=0.0, pi=3.141592653589793)[source]
Transform a periodic variable into its range.
>>> std_periodic_var(math.pi) -3.1415...
>>> std_periodic_var(2*math.pi + 0.01) 0.0...
- Parameters:
p – Value
mid – The middle value
pi – Half-range
- Returns:
The transformed value