espei.optimizers package#
Submodules#
espei.optimizers.opt_base module#
- class espei.optimizers.opt_base.OptimizerBase(dbf)#
Bases:
object
Enable fitting and replaying fitting steps
- fit(symbols, datasets, *args, **kwargs)#
- static predict(params, context)#
Given a set of parameters and a context, return the resulting sum of square error.
- Parameters:
params (list) – 1 dimensional array of parameters
context (dict) – Dictionary of arguments/keyword arguments to pass to functions
- Return type:
float
espei.optimizers.opt_mcmc module#
- class espei.optimizers.opt_mcmc.EmceeOptimizer(dbf, phase_models=None, scheduler=None)#
Bases:
OptimizerBase
An optimizer using an EnsembleSampler based on Goodman and Weare [1] implemented in emcee [2]
- scheduler#
An object implementing a map function
- Type:
mappable
- save_interval#
Interval of iterations to save the tracefile and probfile.
- Type:
int
- tracefile#
Filename to store the trace with NumPy.save. Array has shape (chains, iterations, parameters). Defaults to None.
- Type:
str
- probfile#
filename to store the log probability with NumPy.save. Has shape (chains, iterations)
- Type:
str
References
[1] Goodman and Weare, Ensemble Samplers with Affine Invariance. Commun. Appl. Math. Comput. Sci. 5, 65-80 (2010). [2] Foreman-Mackey, Hogg, Lang, Goodman, emcee: The MCMC Hammer. Publ. Astron. Soc. Pac. 125, 306-312 (2013).
- do_sampling(chains, iterations)#
- static get_priors(prior, symbols, params)#
Build priors for a particular set of fitting symbols and initial parameters. Returns a dict that should be used to update the context.
- Parameters:
prior (dict or PriorSpec or None) – Prior to initialize. See the docs on
symbols (list of str) – List of symbols that will be fit
params (list of float) – List of parameter values corresponding to the symbols. These should be the initial parameters that the priors will be based off of.
- static initialize_chains_from_trace(restart_trace)#
- static initialize_new_chains(params, chains_per_parameter, std_deviation, deterministic=True)#
Return an array of num_samples from a Gaussian distribution about each parameter.
- Parameters:
params (ndarray) – 1D array of initial parameters that will be the mean of the distribution.
num_samples (int) – Number of chains to initialize.
chains_per_parameter (int) – number of chains for each parameter. Must be an even integer greater or equal to 2. Defaults to 2.
std_deviation (float) – Fractional standard deviation of the parameters to use for initialization.
deterministic (bool) – True if the parameters should be generated deterministically.
- Return type:
ndarray
Notes
Parameters are sampled from
normal(loc=param, scale=param*std_deviation)
. A parameter of zero will produce a standard deviation of zero and therefore only zeros will be sampled. This will break emcee’s StretchMove for this parameter and only zeros will be selected.
- static predict(params, **ctx)#
Calculate lnprob = lnlike + lnprior
- save_sampler_state()#
Convenience function that saves the trace and lnprob if they haven’t been set to None by the user.
Requires that the sampler attribute be set.
espei.optimizers.opt_scipy module#
- class espei.optimizers.opt_scipy.SciPyOptimizer(dbf)#
Bases:
OptimizerBase
- static predict(params, ctx)#
Given a set of parameters and a context, return the resulting sum of square error.
- Parameters:
params (list) – 1 dimensional array of parameters
context (dict) – Dictionary of arguments/keyword arguments to pass to functions
- Return type:
float
espei.optimizers.utils module#
- exception espei.optimizers.utils.OptimizerError#
Bases:
BaseException