sequince.transforms#
Coordinate transforms used to manipulate particle states during mutation.
Attributes#
Classes#
Mapping between the open unit interval and the real line. |
|
Map the unit interval to the real line with a stabilized logit. |
|
Map the unit interval to the real line with a Cauchy quantile. |
|
Map the unit interval to the real line with a normal quantile. |
|
Coordinate transform interface for particle mutation. |
|
No-op transform that simply returns the input particles. |
|
Adapt a normalizing flow to the |
|
Standardize coordinates using batch mean and variance statistics. |
|
Whiten a complete Euclidean particle vector with an affine transform. |
|
Linearly rescale specified coordinates into the unit hypercube. |
|
Send bounded coordinates to the real line independently. |
|
Wrap selected periodic coordinates, optionally centering their mean. |
|
Compose multiple transforms while tracking cumulative log-Jacobians. |
Functions#
|
Apply a particle selection to particle-aligned auxiliary array leaves. |
|
Return whether an auxiliary pytree contains particle-aligned arrays. |
|
Resolve a built-in mapping name or validate a mapping strategy object. |
|
Return a prebuilt particle transform by name. |
Module Contents#
- sequince.transforms.logger#
- sequince.transforms.Bounds#
- sequince.transforms.select_transform_auxiliary(auxiliary, selection, *, n_particles)[source]#
Apply a particle selection to particle-aligned auxiliary array leaves.
Every array leaf satisfying
leaf.ndim > 0andleaf.shape[0] == n_particlesis particle-aligned and receivesselection. Other leaves are returned unchanged; this shape convention assigns no additional semantics to them.- Parameters:
auxiliary (Any)
selection (Any)
n_particles (int)
- Return type:
Any
- sequince.transforms.has_particle_aligned_auxiliary(auxiliary, *, n_particles)[source]#
Return whether an auxiliary pytree contains particle-aligned arrays.
- class sequince.transforms.UnitIntervalMapping[source]#
Bases:
ProtocolMapping between the open unit interval and the real line.
Implementations return the elementwise log absolute determinant alongside transformed values. They must preserve the Array API namespace of their input.
- class sequince.transforms.LogitMapping[source]#
Map the unit interval to the real line with a stabilized logit.
- Parameters:
eps (float, default=1e-6) – Clamp values to
[eps, 1 - eps]before applying the logit.
- class sequince.transforms.CauchitMapping[source]#
Map the unit interval to the real line with a Cauchy quantile.
- Parameters:
eps (float, default=1e-6) – Clamp values to
[eps, 1 - eps]before applying the quantile.
- class sequince.transforms.ProbitMapping[source]#
Map the unit interval to the real line with a normal quantile.
- Parameters:
eps (float, default=1e-6) – Clamp values to
[eps, 1 - eps]before applying the quantile.
- sequince.transforms.get_unit_interval_mapping(mapping)[source]#
Resolve a built-in mapping name or validate a mapping strategy object.
- Parameters:
mapping (str | UnitIntervalMapping)
- Return type:
- class sequince.transforms.ParticleTransform[source]#
Coordinate transform interface for particle mutation.
Use
fit()to optionally adapt internal statistics using the particle cloud.forward()returns transformed particles, log-Jacobian values, and auxiliary data.inverse()undoes the forward transform.- fit(particles, context=None, *, rng=None)[source]#
Return a transform fitted to the supplied
particles.- Parameters:
rng (sequince.utils.random.RNGLike)
- class sequince.transforms.IdentityTransform[source]#
Bases:
ParticleTransformNo-op transform that simply returns the input particles.
- class sequince.transforms.FlowTransform[source]#
Bases:
ParticleTransformAdapt a normalizing flow to the
ParticleTransforminterface.- fit(particles, context=None, *, rng=None)[source]#
Return a transform fitted to the supplied
particles.- Parameters:
rng (sequince.utils.random.RNGLike)
- class sequince.transforms.AffineTransform[source]#
Bases:
ParticleTransformStandardize coordinates using batch mean and variance statistics.
- Parameters:
- fit(particles, context=None, *, rng=None)[source]#
Return a transform fitted to the supplied
particles.- Parameters:
rng (sequince.utils.random.RNGLike)
- class sequince.transforms.WhiteningTransform[source]#
Bases:
ParticleTransformWhiten a complete Euclidean particle vector with an affine transform.
The transform is fitted to a particle population and maps its coordinates according to
z = L**-1 (x - mean), whereL L.Tis a regularized estimate of the population covariance. It is intended to be composed after any problem-specific transforms which unwrap periodic coordinates or otherwise make the representation suitable for Euclidean linear algebra.- Parameters:
eps (float, default=1e-6) – Relative diagonal regularization. Each variance receives
epstimes its own scale. Exactly constant directions receive a smaller floor tied to the largest variance and the precision of the array dtype. Values below machine precision are promoted to machine precision.
- fit(particles, context=None, *, rng=None)[source]#
Return a transform fitted to the unweighted particle population.
- Parameters:
rng (sequince.utils.random.RNGLike)
- class sequince.transforms.BoundedToUnitHypercubeTransform[source]#
Bases:
ParticleTransformLinearly rescale specified coordinates into the unit hypercube.
- Parameters:
bounds (Mapping[int, tuple[float, float]]) – Dictionary mapping column indices to
(lower, upper)bounds. Each lower bound must be strictly smaller than the corresponding upper bound.
- bounds: Bounds#
- class sequince.transforms.BoundedToUnboundedTransform[source]#
Bases:
BoundedToUnitHypercubeTransformSend bounded coordinates to the real line independently.
- Parameters:
bounds (Mapping[int, tuple[float, float]]) – Dictionary of coordinate bounds, as defined in
BoundedToUnitHypercubeTransform.mapping (str | UnitIntervalMapping, default="logit") – Built-in mapping name or an object implementing
forwardandinverse. Built-in options are"logit","cauchit", and"probit".
- mapping: str | UnitIntervalMapping = 'logit'#
- class sequince.transforms.PeriodicBoundaryTransform[source]#
Bases:
ParticleTransformWrap selected periodic coordinates, optionally centering their mean.
- Parameters:
bounds (Mapping[int, tuple[float, float]]) – Map from index to
(lower, upper)bounds defining the periodic interval for each coordinate.centering ({None, "circular-mean", "angular-mean"}, optional) – With
None(default), only wrap into the configured interval. With"circular-mean", first callfit()to estimate the unweighted circular mean of each selected coordinate. Forward values are offsets from that mean in[-width / 2, width / 2); inverse values are restored to[lower, upper). Usesscipy.stats.circmean(); when the mean resultant vector is zero, the center is implementation-defined, as in SciPy."angular-mean"is an alias for"circular-mean". Underscore spellings ("circular_mean"and"angular_mean") are also accepted.
- bounds: Bounds#
- fit(particles, context=None, *, rng=None)[source]#
Return a fitted copy using a cloud of shape (n_particles, n_dims).
Circular-mean fitting requires a nonempty floating-point cloud and uses the configured interval width as the period.
- Parameters:
particles (sequince.typing.Array)
context (Any)
rng (sequince.utils.random.RNGLike)
- Return type:
- class sequince.transforms.CompositeTransform[source]#
Bases:
ParticleTransformCompose multiple transforms while tracking cumulative log-Jacobians.
Forward auxiliary data is a tuple with exactly one entry per component, including
Noneentries. Inversion validates this shape and supplies entries to their components in reverse transform order. A supplied RNG is resolved once and advanced sequentially across components, which avoids reusing functional random keys.- Parameters:
transforms (Sequence[ParticleTransform]) – Ordered sequence of transforms to apply. The forward pass executes transforms from first to last, while the inverse pass applies them in reverse.
- transforms: Sequence[ParticleTransform]#
- fit(particles, context=None, *, rng=None)[source]#
Return a transform fitted to the supplied
particles.- Parameters:
rng (sequince.utils.random.RNGLike)
- sequince.transforms.get_prebuilt_transform(name, **kwargs)[source]#
Return a prebuilt particle transform by name.
- Parameters:
name (str) – Name of the desired transform. Supported options are
"identity","affine","whitening","bounded_to_unit_hypercube","bounded_to_unbounded", and"periodic_boundary".**kwargs – Additional keyword arguments passed to the transform constructor.
- Returns:
The requested particle transform instance.
- Return type: