physbo.search.score module

physbo.search.score.EI(predictor, training, test, fmax=None)[source]

Maximum expected improvement.

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 posterior probability distribution. If not set, the maximum value of posterior mean for training is used.

Returns:

score

Return type:

numpy.ndarray

class physbo.search.score.ExpectedImprovement(fmax=None)[source]

Bases: object

Callable acquisition function wrapping EI().

Parameters:

fmax (float, optional) – Maximum posterior mean; None uses the training data. Default is None.

See also

EI

Acquisition function with predictor, training and test arguments.

name = 'EI'
physbo.search.score.PI(predictor, training, test, fmax=None)[source]

Maximum probability of improvement.

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 posterior probability distribution. If not set, the maximum value of posterior mean for training is used.

Returns:

score

Return type:

numpy.ndarray

class physbo.search.score.ProbabilityOfImprovement(fmax=None)[source]

Bases: object

Callable acquisition function wrapping PI().

Parameters:

fmax (float, optional) – Maximum posterior mean; None uses the training data. Default is None.

See also

PI

Acquisition function with predictor, training and test arguments.

name = 'PI'
physbo.search.score.TS(predictor, training, test, alpha=1, rng=None)[source]

Thompson sampling (See Sec. 2.1 in Materials Discovery Volume 4, June 2016, Pages 18-21)

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

  • alpha (float) – noise for sampling source (default: 1.0)

  • rng (rng object, optional) – random number generator (default: global numpy.random state)

Returns:

score

Return type:

numpy.ndarray

Notes

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 (see ThompsonSampling), 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)[source]

Bases: object

Callable acquisition function wrapping TS().

Parameters:
  • 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.random state. An instance given to a policy without a generator of its own borrows the policy’s (see physbo._rng.attach_rng()).

Notes

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, and with_sample() gives the score function evaluating it (see share_sample()).

See also

TS

Acquisition function with predictor, training and test arguments.

draw(predictor, training)[source]

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'
with_sample(sample)[source]

The score function evaluating sample from draw(), or this object if sample is None.

physbo.search.score.UCB(predictor, training, test, beta=1.0)[source]

Upper Confidence Bound (UCB).

The score is fmean + beta * fstd, where fmean and fstd are the mean and the standard deviation of the posterior predictive distribution. Since PHYSBO maximizes the objective, larger beta puts more weight on exploration (high-variance candidates), while beta == 0 reduces to greedy exploitation of the posterior mean.

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

  • beta (float) – Trade-off parameter between exploitation and exploration. (default: 1.0)

Returns:

score

Return type:

numpy.ndarray

class physbo.search.score.UpperConfidenceBound(beta=1.0)[source]

Bases: object

Callable acquisition function wrapping UCB().

Parameters:

beta (float, optional) – Weight of the posterior standard deviation. Default is 1.0.

See also

UCB

Acquisition function with predictor, training and test arguments.

name = 'UCB'
physbo.search.score.resolve(score, *, alpha=1.0, ucb_beta=1.0, rng=None)[source]

Resolve a score name or return a callable unchanged.

Parameters:
  • 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 rng attribute and was not given one of its own (the built-in ThompsonSampling) is attached to it (see physbo._rng.attach_rng()). Default is None, the global numpy.random state.

Returns:

Acquisition function. Existing callables are returned unchanged.

Return type:

callable

Raises:
  • 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)[source]

Calculate scores (acquisition function) for test data.

Parameters:
  • 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”.

Returns:

score

Return type:

numpy.ndarray

Raises:

NotImplementedError – If unknown mode is given

physbo.search.score.share_sample(mode, predictor, training, comm)[source]

The score evaluating one posterior sample on every process.

For a ThompsonSampling instance in a parallel run (comm given), the sample is drawn on rank 0 from its generator, broadcast, and the returned score evaluates it on every process. Any other mode, or comm None, is returned unchanged. A collective operation when comm is given; an exception raised while drawing is raised on every process (see physbo._mpi).

physbo.search.score.share_samples(mode, predictor, models, K, comm)[source]

The posterior samples of K models, drawn on rank 0 and broadcast.

models(k) returns the predictor and the training data of the k-th model (the same on every process). For a ThompsonSampling instance in a parallel run whose predictor has a finite-dimensional posterior representation, the returned list holds one sample per model, for ThompsonSampling.with_sample(); otherwise None is returned, and the score draws in each call. A collective operation when it draws.