physbo.search.score module
- physbo.search.score.EI(predictor, training, test, fmax=None)[ソース]
Maximum expected improvement.
- パラメータ:
predictor (predictor object) -- Base class is defined in physbo.predictor.
training (physbo.variable) -- Training dataset. If the predictor is not trained, use this for training.
test (physbo.variable) -- Inputs
fmax (float) -- Max value of posterior probability distribution. If not set, the maximum value of posterior mean for training is used.
- 戻り値:
score
- 戻り値の型:
numpy.ndarray
- class physbo.search.score.ExpectedImprovement(fmax=None)[ソース]
ベースクラス:
objectCallable acquisition function wrapping
EI().- パラメータ:
fmax (float, optional) -- Maximum posterior mean; None uses the training data. Default is None.
参考
EIAcquisition function with predictor, training and test arguments.
- name = 'EI'
- physbo.search.score.PI(predictor, training, test, fmax=None)[ソース]
Maximum probability of improvement.
- パラメータ:
predictor (predictor object) -- Base class is defined in physbo.predictor.
training (physbo.variable) -- Training dataset. If the predictor is not trained, use this for training.
test (physbo.variable) -- Inputs
fmax (float) -- Max value of posterior probability distribution. If not set, the maximum value of posterior mean for training is used.
- 戻り値:
score
- 戻り値の型:
numpy.ndarray
- class physbo.search.score.ProbabilityOfImprovement(fmax=None)[ソース]
ベースクラス:
objectCallable acquisition function wrapping
PI().- パラメータ:
fmax (float, optional) -- Maximum posterior mean; None uses the training data. Default is None.
参考
PIAcquisition function with predictor, training and test arguments.
- name = 'PI'
- physbo.search.score.TS(predictor, training, test, alpha=1, rng=None)[ソース]
Thompson sampling (See Sec. 2.1 in Materials Discovery Volume 4, June 2016, Pages 18-21)
- パラメータ:
predictor (predictor object) -- Base class is defined in physbo.predictor.
training (physbo.variable) -- Training dataset. If the predictor is not trained, use this for training.
test (physbo.variable) -- Inputs
alpha (float) -- noise for sampling source (default: 1.0)
rng (rng object, optional) -- random number generator (default: global numpy.random state)
- 戻り値:
score
- 戻り値の型:
numpy.ndarray
メモ
For predictors with a finite-dimensional posterior sample representation (the BLM predictor, i.e.
num_rand_basis > 0), the sample is a weight vector, drawn once and evaluated at every test point. In a parallel run the policies draw it on rank 0 and broadcast it (seeThompsonSampling), so that every rank scores its candidates with the same function sample. The GP predictor (num_rand_basis == 0) has no finite sample representation; in a parallel run each rank then samples the marginal distribution of its own candidates only, which is an approximation: cross-rank correlations are ignored, and the result depends on the number of ranks. For TS in parallel runs, the BLM predictor is recommended.
- class physbo.search.score.ThompsonSampling(alpha=1.0, rng=None)[ソース]
ベースクラス:
objectCallable acquisition function wrapping
TS().- パラメータ:
alpha (float, optional) -- Scaling parameter for posterior sampling. Default is 1.0.
rng (rng object, optional) -- Random number generator for the posterior sample; None (default) draws from the global
numpy.randomstate. An instance given to a policy without a generator of its own borrows the policy's (seephysbo._rng.attach_rng()).
メモ
Each call draws a new posterior sample. In a parallel run the policies share one sample between the processes:
draw()draws it on rank 0, it is broadcast, andwith_sample()gives the score function evaluating it (seeshare_sample()).参考
TSAcquisition function with predictor, training and test arguments.
- draw(predictor, training)[ソース]
Draw the posterior sample to be shared between the processes.
Returns the sample of a predictor with a finite-dimensional representation of the posterior (the BLM predictor), or None for a predictor without one (the GP predictor), which then samples in each call.
- name = 'TS'
- physbo.search.score.UCB(predictor, training, test, beta=1.0)[ソース]
Upper Confidence Bound (UCB).
The score is
fmean + beta * fstd, wherefmeanandfstdare the mean and the standard deviation of the posterior predictive distribution. Since PHYSBO maximizes the objective, largerbetaputs more weight on exploration (high-variance candidates), whilebeta == 0reduces to greedy exploitation of the posterior mean.- パラメータ:
predictor (predictor object) -- Base class is defined in physbo.predictor.
training (physbo.variable) -- Training dataset. If the predictor is not trained, use this for training.
test (physbo.variable) -- Inputs
beta (float) -- Trade-off parameter between exploitation and exploration. (default: 1.0)
- 戻り値:
score
- 戻り値の型:
numpy.ndarray
- class physbo.search.score.UpperConfidenceBound(beta=1.0)[ソース]
ベースクラス:
objectCallable acquisition function wrapping
UCB().- パラメータ:
beta (float, optional) -- Weight of the posterior standard deviation. Default is 1.0.
参考
UCBAcquisition function with predictor, training and test arguments.
- name = 'UCB'
- physbo.search.score.resolve(score, *, alpha=1.0, ucb_beta=1.0, rng=None)[ソース]
Resolve a score name or return a callable unchanged.
- パラメータ:
score (str or callable) -- "EI", "PI", "TS", "UCB", or a callable accepting predictor, training and test as positional arguments.
alpha (float, optional) -- Posterior sampling scale for "TS". Default is 1.0.
ucb_beta (float, optional) -- Exploration weight for "UCB". Default is 1.0.
rng (rng object, optional) -- Random number generator for "TS". A callable that holds a generator in an
rngattribute and was not given one of its own (the built-inThompsonSampling) is attached to it (seephysbo._rng.attach_rng()). Default is None, the globalnumpy.randomstate.
- 戻り値:
Acquisition function. Existing callables are returned unchanged.
- 戻り値の型:
callable
- 例外:
NotImplementedError -- If the score name is unknown.
TypeError -- If score is a class rather than an instance, or is neither a string nor a callable.
- physbo.search.score.score(mode, predictor, test, training=None, **kwargs)[ソース]
Calculate scores (acquisition function) for test data.
- パラメータ:
mode (str or callable) --
Kind of score.
"EI", "PI", "TS", and "UCB" are available. A callable is called as
mode(predictor, training, test)and ignores score parameters.predictor (predictor object) -- Base class is defined in physbo.predictor.
training (physbo.variable) -- Training dataset. If the predictor is not trained, use this for training.
test (physbo.variable) -- Inputs
fmax (float) -- Max value of mean of posterior probability distribution. If not set, the maximum value of posterior mean for training is used. Used only for mode == "EI" and "PI"
alpha (float) -- noise for sampling source (default: 1.0) Used only for mode == "TS"
rng (rng object) -- random number generator (default: global numpy.random state) Used only for mode == "TS"; a callable mode draws from its own.
ucb_beta (float) -- Trade-off parameter between exploitation and exploration (default: 1.0). The score is
fmean + ucb_beta * fstd; larger values favor exploration. Used only for mode == "UCB".
- 戻り値:
score
- 戻り値の型:
numpy.ndarray
- 例外:
NotImplementedError -- If unknown mode is given
The score evaluating one posterior sample on every process.
For a
ThompsonSamplinginstance in a parallel run (commgiven), the sample is drawn on rank 0 from its generator, broadcast, and the returned score evaluates it on every process. Any othermode, orcommNone, is returned unchanged. A collective operation whencommis given; an exception raised while drawing is raised on every process (seephysbo._mpi).
The posterior samples of
Kmodels, drawn on rank 0 and broadcast.models(k)returns the predictor and the training data of thek-th model (the same on every process). For aThompsonSamplinginstance in a parallel run whosepredictorhas a finite-dimensional posterior representation, the returned list holds one sample per model, forThompsonSampling.with_sample(); otherwise None is returned, and the score draws in each call. A collective operation when it draws.