torchsky.encoders¶
Experimental surface
These APIs are under active development. Names, defaults, and result objects may change between minor releases; pin a version if you depend on them in production.
Coordinate-aware encoders for implicit sky models.
Guides: encoders
This reference is generated from the package source. Names are grouped by
the module that defines them; import every name from the public
namespace torchsky.encoders unless the group text says otherwise.
Top-level namespace¶
Coordinate-aware encoders for implicit sky models.
Note: This module is experimental; its API may change between releases.
SirenImplicitField ¶
SirenImplicitField(
in_features: int,
hidden_features: int = 128,
hidden_layers: int = 3,
out_features: int = 1,
)
SkyCoordinateEncoder ¶
SkyCoordinateEncoder(
*,
num_fourier_frequencies: int = 4,
spectral_frequencies: int = 4,
include_degree2: bool = True,
min_frequency: float = 1.0,
)
Bases: Module
Spherical polynomial + Fourier features, optionally with log-spectral ones.
forward ¶
forward(
ra_deg: Tensor,
dec_deg: Tensor,
*,
wavelength: Optional[Tensor] = None,
frequency: Optional[Tensor] = None,
) -> Tensor
harmonic_sky_encoding ¶
harmonic_sky_encoding(
ra_deg: Tensor,
dec_deg: Tensor,
*,
include_constant: bool = True,
include_degree1: bool = True,
include_degree2: bool = True,
) -> Tensor
Low-order real polynomial basis on the unit sphere (not normalized SH).
Uses (x,y,z) = lonlat_to_xyz(ra_deg, dec_deg) on the unit sphere, then optional
terms: constant; linear x,y,z; quadratic xy, yz, zx, x²−y², 3z²−1. The degree-2
pieces match (unnormalized) real spherical harmonic combinations in Cartesian form,
but this is a feature basis for implicit models, not a complete orthonormal Y_lm stack.
log_spectral_encoding ¶
log_spectral_encoding(
*,
wavelength: Optional[Tensor] = None,
frequency: Optional[Tensor] = None,
num_frequencies: int = 4,
base: float = 2.0,
) -> Tensor
Multi-scale Fourier features for log wavelength or log frequency.
Photometry¶
Coordinate-aware encoders for implicit sky models.
Note: This module is experimental; its API may change between releases.
BinnedRedshiftHead ¶
BinnedRedshiftHead(
latent_dim: int, bin_edges: Sequence[float] | Tensor
)
Bases: Module
Conditional logits with a piecewise-uniform density on explicit z bins.
Output logits represent bin probability masses; log_prob includes bin
width, so nonuniform bins still define a normalized density. Targets outside
the closed support have log probability -inf. Applications must apply
their evidence/support policy; passing supported rejects empty objects.
Training does not by itself establish probability calibration.
MaskedSetFusion ¶
MaskedSetFusion(latent_dim: int)
Bases: Module
Permutation-invariant learned pooling of (..., items, latent_dim).
Returns (latent, supported). Empty sets have a zero latent and false
support. Padding can contain arbitrary values, including NaNs. Attention
weights are representation weights, not association probabilities.
PhotometryEncoder ¶
PhotometryEncoder(
num_passbands: int,
num_surveys: int,
*,
flux_scale: Sequence[float] | Tensor,
num_methods: int = 1,
latent_dim: int = 64,
epoch_origin: float = 2000.0,
epoch_scale: float = 100.0,
)
Bases: Module
Shared measurement-token encoder with explicit vocabulary and scaling.
All inputs have shape (..., measurements). Flux and flux_scale use
the same declared unit per passband. Negative measured flux is valid.
status=0 denotes a detection and status=1 an upper-limit threshold;
neither is padding. error=None or NaN means unknown uncertainty. Known
errors must be finite and positive. Epochs use decimal years with NaN/None
meaning unknown. Vocabulary IDs are caller-owned nonnegative integers.
Returns a latent of shape (..., latent_dim) and a boolean support mask.
No absolute sky position enters this content encoder. Scaling buffers are
saved in state_dict; save the corresponding vocabulary alongside it.
token_encoder
instance-attribute
¶
token_encoder = Sequential(
Linear(latent_dim + 5, latent_dim),
SiLU(),
Linear(latent_dim, latent_dim),
)
forward ¶
forward(
flux: Tensor,
error: Tensor | None,
passband_id: Tensor,
survey_id: Tensor,
*,
mask: Tensor | None = None,
method_id: Tensor | None = None,
status: Tensor | None = None,
epoch: Tensor | None = None,
) -> tuple[Tensor, Tensor]
marginalize_association_logits ¶
marginalize_association_logits(
logits: Tensor,
association_weights: Tensor,
hypothesis_mask: Tensor | None = None,
) -> Tensor
Mix conditional bin masses over mutually exclusive association hypotheses.
Inputs have shapes (..., hypotheses, bins) and (..., hypotheses);
returns normalized log bin masses (..., bins). Nonnegative input weights
are normalized over the supplied hypotheses. Include a no-match hypothesis
when applicable: omitted hypotheses produce a conditional distribution.
This algebra does not turn matcher ranking scores into calibrated weights.