hopsy.tune#
- class hopsy.tune(mcs, rngs, target, n_tuning, k=[1], accrate=0.234, seed=42, n_procs=1, n_rounds=100, n_burnin=50, sample_proposal=True, lower=-5, upper=5, n_points=256, params=['stepsize'], transforms=None)#
Thompson Sampling-based tuning method for specifying meaningful hyperparameters for Markov chain proposal distributions. This method supports three different tuning targets, namely the commonly used accpetance rate, the Expected Squared Jump Distance (ESJD) and the ESJD per second (ESJD/s) rather than per sample.
Tuning happens over a fixed search domain created from a Sobol sequence of n_points grid points with lower and upper bound using lower and upper. Its dimension is automatically adapted to the number of parameters that are to be tuned per proposal. Note that constraints are handled by transforming the parameters using the transformations stored in the transforms dict. Default transforms are available for stepsize, where an exponential transform is applied (i.e. Thompson Sampling happens in log space) and for fisher_weight, where a sigmoid function is applied.
- Parameters:
mcs (list of list or list of hopsy.MarkovChain) – Markov chains, which will be used to generate samples. If list of lists of ``hopsy.MarkovChain``s are passed, outer lists are expected to share the same proposal algorithm, inner lists to be replicas of the same chain.
rngs (list of list or list of hopsy.RandomNumberGenerator) – Random number generators required for sampling from the Markov chains. Should match mcs in number and shape.
target (str) – Tuning target. Choose one of accrate, esjd or esjd/s.
n_tuning (int) – Total budget of samples that may be drawn for tuning per chain.
k (list of int, default=[1]) – Lags at which the ESJDs are computed. If more than one lag is passed, ESJDs across multiple lags will be summed up.
accrate (float, default=0.234) – Target accpetance rate for acceptance rate tuning.
seed (int, default=42) – RNG seed for the Thompson Sampling procedure.
n_procs (int, default=1) – Number of parallel chains. Is passed as is to hopsy.sample.
n_rounds (int, default=100) – Number of Thompson Sampling rounds.
n_burnin (int, default=50) – Number of Thompson Sampling rounds, where it is just naively applied to all proposal distributions. This option only makes any difference, if sample_proposal==True.
sample_proposal (bool, default=True) – Choose whether to apply TS also on the discrete choice of proposal algorithm to use. This option is only supported if tuning w.r.t. to ESJD or ESJD/s.
lower (float, default=-5) – Lower bound on the search domain of the transformed hyperparameters.
upper (float, default=5) – Upper bound on the search domain of the transformed hyperparameters.
n_points (int, default=256) – Number of points to draw from the Sobol sequence. Should ideally be some power of 2.
params (list of str, default=['stepsize']) – Parameters that are to be tuned. They get accessed as attributes of mc.proposal. If a proposal doesn’t provide the corresponding parameter, then it will just be ignored.
transforms (dict of callable, default=None) – Dictonary containing transforms mapping unbounded values to the proper range for a given parameter. Default transforms exist for stepsize, which gets mapped using an exponential function, and fisher_weight, which gets mapped using a sigmoid. Default values are overridden if any other transforms are passed here for the same parameters.
- Returns:
mcs (dict of list of hopsy.MarkovChain) – List of tuned Markov chains, where each list of replicas is stored with key==mc.proposal.__class__.__name__.
rngs (dict of list of hopsy.RandomNumberGenerator) – List of forwarded random number generators, where corresponding RNGs to the Markov chains in mcs are also stored with key==mc.proposal.__class__.__name__.
(gprs, domains) (tuple of dict) – gprs contains the fitted sklearn GaussianProcessRegressor`s, which were used as surrogate functions to the blackbox tuning target. `domains contains the Sobol sequence domains on which the GPs were evaluated to obtain the next hyperparameter choice. Both dicts store using the respective proposal names as keys.