Skip to content

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,
)

Bases: Module

SIREN multilayer perceptron over precomputed features.

net instance-attribute

net = Sequential(*layers)

forward

forward(x: Tensor) -> Tensor

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.

include_degree2 instance-attribute

include_degree2 = include_degree2

min_frequency instance-attribute

min_frequency = float(min_frequency)

num_fourier_frequencies instance-attribute

num_fourier_frequencies = num_fourier_frequencies

spectral_frequencies instance-attribute

spectral_frequencies = spectral_frequencies

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.

bin_edges instance-attribute

bin_edges: Tensor

linear instance-attribute

linear = Linear(latent_dim, numel() - 1)

forward

forward(
    latent: Tensor, *, supported: Tensor | None = None
) -> Tensor

log_prob

log_prob(logits: Tensor, redshift: Tensor) -> Tensor

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.

latent_dim instance-attribute

latent_dim = latent_dim

output instance-attribute

output = Sequential(
    Linear(latent_dim + 1, latent_dim), SiLU()
)

score instance-attribute

score = Linear(latent_dim, 1)

forward

forward(
    tokens: Tensor, mask: Tensor | None = None
) -> tuple[Tensor, Tensor]

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.

epoch_origin instance-attribute

epoch_origin: Tensor

epoch_scale instance-attribute

epoch_scale: Tensor

flux_scale instance-attribute

flux_scale: Tensor

fusion instance-attribute

fusion = MaskedSetFusion(latent_dim)

method_embedding instance-attribute

method_embedding = Embedding(num_methods, latent_dim)

passband_embedding instance-attribute

passband_embedding = Embedding(num_passbands, latent_dim)

status_embedding instance-attribute

status_embedding = Embedding(2, latent_dim)

survey_embedding instance-attribute

survey_embedding = Embedding(num_surveys, latent_dim)

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.