Proposal#

This module provides different random number generators for getting proposals from which to start the optimizer for the acquisition function. The way these points are proposed becomes increasingly important with higher dimensions as the volume of the parameter space grows exponentially.

As standard GPry uses the PartialProposer which consists of a centroid proposer with 25% of samples drawn from a uniform distribution (to make the acquisition more robust). Every proposer has a get method which returns a random sample from the proposer.

Classes to generate random proposals within the prior or trust bounds, used to generate initial samples for the active learning cycle, or as starting points from which to optimize the acquisition function.

proposal.check_in_bounds(get_method)[source]#

Decorator for get methods of Proposer sub-classes, that call the method until the returned proposal falls within the bounds defined as an attribute.

Print a warning every 1000 failed attempts.

It does not need to be used if the returned proposals are guaranteed to fulfil it.

class proposal.Proposer[source]#

Bases: object

Base proposer class. All other proposers inherit from it. If you want to define your own custom proposer it should also inherit from it.

abstract get(rng=None)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

update_bounds(bounds)[source]#

Updates the bounds for the proposal.

Parameters:

bounds (array) – Bounds in which to optimize the acquisition function, assumed to be of shape (d,2) for d dimensional prior

update(gpr)[source]#

Updates the internal GP instance if it has been updated with new data.

Parameters:

gpr (GaussianProcessRegressor) – The gpr instance that has been updated.

class proposal.InitialPointProposer[source]#

Bases: object

Base proposer class for all proposers which work for initial point generation.

class proposal.ReferenceProposer(truth, bounds=None)[source]#

Bases: Proposer, InitialPointProposer

Generates proposals from the “reference” distribution defined in the Truth. If no reference distribution is defined it defaults to the prior.

Parameters:

truth (Truth) – The true model from which to draw the samples.

get(*args, **kwargs)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

class proposal.PriorProposer(truth, bounds=None)[source]#

Bases: Proposer, InitialPointProposer

Generates proposals from the prior of the problem.

Parameters:

truth (Truth) – The true model from which to draw the samples.

get(*args, **kwargs)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

class proposal.UniformProposer(bounds)[source]#

Bases: Proposer, InitialPointProposer

Generates proposals uniformly in a hypercube determined by the bounds

Parameters:

bounds (array-like, shape=(n_dims,2)) – Array of bounds of the prior [lower, upper] along each dimension.

update_bounds(bounds)[source]#

Updates the bounds for the proposal.

Parameters:

bounds (array) – Bounds in which to optimize the acquisition function, assumed to be of shape (d,2) for d dimensional prior

get(rng=None)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

class proposal.PartialProposer(bounds, true_proposer, random_proposal_fraction=0.25)[source]#

Bases: Proposer, InitialPointProposer

Combines any of the other proposers with a UniformProposer with a fraction drawn from the uniform proposer to encourage exploration.

Warning

If you want to use this proposer for initial point generation make sure that your true_proposer is compatible.

Parameters:
  • bounds (array-like, shape=(n_dims,2)) – Array of bounds of the prior [lower, upper] along each dimension.

  • true_proposer (Proposer) – The initialized Proposer instance to use instead of uniform for a fraction of samples.

  • random_proposal_fraction (float, between 0 and 1, optional (default=0.25)) – The fraction of proposals that is drawn from the UniformProposer.

get(rng=None)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

update(gpr)[source]#

Updates the internal GP instance if it has been updated with new data.

Parameters:

gpr (GaussianProcessRegressor) – The gpr instance that has been updated.

update_bounds(bounds)[source]#

Updates the bounds for the proposal.

Parameters:

bounds (array) – Bounds in which to optimize the acquisition function, assumed to be of shape (d,2) for d dimensional prior

class proposal.MeanCovProposer(bounds, mean, cov, include_mean=False)[source]#

Bases: Proposer, InitialPointProposer

Generates proposals from a multivariate normal distribution given a mean vector and covariance matrix.

Parameters:
  • mean (array-like, shape=(n_dims,)) – Mean-vector of the multivariate normal distribution.

  • cov (array-like, shape=(n_dims, n_dims)) –

    Covariance matrix of the multivariate normal distribution.

    Note

    We conduct no explicit checks on whether the covariance matrix you provide is singular. Make sure that your matrix is a valid covariance matrix!

  • include_mean (bool (defaulf: False)) – If True, returns the mean in the first call to get (only for the 1st MPI rank)

get(*args, **kwargs)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

class proposal.CentroidsProposer(bounds, lambd=1.0)[source]#

Bases: Proposer

Proposes points at the centroids of subsets of dim-1 training points. It perturbs some of the proposals away from the centroids to encourage exploration.

boundsarray-like, shape=(n_dims,2)

Array of bounds of the prior [lower, upper] along each dimension.

lambda: float, optional (default=1)

Controls the scale of the perturbation of samples. Lower values correspond to more exploration.

property d#

Dimensionality of the prior.

get(rng=None)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

update(gpr)[source]#

Updates the internal GP instance if it has been updated with new data.

Parameters:

gpr (GaussianProcessRegressor) – The gpr instance that has been updated.

update_bounds(bounds)[source]#

Updates the bounds for the proposal.

Parameters:

bounds (array) – Bounds in which to optimize the acquisition function, assumed to be of shape (d,2) for d dimensional prior

class proposal.MeanAutoCovProposer(mean, model_info)[source]#

Bases: Proposer, InitialPointProposer

Does the same as MeanCovProposer but tries to get an automatically generated covariance matrix from Cobaya’s Cosmo Input Generator.

Parameters:
  • mean (array-like, shape=(n_dims,)) – Mean-vector of the multivariate normal distribution.

  • model_info (dict) – The info dictionary used to generate the model.

get(*args, **kwargs)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

class proposal.SmallChainProposer(bounds, npoints=100, nsteps=20, nretries=3)[source]#

Bases: Proposer

Uses a short MCMC chain starting from a random training point of the GP to generate proposals. Runs a chain of npoints length and takes the nsteps last points as proposals. Once the proposals have been exhausted or the GP has been fit with new data a new chain is run from a different starting location.

Parameters:
  • bounds (array-like, shape=(n_dims,2)) – Array of bounds of the prior [lower, upper] along each dimension.

  • n_points (int, optional (default=100)) – The max number of samples that is generated from the chain

  • nsteps (int, optional (default=10)) – The number of MC steps that is taken from the end of the chain.

  • nretries (int, optional (default=3)) – The number of times that the MC chain is restarted if it fails. If the chain fails nretries times a warning is printed and samples from a uniform distribution are returned.

update_bounds(bounds)[source]#

Updates the bounds for the proposal.

Parameters:

bounds (array) – Bounds in which to optimize the acquisition function, assumed to be of shape (d,2) for d dimensional prior

get(*args, **kwargs)[source]#

Returns a random sample (given a certain random state) in the parameter space for getting initial training samples or the acquisition function to be optimized from.

If the output is not guaranteed by construction to be within the bounds defined in the bounds attribute, decorated this method with check_in_bounds.

Parameters:

rng (int or numpy.random.Generator, optional) – The generator used to propose points. If an integer is given, it is used as a seed for the default global numpy random number generator.

resample(rng=None)[source]#
update(gpr)[source]#

Updates the internal GP instance if it has been updated with new data.

Parameters:

gpr (GaussianProcessRegressor) – The gpr instance that has been updated.