Skip to content
Snippets Groups Projects

Fix constrained prior sampling

Merged Colm Talbot requested to merge constrained-prior-sampling into master

The following simple example was failing due to inconsistent use of iteration parameter names.

I think the issue is that currently, this method assumes that the constraint parameters aren't added to the original dictionary.

This MR fixes that and simplifies some of the other logic in sampling from a constrained space.

def convert_x_y_to_z(parameters):
    """
    Function to convert between sampled parameters and constraint parameter.

    Parameters
    ----------
    parameters: dict
        Dictionary containing sampled parameter values, 'x', 'y'.

    Returns
    -------
    dict: Dictionary with constraint parameter 'z' added.
    """
    parameters['z'] = parameters['x'] - parameters['y']
    return parameters


from bilby.core.prior import PriorDict, Uniform, Constraint

priors = PriorDict(conversion_function=convert_x_y_to_z)
priors['x'] = Uniform(minimum=0, maximum=10)
priors['y'] = Uniform(minimum=0, maximum=10)
priors['z'] = Constraint(minimum=0, maximum=10)
priors.sample(10)

Merge request reports

Pipeline #152140 passed

Pipeline passed for 5a38411e on constrained-prior-sampling

Test coverage 61.00% (0.00%) from 1 job
Approved by

Merged by Moritz HuebnerMoritz Huebner 4 years ago (Sep 3, 2020 3:09pm UTC)

Merge details

  • Changes merged into master with 4ca86425 (commits were squashed).
  • Deleted the source branch.

Pipeline #152987 failed

Pipeline failed for 4ca86425 on master

Test coverage 61.00% (0.00%) from 1 job

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading