Boundaries¶
Discretize and Embed, which move between bounded continuous spaces
and finite sets.
boundaries
¶
Boundary morphisms between discrete and continuous spaces.
These morphisms bridge the gap between the finite tensor world (FinSet, discrete Morphism) and the continuous sampling world (ContinuousSpace, ContinuousMorphism).
Morphisms provided
Discretize — continuous space -> finite set (binning) Embed — finite set -> continuous space (kernel density)
Discretize
¶
Discretize(domain: Euclidean, n_bins: int, soft: bool = True, temperature: float = 0.1)
Bases: ContinuousMorphism
Map a continuous space to a finite set by binning.
Divides a bounded continuous space into n_bins equal-width bins and assigns each continuous input to the bin containing it. The resulting distribution is deterministic (one-hot on the correct bin).
This is useful for converting continuous outputs into discrete categories for downstream processing in the finite tensor world.
For log_prob: returns log(1) = 0 if y equals the correct bin, log(0) otherwise. In practice uses a soft assignment based on distance to bin centers for gradient flow.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source continuous space (must be bounded, 1-dimensional).
TYPE:
|
n_bins
|
Number of discrete bins.
TYPE:
|
soft
|
If True (default), use soft binning via softmax over negative squared distances. If False, use hard (argmax) assignment.
TYPE:
|
temperature
|
Temperature for soft binning. Lower = sharper.
TYPE:
|
Source code in src/quivers/continuous/boundaries.py
log_prob
¶
Log-probability of bin assignment y given input x.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Continuous inputs. Shape (batch, 1).
TYPE:
|
y
|
Bin indices. Shape (batch,).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log-probabilities. Shape (batch,). |
Source code in src/quivers/continuous/boundaries.py
rsample
¶
Assign continuous inputs to discrete bins.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Continuous inputs. Shape (batch, 1).
TYPE:
|
sample_shape
|
Ignored (assignment is deterministic). |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Bin indices. Shape (batch,) or (*sample_shape, batch). |
Source code in src/quivers/continuous/boundaries.py
Embed
¶
Bases: ContinuousMorphism
Map a finite set to a continuous space via kernel density placement.
Each element i of the domain FinSet is associated with a point in the continuous codomain. Sampling from Embed(x=i) produces a value near that point, with learnable spread.
Concretely, Embed places a Gaussian kernel at each bin center:
p(y | i) = Normal(center_i, sigma_i)
The centers and log-sigmas are learnable parameters.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source discrete set.
TYPE:
|
codomain
|
Target continuous space (should be bounded for initialization).
TYPE:
|
Source code in src/quivers/continuous/boundaries.py
base_dimension
¶
base_dimension(x: Tensor) -> int
One standard-normal coordinate per embedded output axis.
A (batch, seq) index matrix places one kernel per
position, so the budget grows with the sequence length as well
as the codomain dimension.
Source code in src/quivers/continuous/boundaries.py
push_base
¶
The location-scale map around the embedding of x.
log_prob
¶
Log-density of y under the kernel centered at x's embedding.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Domain indices. Shape (batch,).
TYPE:
|
y
|
Continuous outputs. Shape (batch, d).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log-densities. Shape (batch,). |
Source code in src/quivers/continuous/boundaries.py
rsample
¶
Sample from the Gaussian kernel at x's embedding point.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Domain indices. Shape (batch,).
TYPE:
|
sample_shape
|
Additional sample dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Continuous samples. Shape (*sample_shape, batch, d). |