mbank.placement

A lot of placement methods, both for the tiling and the normalizing flow. Most of the methods are deprecated and are not guaranteed to work properly. The functions place_random_flow() are place_stochastically_flow() are guaranteed to work.

create_mesh(dist, tile, coarse_boundaries=None)[source]

Creates a mesh of points on an hypercube, given a metric. The points are approximately equally spaced with a distance dist.

Parameters:
  • dist (float) – Distance between templates

  • tile (tuple) – An element of the tiling_handler object. It consists of a tuple (scipy.spatial.Rectangle, np.ndarray)

  • coarse_boundaries (ndarray) – shape: (2,D) - An array with the coarse boundaries of the tiling. If given, each tile is checked to belong to the border of the tiling. If it’s the case, some templates are added to cover the boundaries

Returns:

mesh – shape: (N,D) - A mesh of N templates that cover the tile

Return type:

ndarray

get_cube_corners(boundaries)[source]

Given the boundaries of an hyper-rectangle, it computes all the corners of it

Parameters:

boundaries (ndarray) – shape: (2,D) - An array with the boundaries for the model. Lower limit is boundaries[0,:] while upper limits is boundaries[1,:]

Returns:

corners – shape: (N,D) - An array with the corners. Each row is a different corner

Return type:

ndarray

place_geometric_flow(minimum_match, flow, metric_obj, n_livepoints, boundaries_checker=None, covering_fraction=0.9, qmc=True, dry_run=False, verbose=True)[source]

It computes the number of templates using the random algorithm place_random_flow(). It then places templates on a grid in the gaussian space or with quasi-Monte Carlo sampling and transforms it back to the normal space

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • flow (flow.GW_flow) – Normalizing flow to sample template from

  • metric_obj (handlers.cbc_metric) – A metric object to evaluate the metric at the livepoints

  • n_livepoints (int) – Number of livepoints to compute the covering fraction with

  • boundaries_checker (callable) –

    A boolean function to check whether each input point is inside the boundaries. If None, no boundaries control will be applied. A common usage would be:

    from mbank.parser import boundary_keeper
    bk = boundary_keeper(args)
    def boundaries_checker(theta):
            return bk(theta, args.variable_format)
    

  • covering_fraction (float) – Fraction of livepoints to be killed before terminating the loop

  • qmc (bool) – Whether to sample the templates in the latent space with a quasi-MC algorithm. If False, templates will lie in a grid

  • dry_run (bool) – Whether to run the placement without actually storing the templates. It is useful for the purpose of bank size measurement

  • verbose (bool) – Whether to display the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the placing algorithm. If dry_run is set, only the number of templates will be returned

Return type:

ndarray, int

place_iterative(match, t)[source]

Given a tile, it returns the templates within the tile obtained by iterative splitting.

Parameters:
  • match (float) – Match defining the template volume

  • t (tile) – The tile to cover with templates

Returns:

new_templates – Array with the generated templates

Return type:

ndarray

place_pruning(minimum_match, tiling, N_points, covering_fraction=0.9, verbose=True)[source]

Given a tiling object, it covers the volume with points and covers them with templates. It uses a pruning method, where proposal are chosen from a large set of random points, called livepoints. The bank is created by selecting a proposal from the set of livepoints and removing (killing) the livepoints too close from the proposal. This methods effectively prunes the original set of livepoints, to remove the random points that are too close from each other.

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • tiling (tiling_handler) – Tiling handler that tiles the parameter space

  • N_points (int) – Number of livepoints to cover the space with

  • covering_fraction (float) – Fraction of livepoints to be killed before terminating the loop

  • verbose (bool) – Whether to display the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the placing algorithm

Return type:

ndarray

place_random_flow(minimum_match, flow, metric_obj, n_livepoints, boundaries_checker=None, covering_fraction=0.9, dry_run=False, importance_sampling=False, metric_type='symphony', verbose=True)[source]

