syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm module
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.prepare_data(state, config_space_ext, active_metric, normalize_targets=False, do_fantasizing=False)[source]
Prepares data in
state
for further processing. The entriesconfigs
,targets
of the result dict are lists of one entry per trial, they are sorted in decreasing order of number of target values.features
is the feature matrix corresponding toconfigs
. Ifnormalize_targets
is True, the target values are normalized to mean 0, variance 1 (over all values), andmean_targets
,std_targets
is returned.If
do_fantasizing
is True,state.pending_evaluations
is also taken into account. Entries there have to be of typeFantasizedPendingEvaluation
. Also, in terms of their resource levels, they need to be adjacent to observed entries, so there are no gaps. In this case, the entries of thetargets
list are matrices, each column corr´esponding to a fantasy sample.Note: If
normalize_targets
, mean and stddev are computed over observed values only. Also, fantasy values instate.pending_evaluations
are not normalized, because they are assumed to be sampled from the posterior with normalized targets as well.- Parameters:
state (
TuningJobState
) –TuningJobState
with dataconfig_space_ext (
ExtendedConfiguration
) – Extended config spaceactive_metric (
str
) –normalize_targets (
bool
) – See abovedo_fantasizing (
bool
) – See above
- Return type:
Dict
- Returns:
See above
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.prepare_data_with_pending(state, config_space_ext, active_metric, normalize_targets=False)[source]
Similar to
prepare_data
withdo_fantasizing=False
, but two dicts are returned, the first for trials without pending evaluations, the second for trials with pending evaluations. The latter dict also contains trials which have pending, but no observed evaluations. The second dict has the additional entrynum_pending
, which lists the number of pending evals for each trial. These evals must be contiguous and adjacent with observed evals, so that the union of observed and pending evals are contiguous (when it comes to resource levels).- Parameters:
state (
TuningJobState
) – Seeprepare_data
config_space_ext (
ExtendedConfiguration
) – Seeprepare_data
active_metric (
str
) – Seeprepare_data
normalize_targets (
bool
) – Seeprepare_data
- Return type:
(
Dict
,Dict
)- Returns:
See above
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.issm_likelihood_precomputations(targets, r_min)[source]
Precomputations required by
issm_likelihood_computations
.Importantly,
prepare_data
orders datapoints by nonincreasing number of targetsydims[i]
. For0 <= j < ydim_max
,ydim_max = ydims[0] = max(ydims)
,num_configs[j]
is the number of datapoints i for whichydims[i] > j
.deltay
is a flat matrix (rows corresponding to fantasy samples; column vector if no fantasizing) consisting ofydim_max
parts, where part j is of sizenum_configs[j]
and containsy[j] - y[j-1]
for targets of those i counted innum_configs[j]
, the term needed in the recurrence to computew[j]
. ‘logr`` is a flat vector consisting ofydim_max - 1
parts, where part j (starting from 1) is of sizenum_configs[j]
and contains the logarithmic term for computinga[j-1]
ande[j]
.- Parameters:
targets (
List
[ndarray
]) – Targets from data representation returned byprepare_data
r_min (
int
) – Value of r_min, as returned byprepare_data
- Return type:
Dict
- Returns:
See above
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.issm_likelihood_computations(precomputed, issm_params, r_min, r_max, skip_c_d=False)[source]
Given
precomputed
fromissm_likelihood_precomputations
and ISSM parametersissm_params
, compute quantities required for inference and marginal likelihood computation, pertaining to the ISSM likelihood.The index for r is range(r_min, r_max + 1). Observations must be contiguous from r_min. The ISSM parameters are: - alpha: n-vector, negative - beta: n-vector - gamma: scalar, positive
Results returned are: - c: n vector [c_i], negative - d: n vector [d_i], positive - vtv: n vector [|v_i|^2] - wtv: (n, F) matrix [(W_i)^T v_i], F number of fantasy samples - wtw: n-vector [|w_i|^2] (only if no fantasizing)
- Parameters:
precomputed (
Dict
) – Output ofissm_likelihood_precomputations
issm_params (
Dict
) – Parameters of ISSM likelihoodr_min (
int
) – Smallest resource valuer_max (
int
) – Largest resource valueskip_c_d (
bool
) – If True, c and d are not computed
- Return type:
Dict
- Returns:
Quantities required for inference and learning criterion
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.posterior_computations(features, mean, kernel, issm_likelihood, noise_variance)[source]
Computes posterior state (required for predictions) and negative log marginal likelihood (returned in
criterion
), The latter is computed only when there is no fantasizing (i.e., ifissm_likelihood
containswtw
).- Parameters:
features – Input matrix X
mean – Mean function
kernel – Kernel function
issm_likelihood (
Dict
) – Outcome ofissm_likelihood_computations
noise_variance – Variance of ISSM innovations
- Return type:
Dict
- Returns:
Internal posterior state
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.predict_posterior_marginals(poster_state, mean, kernel, test_features)[source]
These are posterior marginals on the h variable, whereas the full model is for f_r = h + g_r (additive).
posterior_means
is a (n, F) matrix, where F is the number of fantasy samples, or F == 1 without fantasizing.- Parameters:
poster_state (
Dict
) – Posterior statemean – Mean function
kernel – Kernel function
test_features – Feature matrix for test points (not extended)
- Returns:
posterior_means, posterior_variances
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.sample_posterior_marginals(poster_state, mean, kernel, test_features, random_state, num_samples=1)[source]
We sample from posterior marginals on the h variance, see also
predict_posterior_marginals
.
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.predict_posterior_marginals_extended(poster_state, mean, kernel, test_features, resources, issm_params, r_min, r_max)[source]
These are posterior marginals on f_r = h + g_r variables, where (x, r) are zipped from
test_features
,resources
.issm_params
are likelihood parameters for the test configs.posterior_means
is a (n, F) matrix, where F is the number of fantasy samples, or F == 1 without fantasizing.- Parameters:
poster_state (
Dict
) – Posterior statemean – Mean function
kernel – Kernel function
test_features – Feature matrix for test points (not extended)
resources (
List
[int
]) – Resource values corresponding to rows oftest_features
issm_params (
Dict
) – See abover_min (
int
) –r_max (
int
) –
- Returns:
posterior_means, posterior_variances
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.sample_posterior_joint(poster_state, mean, kernel, feature, targets, issm_params, r_min, r_max, random_state, num_samples=1)[source]
Given
poster_state
for some data plus one additional configuration with data (feature
,targets
,issm_params
), draw joint samples of the latent variables not fixed by the data, and of the latent target values.targets
may be empty, but must not reach all the way tor_max
. The additional configuration must not be in the dataset used to computeposter_state
.If
targets
correspond to resource values range(r_min, r_obs), we sample latent target values y_r corresponding to range(r_obs, r_max+1) and latent function values f_r corresponding to range(r_obs-1, r_max+1), unless r_obs = r_min (i.e.targets
empty), in which case both [y_r] and [f_r] ranges in range(r_min, r_max+1). We return a dict with [f_r] underf
, [y_r] undery
. These are matrices withnum_samples
columns.- Parameters:
poster_state (
Dict
) – Posterior state for datamean – Mean function
kernel – Kernel function
feature – Features for additional config
targets (
ndarray
) – Target values for additional configissm_params (
Dict
) – Likelihood parameters for additional configr_min (
int
) – Smallest resource valuer_max (
int
) – Largest resource valuerandom_state (
RandomState
) – numpy.random.RandomStatenum_samples (
int
) – Number of joint samples to draw (default: 1)
- Return type:
Dict
- Returns:
See above
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.issm_likelihood_slow_computations(targets, issm_params, r_min, r_max, skip_c_d=False)[source]
Naive implementation of
issm_likelihood_computations
, which does not require precomputations, but is much slower. Here, results are computed one datapoint at a time, instead of en bulk.This code is used in unit testing, and called from
sample_posterior_joint
.- Return type:
Dict
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.update_posterior_state(poster_state, kernel, feature, d_new, s_new, r2_new)[source]
Incremental update of posterior state, given data for one additional configuration. The new datapoint gives rise to a new row/column of the Cholesky factor. r2vec and svec are extended by
r2_new
,s_new
respectively. r4vec and pvec are extended and all entries change. The new datapoint is represented byfeature
,d_new
,s_new
,r2_new
.Note: The field
criterion
is not updated, but set to np.nan.- Parameters:
poster_state (
Dict
) – Posterior state for datakernel – Kernel function
feature – Features for additional config
d_new – See above
s_new – See above
r2_new – See above
- Return type:
Dict
- Returns:
Updated posterior state
- syne_tune.optimizer.schedulers.searchers.bayesopt.gpautograd.learncurve.issm.update_posterior_pvec(poster_state, kernel, feature, d_new, s_new, r2_new)[source]
Part of
update_posterior_state
, just returns the new p vector.- Parameters:
poster_state (
Dict
) – Seeupdate_posterior_state
kernel – See
update_posterior_state
feature – See
update_posterior_state
d_new – See
update_posterior_state
s_new – See
update_posterior_state
r2_new – See
update_posterior_state
- Return type:
ndarray
- Returns:
New p vector, as flat vector