Encoding Mixins#
Mixins that provide encode() interfaces for inference.
BasicEncodingMixin#
Simple encoding for models that produce single-resolution representations.
Lightweight shared encoding mixin for fixed-length sequence models.
Provides a uniform encode(data, batch_size, num_workers) API for models that
process whole sequences in a single forward pass (TST, TimeVAE, TimeNet,
MCL, TS-TCC, Series2Vec). Models that need sliding-window inference, multi-scale
pooling, or mask-mode handling (the dilated trio: TS2Vec, AutoTCL, CoST) should
use the heavier mixins under convolutional/dilated/_mixin/ instead.
Subclasses expose their encoder via BasicEncodingMixin._get_encoder()
and, when needed, customize input preparation and output post-processing via
_prepare_inputs() and _postprocess(). The mixin itself owns the
DataLoader iteration, eval/inference mode handling, device placement, encoder
invocation, and result concatenation.
- class chronocratic.models._mixin.encoding.BasicEncodingMixin#
Bases:
ABCUniform
encode()API for fixed-length sequence models.Designed to be mixed into a
lightning.pytorch.LightningModule. The LightningModule is expected to provideself.deviceso that batches can be moved onto the model’s device.Subclasses implement
_get_encoder()(required) and may override_get_encoder_module(),_prepare_inputs(), and_postprocess()to adapt the contract to encoders that take extra arguments or return non-tensor structures.The mixin manages the
training/evalstate of the encoder module (not the whole LightningModule) so thatencode()does not perturb submodules that are unrelated to inference (e.g. contrastive heads, auxiliary loss modules).- encode(data: Tensor, batch_size: int, num_workers: int = 0) Tensor#
Extract representations for
datain mini-batches.Iterates
datathrough aDataLoader, moves each batch toself.device, invokes the encoder via the_get_encoder/_prepare_inputs/_postprocesshooks underinference_mode, and concatenates the per-batch outputs on dim 0. The model’s prior training-mode state is preserved across the call.- Parameters:
data – Input tensor of shape
(N, ...)— leading dim is the sample dimension, the rest is whatever the model expects.batch_size – Mini-batch size for inference.
num_workers – Number of DataLoader workers.
- Returns:
CPU tensor of shape
(N, ...)— concatenation of per-batch representations along dim 0.
PoolingEncodingMixin#
Multi-resolution encoding with sliding window and pooling. Used by dilated convolutional models.
- class chronocratic.models.convolutional.dilated._mixin.encoding.BaseEncodingMixin#
Bases:
ABCBase mixin providing shared encoding logic for time series models.
Contains the public
encode()entry point, sliding window computation, and default strategy methods. Subclasses override_get_encoder(),_get_eval_method(), and_get_slice()to provide model-specific behavior.Attributes are intentionally declared here but implemented by subclasses: TS2Vec, AutoTCL (pooling), CoST (decomposition).
- encode(data: Tensor, batch_size: int, num_workers: int, mask: MaskMode | None = None, encoding_window: str | int | None = None, *, causal: bool = False, sliding_length: int | None = None, sliding_padding: int = 0) Tensor#
Compute representations using the model.
- Parameters:
data – Shape (n_instance, n_timestamps, n_features). Missing data set to NaN.
batch_size – Batch size used for inference.
num_workers – Number of workers used for data loading.
mask – Mask for the encoder. One of ‘binomial’, ‘continuous’, ‘all_true’, ‘all_false’, or ‘mask_last’.
encoding_window – Pooling strategy. ‘full_series’, ‘multiscale’, or an integer for the pooling kernel size.
causal – If True, future information is not encoded.
sliding_length – Sliding window length. If set, sliding inference is applied.
sliding_padding – Contextual data length for each sliding window.
- Returns:
The representations for data.
- class chronocratic.models.convolutional.dilated._mixin.encoding.DecompositionEncodingMixin#
Bases:
BaseEncodingMixinMixin for decomposition-based encoding (CoST).
Extends
BaseEncodingMixinwith trend+seasonality feature concatenation evaluation. Models inheriting this mixin encode decomposed components and concatenate their final-step features rather than using pooling slices.
- class chronocratic.models.convolutional.dilated._mixin.encoding.PoolingEncodingMixin#
Bases:
BaseEncodingMixinMixin for pooling-based encoding (TS2Vec, AutoTCL).
Extends
BaseEncodingMixinwith slice computation and pooling evaluation strategies. Models inheriting this mixin use multi-scale or integer pooling to produce fixed-length representations.