swyft.bounds

class swyft.bounds.BallsBound(points, scale=1.0)[source]

Simple mask based on coverage balls around inducing points.

Parameters:
  • points (Array) – shape (num_points, n_dim)

  • scale (float) – Scale ball size (default 1.0)

static from_marginal_posterior(n_samples, observation, marginal_posterior, threshold=-13.0, batch_size=None)

see CompositBound.from_marginal_posterior

Parameters:
  • n_samples (int) –

  • observation (ObsType) –

  • marginal_posterior (swyft.inference.marginalposterior.MarginalPosterior) –

  • threshold (float) –

  • batch_size (Optional[int]) –

Return type:

BoundType

classmethod from_state_dict(state_dict)[source]

Instantiate Bound object based on state_dict.

Parameters:

state_dict (dict) – State dictionary

property n_parameters: int

Number of dimensions.

sample(n_samples)[source]

Sample.

Parameters:

n_samples – Numbe of samples.

Returns:

s (n_samples x n_parameters)

property volume: float

Volume of the bound region.

class swyft.bounds.Bound[source]

A bound region on the hypercube.

Note

The Bound object provides methods to sample from subregions of the hypercube, to evaluate the volume of the constrained region, and to evaluate the bound.

static from_marginal_posterior(n_samples, observation, marginal_posterior, threshold=-13.0, batch_size=None)[source]

see CompositBound.from_marginal_posterior

Parameters:
  • n_samples (int) –

  • observation (ObsType) –

  • marginal_posterior (swyft.inference.marginalposterior.MarginalPosterior) –

  • threshold (float) –

  • batch_size (Optional[int]) –

Return type:

BoundType

classmethod from_state_dict(state_dict)[source]

Instantiate Bound object based on state_dict.

Parameters:

state_dict (dict) – State dictionary

Return type:

BoundType

property n_parameters: int

Number of dimensions.

sample(n_samples)[source]

Sample.

Parameters:

n_samples (int) – Numbe of samples.

Returns:

s (n_samples x n_parameters)

Return type:

ndarray

property volume: float

Volume of the bound region.

class swyft.bounds.CompositBound(bounds_map, n_parameters)[source]

Composit bound object. Product of multiple bounds.

Parameters:
  • bounds_map (dict) – Dictionary mapping indices like (0, 3) etc –> bounds

  • n_parameters (int) – Length of parameter vector.

classmethod from_marginal_posterior(n_samples, observation, marginal_posterior, threshold, batch_size=None)[source]

create a new bound object from a marginal posterior by sampling to estimate the log_prob contours

Parameters:
  • n_samples (int) – number of samples to estimate with

  • observation (ObsType) – single observation to define the bounds

  • marginal_posterior (swyft.inference.marginalposterior.MarginalPosterior) – marginal posterior object

  • threshold (float) – above which log weight do we bound? -13 is standard

  • batch_size (Optional[int]) – when evaluating the log_prob, what batch size to use

Returns:

a bound object based on the above

Return type:

BoundType

classmethod from_state_dict(state_dict)[source]

Instantiate Bound object based on state_dict.

Parameters:

state_dict (dict) – State dictionary

classmethod from_weighted_samples(weighted_samples, cdf, n_parameters, threshold)[source]

create a new bound object from weighted samples and the cdf

Parameters:
  • weighted_samples (WeightedMarginalSamples) – log weighted samples

  • cdf (Callable) – transforms from v to u

  • n_parameters (int) – number of total parameters

  • threshold (float) – above which log weight do we bound? -13 is standard.

Returns:

a bound object based on the above

Return type:

BoundType

property n_parameters: int

Number of dimensions.

sample(n_samples)[source]

Sample.

Parameters:

n_samples – Numbe of samples.

Returns:

s (n_samples x n_parameters)

property volume: float

Volume of the bound region.

class swyft.bounds.RectangleBound(rec_bounds)[source]

Rectangle bound.

Parameters:

rec_bounds (n x 2 np.ndarray) – list of (u_min, u_max) values.

Note: 0 <= u_min < u_max <= 1.

static from_marginal_posterior(n_samples, observation, marginal_posterior, threshold=-13.0, batch_size=None)

see CompositBound.from_marginal_posterior

Parameters:
  • n_samples (int) –

  • observation (ObsType) –

  • marginal_posterior (swyft.inference.marginalposterior.MarginalPosterior) –

  • threshold (float) –

  • batch_size (Optional[int]) –

Return type:

BoundType

classmethod from_state_dict(state_dict)[source]

Instantiate Bound object based on state_dict.

Parameters:

state_dict (dict) – State dictionary

property n_parameters

Number of dimensions.

sample(n_samples)[source]

Sample.

Parameters:

n_samples – Numbe of samples.

Returns:

s (n_samples x n_parameters)

property volume

Volume of the bound region.

class swyft.bounds.UnitCubeBound(n_parameters)[source]

The unit hypercube bound.

Initialize unit hypercube bound.

Parameters:

n_parameters (int) – Number of parameters.

static from_marginal_posterior(n_samples, observation, marginal_posterior, threshold=-13.0, batch_size=None)

see CompositBound.from_marginal_posterior

Parameters:
  • n_samples (int) –

  • observation (ObsType) –

  • marginal_posterior (swyft.inference.marginalposterior.MarginalPosterior) –

  • threshold (float) –

  • batch_size (Optional[int]) –

Return type:

BoundType

classmethod from_state_dict(state_dict)[source]

Instantiate Bound object based on state_dict.

Parameters:

state_dict (dict) – State dictionary

property n_parameters: int

Number of dimensions.

sample(n_samples)[source]

Generate samples from the bound region.

Parameters:

n_samples (int) – Number of samples

property volume

The volume of the constrained region.