ComponentAdaptation

Inheritance diagram of gmmvi.optimization.gmmvi_modules.component_adaptation.ComponentAdaptation, gmmvi.optimization.gmmvi_modules.component_adaptation.FixedComponentAdaptation, gmmvi.optimization.gmmvi_modules.component_adaptation.VipsComponentAdaptation
class gmmvi.optimization.gmmvi_modules.component_adaptation.ComponentAdaptation[source]

This class provides a common interface for adapting the number of components.

There are currently only two options:

1. The FixedComponentAdaptation a dummy-class, that does not do anything.

2. The VipsComponentAdaptation uses the procedure of VIPS [AZN20] to add and delete components.

Parameters:
  • gmm_wrapperGmmWrapper The wrapped model where we want to adapt the number of components.

  • sample_dbSampleDB The sample database can be used to select candidate locations for adding a new component, without having to perform additional queries to the target distribution.

  • target_distributionLNPDF The target distribution can be used to evaluate candidate locations for adding a new component.

  • prior_mean – tf.Tensor A one dimensional tensor of size num_dimensions, specifying the mean of the Gaussian that we can use to sample candidate locations for adding a new component.

  • initial_cov – tf.Tensor A two-dimensional tensor of size num_dimensions x num_dimensions, specifying the covariance of the Gaussian that we can use to sample candidate locations for adding a new component.

static build_from_config(config, gmm_wrapper, sample_db, target_distribution, prior_mean, initial_cov)[source]

This static method provides a convenient way to create a FixedComponentAdaptation or VipsComponentAdaptation depending on the provided config.

Parameters:
  • config – dict The dictionary is typically read from YAML a file, and holds all hyperparameters.

  • gmm_wrapperGmmWrapper The wrapped model where we want to adapt the number of components.

  • sample_dbSampleDB The sample database can be used to select candidate locations for adding a new component, without having to perform additional queries to the target distribution.

  • target_distributionLNPDF The target distribution can be used to evaluate candidate locations for adding a new component.

  • prior_mean – tf.Tensor A one dimensional tensor of size num_dimensions, specifying the mean of the Gaussian that we can use to sample candidate locations for adding a new component.

  • initial_cov – tf.Tensor A two-dimensional tensor of size num_dimensions x num_dimensions, specifying the covariance of the Gaussian that we can use to sample candidate locations for adding a new component.

FixedComponentAdaptation

class gmmvi.optimization.gmmvi_modules.component_adaptation.FixedComponentAdaptation[source]

This is a dummy class, used when we do not want to adapt the number of components during learning.

adapt_number_of_components(iteration)[source]

As we do not want to change the number of components, this method does not do anything.

Parameters:

iteration – int The current iteration (ignored).

VipsComponentAdaptation

class gmmvi.optimization.gmmvi_modules.component_adaptation.VipsComponentAdaptation(model: GmmWrapper, sample_db: SampleDB, target_lnpdf: LNPDF, prior_mean: Union[float, Tensor], initial_cov: Union[float, Tensor], del_iters: int, add_iters: int, max_components: int, thresholds_for_add_heuristic: float, min_weight_for_del_heuristic: float, num_database_samples: int, num_prior_samples: int)[source]

This class implements the component adaptation procedure used by VIPS.

See [AZN20].

Parameters:
  • gmm_wrapperGmmWrapper The wrapped model where we want to adapt the number of components.

  • sample_dbSampleDB The sample database can be used to select candidate locations for adding a new component, without having to perform additional queries to the target distribution.

  • target_distributionLNPDF The target distribution can be used to evaluate candidate locations for adding a new component.

  • prior_mean – tf.Tensor A one dimensional tensor of size num_dimensions, specifying the mean of the Gaussian that we can use to sample candidate locations for adding a new component.

  • initial_cov – tf.Tensor A two-dimensional tensor of size num_dimensions x num_dimensions, specifying the covariance of the Gaussian that we can use to sample candidate locations for adding a new component.

  • del_iters – int minimum number of updates a component needs to have received, before it is considered as candidate for deletion.

  • add_iters – int a new component will be added every add_iters iterations

  • max_components – int do not add components, if the model has at least max_components components

  • num_database_samples – int number of samples from the SampleDB that are used for selecting a good initial mean when adding a new component.

  • num_prior_samples – int number of samples from the prior distribution that are used for selecting a good initial mean when adding a new component.

adapt_number_of_components(iteration: int)[source]

This method may change the number of components, either by deleting bad components that have low weights, or by adding new components.

Parameters:

iteration – int The current iteration, used to decide whether a new component should be added.

add_at_best_location(samples, target_lnpdfs)[source]

Find the most promising [AZN20] location among the provided samples for adding a new component, that is, a new component will be added with mean given by one of the provided samples.

Parameters:
  • samples – tf.Tensor candidate locations for initializing the mean of the new component

  • target_lnpdfs – tf.Tensor for each candidate location, this tensor contains the log-density under the (unnormalized) target distribution.

add_new_component()[source]

This method adds a new component by first selecting a set of candidate locations and the choosing the most promising one using the procedure of VIPS [AZN20].

delete_bad_components()[source]

Components are deleted, if all the following criteria are met received:

  1. It must have received at least del_iters updates

  2. It must not have improved significantly during the last iterations. In contrast to VIPS, we use a Gaussian filter to smooth the rewards of the component, to be more robust with respect to noisy target distributions.

  3. It must have very low weight, such that the effects on the model are negligible.

select_samples_for_adding_heuristic()[source]

Select a set of samples used as candidates for initializing the mean of the new component.

Returns:

samples - the selected candidate locations

target_lnpdfs - log-densities of the samples under the unnormalized target distribution

prior_samples - additional samples drawn from a prior, which have not yet been evaluated on the target distribution.

Return type:

tuple(tf.Tensor, tf.Tensor, tf.Tensor)