utils.optimal_parameters
utils.optimal_parameters(trace_array, lnprob_array, kth=0)
Return the optimal parameters in the trace based on the highest likelihood. If kth is specified, return the kth set of unique optimal parameters.
Parameters
Name | Type | Description | Default |
---|---|---|---|
trace_array |
ndarray | Array of shape (number of chains, iterations, number of parameters) | required |
lnprob_array |
ndarray | Array of shape (number of chains, iterations) | required |
kth |
int | Zero-indexed optimum. 0 (the default) is the most optimal solution. 1 is the second most optimal, etc.. Only unique solutions will be returned. | 0 |
Returns
Type | Description |
---|---|
Array of optimal parameters |
Notes
It is ok if the calculation did not finish and the arrays are padded with zeros. The number of chains and iterations in the trace and lnprob arrays must match.
Examples
>>> from espei.utils import optimal_parameters
>>> trace = np.array([[[1, 0], [2, 0], [3, 0], [0, 0]], [[0, 2], [0, 4], [0, 6], [0, 0]]]) # 3 iterations of 4 allocated
>>> lnprob = np.array([[-6, -4, -2, 0], [-3, -1, -2, 0]])
>>> bool(np.all(np.isclose(optimal_parameters(trace, lnprob), np.array([0, 4]))))
True