Hypercube¶
Flexible prior distributions with hypercube mapping.
Overview¶
Hypercube maps between a hypercube domain and various target
distributions. This enables uniform treatment of different prior types during
training while preserving the original distribution semantics.
Use Hypercube as the simulator (prior) for latent nodes when pairing with the
Flow estimator.
Supported Distributions¶
| Type | Parameters | Description |
|---|---|---|
uniform |
low, high |
Uniform distribution |
normal |
mean, std |
Gaussian distribution |
cosine |
low, high |
Distribution with pdf proportional to sin(angle) |
sine |
low, high |
Inverse sine mapping |
uvol |
low, high |
Uniform-in-volume |
triangular |
a, c, b |
Triangular distribution (min, mode, max) |
Usage¶
from falcon.priors import Hypercube
# Define priors for 3 parameters
prior = Hypercube(
priors=[
('uniform', -10.0, 10.0),
('normal', 0.0, 1.0),
('triangular', -1.0, 0.0, 1.0),
]
)
# Sample from prior
samples = prior.simulate_batch(1000)
# Transform to/from hypercube space
u = prior.inverse(samples) # To hypercube
x = prior.forward(u) # From hypercube
YAML Configuration¶
simulator:
_target_: falcon.priors.Hypercube
priors:
- ['uniform', -10.0, 10.0]
- ['normal', 0.0, 1.0]
hypercube_range: [-2, 2]
Class Reference¶
Hypercube
¶
Maps a set of univariate priors between a hypercube domain and their target distributions.
This class supports a bi-directional transformation
- forward: maps from a hypercube domain (default range [-2, 2]) to the target distributions.
- inverse: maps from the target distribution domain back to the hypercube.
Supported distribution types and their required parameters
- "uniform": Linear mapping from [0, 1] to [low, high]. Parameters: low, high.
- "cosine": Uses an acos transform for distributions with pdf ∝ sin(angle). Parameters: low, high.
- "sine": Uses an asin transform for a similar angular mapping. Parameters: low, high.
- "uvol": Uniform-in-volume transformation. Parameters: low, high.
- "normal": Maps using the inverse CDF (probit function) for a normal distribution. Parameters: mean, std.
- "triangular": Maps to a triangular distribution via its inverse CDF. Parameters: a (min), c (mode), b (max).
Priors should be provided as a list of tuples
(dist_type, param1, param2, ...)
For example, a uniform prior would be ("uniform", low, high) and a triangular prior would be ("triangular", a, c, b).
Initializes the Hypercube object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priors
|
list
|
List of tuples defining each prior. Each tuple starts with a string specifying the distribution type, followed by its parameters. |
[]
|
hypercube_range
|
list or tuple
|
The range of the hypercube domain (default: [-2, 2]). |
[-2, 2]
|
Source code in falcon/priors/hypercube.py
forward
¶
Applies the forward transformation to a batch of input values.
The input tensor u should have shape (..., n_params), where the last dimension corresponds to different parameters (each in the hypercube_range). First, the values are rescaled to [0,1] and then mapped into the corresponding target distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
Tensor of shape (..., n_params) with values in the hypercube_range. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Tensor of shape (..., n_params) with values in the target distribution domains. |
Source code in falcon/priors/hypercube.py
inverse
¶
Applies the inverse transformation to a batch of values from the target distributions.
The input tensor x should have shape (..., n_params). Each value is mapped back to [0,1] and then rescaled to the hypercube_range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Tensor of shape (..., n_params) with values in the target distribution domains. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Tensor of shape (..., n_params) with values in the hypercube_range. |
Source code in falcon/priors/hypercube.py
simulate_batch
¶
Generates a batch of samples from the target distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of samples to generate. |
required |
Returns:
| Type | Description |
|---|---|
|
torch.Tensor: Tensor of shape (n_samples, n_params) with samples in the target distributions. |