Jim
Jim
¤
Master class for gravitational-wave parameter estimation.
Wires together a LikelihoodBase, a
Prior, optional parameter transforms, and a
pluggable JAX Sampler selected via a typed
sampler_config object.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise Jim and build the internal sampler. |
add_name |
Convert a flat sampling-space array to a named dict. |
evaluate_posterior |
Log-posterior in the sampling space. |
evaluate_prior |
Log-prior in the sampling space (with Jacobian corrections from sample_transforms). |
get_diagnostics |
Return run-level diagnostics from the most recent |
get_samples |
Retrieve posterior samples in prior space, optionally downsampled. |
sample |
Run the sampler. |
sample_initial_positions |
Draw |
__init__(likelihood: LikelihoodBase, prior: Prior, sampler_config: SamplerConfig, *, sample_transforms: Sequence[BijectiveTransform] = (), likelihood_transforms: Sequence[NtoMTransform] = (), periodic: Optional[list[str] | dict[str, tuple[float, float]]] = None, seed: int = 0, verbose: bool = False) -> None
¤
Initialise Jim and build the internal sampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
likelihood
|
LikelihoodBase
|
The likelihood to evaluate. |
required |
prior
|
Prior
|
The prior distribution. |
required |
sampler_config
|
SamplerConfig
|
Pydantic config selecting and configuring the
sampler backend (e.g. |
required |
sample_transforms
|
Sequence[BijectiveTransform]
|
Bijective transforms applied in the sampling space (reversed when retrieving posterior samples). |
()
|
likelihood_transforms
|
Sequence[NtoMTransform]
|
Transforms applied to reach the likelihood parameter space from the prior parameter space. |
()
|
periodic
|
Optional[list[str] | dict[str, tuple[float, float]]]
|
Periodic sampling-space parameters. For most samplers,
pass a |
None
|
seed
|
int
|
Integer random seed. The key for the sampling run is derived
from this seed at construction time, so |
0
|
verbose
|
bool
|
Enable DEBUG-level logging for all |
False
|
add_name(x: Float[Array, ' n_dims']) -> dict[str, Float]
¤
Convert a flat sampling-space array to a named dict.
evaluate_posterior(params: Float[Array, ' n_dims']) -> Float
¤
Log-posterior in the sampling space.
evaluate_prior(params: Float[Array, ' n_dims']) -> Float
¤
Log-prior in the sampling space (with Jacobian corrections from sample_transforms).
get_diagnostics() -> dict[str, Any]
¤
Return run-level diagnostics from the most recent sample call.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Plain dict of backend-specific diagnostics. |
get_samples(n_samples: int = 0) -> dict[str, np.ndarray]
¤
Retrieve posterior samples in prior space, optionally downsampled.
Calls Sampler.get_samples on the
underlying sampler, which returns equally-weighted posterior samples.
Pass n_samples to further downsample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Target number of samples. If 0 (default) returns all |
0
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dict mapping prior parameter names to 1-D numpy arrays in prior |
dict[str, ndarray]
|
space, plus an extra item containing the log-likelihood values. |
sample(initial_position: Optional[Float[Array, 'n_chains n_dims']] = None) -> None
¤
Run the sampler.
The sampling key is pre-reserved at construction time from seed,
so results are reproducible regardless of any calls made before this
method (e.g. the construction-time posterior verification).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_position
|
Optional[Float[Array, 'n_chains n_dims']]
|
Starting positions in sampling space, or
The concrete sampler validates the shape and raises
|
None
|
sample_initial_positions(n_points: int, rng_key: Optional[Key] = None) -> Float[Array, 'n_points n_dims']
¤
Draw n_points initial positions from the prior in sampling space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_points
|
int
|
Number of positions to draw. |
required |
rng_key
|
Optional[Key]
|
Optional explicit PRNG key. If |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'n_points n_dims']
|
Array of shape |