starred.optim package

Submodules

starred.optim.inference_base module

class starred.optim.inference_base.FisherCovariance(parameter_class, differentiable_class, diagonal_only=False)[source]

Bases: object

Parameters:

diagonal_only – bool, if you are confident your parameters are not correlated: you can save space by calculating the diagonal of the hessian only.

compute_fisher_information(recompute=False)[source]
Parameters:

recompute – bool, redo? default False

property covariance_matrix
draw_samples(num_samples=10000, seed=None)[source]

Draw samples from the multivariate Gaussian distribution defined by the best fit values and the covariance

Parameters:
  • num_samples – int, number of samples to draw

  • seed – int, seed for the random number generator

Returns:

array of shape (num_samples, num_parameters)

fisher2covar(fisher_matrix, inversion='full')[source]
property fisher_matrix
get_kwargs_sigma()[source]

Return the standard deviation of the marginalized distribution for each parameter. This corresponds to the square roots of the diagonal coefficient of the covariance matrix.

static split_matrix(matrix, num_before, num_after)[source]
class starred.optim.inference_base.InferenceBase(loss_class, param_class)[source]

Bases: object

Class that defines wraps the loss function, and computes first and second order derivatives.

Parameters:
  • loss_class – Loss instance

  • param_class – Parameters instance

gradient(args)[source]

Returns the gradient (first derivative) of the loss function.

hessian(args)[source]

Returns the Hessian (second derivative) of the loss function.

hessian_vec_prod(args, vec)[source]

Hessian-vector product.

log_likelihood(args)[source]

Log Likelihood function to be maximised. :param args: list or array of paramers

loss(args)[source]

Loss function to be minimized. :param args: list or array of paramers

property parameters

Returns the parameters.

value_and_gradient(args)[source]

Returns both the value and the gradient (first derivative) of the loss function.

starred.optim.optimization module

class starred.optim.optimization.Optimizer(loss_class, param_class, method='BFGS')[source]

Bases: InferenceBase

Class that handles optimization tasks, i.e., finding best-fit point estimates of parameters It currently handles a subset of scipy.optimize.minimize routines, using first and second order derivatives when required.

compute_fisher_matrix()[source]
property loss_history

Returns the loss history.

minimize(restart_from_init=True, **kwargs_optimiser)[source]

Minimizes the loss function and returns the best fit.

property param_history

Returns the parameter history.

starred.optim.sampling module

class starred.optim.sampling.Sampler(loss_class, param_class, sampler='emcee')[source]

Bases: InferenceBase

prior_draw(key)[source]

Uniform prior

sample(init_params, **kwargs_sampler)[source]

Minimizes the loss function and returns the best fit.

transform(x)[source]

transform x back to the original parameter. Useful if some parameter are sampled in log space for example

Module contents

This subpackage contains optimization and sampling functions