Draw templates from the flow. For each proposal, all the livepoints in the ellipse of constant minimum_match are killed. The iteration goes on until a fraction of covering_fraction of the space is covered. It follows 2202.09380

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • flow (flow.GW_flow) – Normalizing flow to sample template from

  • metric_obj (handlers.cbc_metric) – A metric object to evaluate the metric at the livepoints

  • n_livepoints (int) – Number of livepoints to compute the covering fraction with

  • boundaries_checker (callable) –

    A boolean function to check whether each input point is inside the boundaries. If None, no boundaries control will be applied. A common usage would be:

    from mbank.parser import boundary_keeper
    bk = boundary_keeper(args)
    def boundaries_checker(theta):
            return bk(theta, args.variable_format)
    

  • covering_fraction (float) – Fraction of livepoints to be killed before terminating the loop

  • dry_run (bool) – Whether to run the placement without actually storing the templates. It is useful for the purpose of bank size measurement

  • importance_sampling (bool) – Whether to compute the covering fraction using importance sampling. Importance sampling gives a more accurate estimation of the covering fraction but at the cost of a higher variance in the number of templates.

  • metric_type (str) – The method to compute the metric. Default ‘symphony’

  • verbose (bool) – Whether to display the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the placing algorithm. If dry_run is set, only the number of templates will be returned

Return type:

ndarray, int

place_random_tiling(minimum_match, tiling, N_livepoints, covering_fraction=0.9, verbose=True)[source]

Draw templates from the uniform distribution on the manifold. For each proposal, all the livepoints in the ellipse of constant minimum_match are killed. The iteration goes on until a fraction of covering_fraction of livepoints are alive. It follows 2202.09380

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • tiling (tiling_handler) – Tiling handler that tiles the parameter space

  • N_livepoints (int) – Number of livepoints to cover the space with

  • covering_fraction (float) – Fraction of livepoints to be killed before terminating the loop

  • verbose (bool) – Whether to display the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the placing algorithm

Return type:

ndarray

place_stochastically(minimum_match, tiling, empty_iterations=200, seed_bank=None, verbose=True)[source]

Place templates with a stochastic placing algorithm. It iteratively proposes a new template to add to the bank. The proposal is accepted if the match of the proposal with the previously placed templates is smaller than minimum_match. The iteration goes on until no template is found to have a distance smaller than the given threshold minimum_match. It can start from a given set of templates.

The match of a proposal is computed against all the templats that have been added.

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • tiling (tiling_handler) – A tiling object to compute the match with

  • empty_iterations (int) – Number of consecutive templates that are not accepted before the placing algorithm is terminated

  • seed_bank (ndarray) – shape: (N,D) - A set of templates that provides a first guess for the bank

  • verbose (bool) – Whether to print the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the stochastic placing algorithm

Return type:

ndarray

place_stochastically_flow(minimum_match, flow, metric_obj, boundaries_checker=None, empty_iterations=200, seed_bank=None, dry_run=False, verbose=True)[source]

Place templates with a stochastic placing algorithm. It iteratively proposes a new template to add to the bank. The proposal is accepted if the match of the proposal with the previously placed templates is smaller than minimum_match. The iteration goes on until no template is found to have a distance smaller than the given threshold minimum_match. It can start from a given set of templates.

The match of a proposal is computed against all the templats that have been added.

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • flow (flow.GW_flow) – Normalizing flow to sample template from

  • metric_obj (handlers.cbc_metric) – A metric object to evaluate the metric at the livepoints

  • boundaries_checker (callable) –

    A boolean function to check whether each input point is inside the boundaries. If None, no boundaries control will be applied. A common usage would be:

    from mbank.parser import boundary_keeper
    bk = boundary_keeper(args)
    def boundaries_checker(theta):
            return bk(theta, args.variable_format)
    

  • empty_iterations (int) – Number of consecutive templates that are not accepted before the placing algorithm is terminated

  • seed_bank (ndarray) – shape: (N,D) - A set of templates that provides a first guess for the bank

  • dry_run (bool) – Whether to run the placement without actually storing the templates. It is useful for the purpose of bank size measurement

  • verbose (bool) – Whether to print the progress bar

Returns:

new_templates – shape: (N,D) - A set of templates generated by the stochastic placing algorithm

Return type:

ndarray

place_stochastically_in_tile(minimum_match, tile)[source]

Place templates with a stochastic placing algorithm withing a given tile, by iteratively proposing a new template to add to the bank inside the given tile. The proposal is accepted if the match of the proposal with the previously placed templates is smaller than minimum_match. The iteration goes on until no template is found to have a distance smaller than the given threshold minimum_match.

Parameters:
  • minimum_match (float) – Minimum match between templates.

  • tile (tuple) – An element of the tiling_handler object. It consists of a tuple (scipy.spatial.Rectangle, np.ndarray)

Returns:

new_templates – shape: (N,D) - A set of templates generated by the stochastic placing algorithm within the given tile

Return type:

ndarray