Documentation
¶
Overview ¶
Package timeseries implements time-series model builders.
Package timeseries implements time-series model builders.
Package timeseries implements GGUF metadata loading for time-series models.
Index ¶
- func BuildPatchTST[T tensor.Numeric](cfg PatchTSTConfig, engine compute.Engine[T]) (*graph.Graph[T], error)
- func BuildTFT[T tensor.Numeric](cfg TFTConfig, engine compute.Engine[T]) (*graph.Graph[T], error)
- type PatchTSTBuilder
- type PatchTSTConfig
- type RegimeConfig
- type RegimeDetector
- func (rd *RegimeDetector[T]) Attributes() map[string]interface{}
- func (rd *RegimeDetector[T]) Backward(_ context.Context, _ types.BackwardMode, _ *tensor.TensorNumeric[T], ...) ([]*tensor.TensorNumeric[T], error)
- func (rd *RegimeDetector[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (rd *RegimeDetector[T]) OpType() string
- func (rd *RegimeDetector[T]) OutputShape() []int
- func (rd *RegimeDetector[T]) Parameters() []*graph.Parameter[T]
- type TFTConfig
- type TimeSeriesSignalConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPatchTST ¶
func BuildPatchTST[T tensor.Numeric](cfg PatchTSTConfig, engine compute.Engine[T]) (*graph.Graph[T], error)
BuildPatchTST constructs a PatchTST computation graph. Input: [batch, seq_len, num_vars] time series. Output: [batch, horizon, num_vars] predictions.
Types ¶
type PatchTSTBuilder ¶
type PatchTSTBuilder[T tensor.Numeric] func(cfg TimeSeriesSignalConfig, engine compute.Engine[T]) (*graph.Graph[T], error)
PatchTSTBuilder constructs a PatchTST computation graph from a signal config and compute engine. This allows callers to supply their own graph builder without creating a circular import.
type PatchTSTConfig ¶
type PatchTSTConfig struct {
PatchLen int // patch size (e.g., 16)
Stride int // patch stride (e.g., 8)
NumLayers int // transformer encoder depth (e.g., 3)
NumHeads int // attention heads (e.g., 8)
DModel int // model dim (e.g., 128)
Horizon int // prediction horizon H
NumVars int // number of input features D
}
PatchTSTConfig holds configuration for the PatchTST model.
type RegimeConfig ¶
type RegimeConfig struct {
InputDim int // number of input features per timestep
HiddenDim int // GRU hidden size (e.g., 128)
NumLayers int // GRU depth (e.g., 2)
SeqLen int // input sequence length (e.g., 60 days)
NumClasses int // number of regime classes (default: 4)
}
RegimeConfig holds configuration for the regime detection model.
type RegimeDetector ¶
RegimeDetector is a GRU-based regime classification model. It processes sequential input through stacked GRU layers and classifies the final hidden state into one of NumClasses regimes (bull/bear/sideways/volatile).
func BuildRegimeDetector ¶
func BuildRegimeDetector[T tensor.Numeric]( cfg RegimeConfig, engine compute.Engine[T], ops numeric.Arithmetic[T], ) (*RegimeDetector[T], error)
BuildRegimeDetector constructs a regime detection model. The model consists of stacked GRU layers followed by a linear classifier with softmax output producing 4-class probabilities (bull/bear/sideways/volatile).
func (*RegimeDetector[T]) Attributes ¶
func (rd *RegimeDetector[T]) Attributes() map[string]interface{}
Attributes returns the model configuration.
func (*RegimeDetector[T]) Backward ¶
func (rd *RegimeDetector[T]) Backward(_ context.Context, _ types.BackwardMode, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) ([]*tensor.TensorNumeric[T], error)
Backward is not implemented for inference-only use.
func (*RegimeDetector[T]) Forward ¶
func (rd *RegimeDetector[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
Forward runs the regime detection model. Input shape: [batch, seqLen, inputDim] Output shape: [batch, numClasses] with softmax probabilities.
func (*RegimeDetector[T]) OpType ¶
func (rd *RegimeDetector[T]) OpType() string
OpType returns the operation type.
func (*RegimeDetector[T]) OutputShape ¶
func (rd *RegimeDetector[T]) OutputShape() []int
OutputShape returns [batch, numClasses].
func (*RegimeDetector[T]) Parameters ¶
func (rd *RegimeDetector[T]) Parameters() []*graph.Parameter[T]
Parameters returns all trainable parameters.
type TFTConfig ¶
type TFTConfig struct {
NumStaticFeatures int // static covariates (e.g. asset metadata)
NumTemporalFeatures int // time-varying inputs
HiddenDim int // d_model
NumHeads int // attention heads
NumLSTMLayers int // LSTM encoder layers
HorizonLen int // forecast steps H
Quantiles []float32 // e.g. [0.1, 0.5, 0.9]
}
TFTConfig holds configuration for the Temporal Fusion Transformer.
type TimeSeriesSignalConfig ¶
type TimeSeriesSignalConfig struct {
PatchLen int // ts.signal.patch_len
Stride int // ts.signal.stride (defaults to PatchLen if absent)
InputFeatures int // ts.signal.input_features
HiddenDim int // ts.signal.hidden_dim (default 128)
NumHeads int // ts.signal.num_heads (default 8)
NumLayers int // ts.signal.num_layers (default 6)
HorizonLen int // ts.signal.horizon_len (default 1)
}
TimeSeriesSignalConfig holds signal processing parameters loaded from GGUF metadata for time-series models.
func LoadPatchTSTFromGGUF ¶
func LoadPatchTSTFromGGUF[T tensor.Numeric](path string, engine compute.Engine[T], build PatchTSTBuilder[T]) (*graph.Graph[T], TimeSeriesSignalConfig, error)
LoadPatchTSTFromGGUF loads a PatchTST model from a GGUF file. It parses the file header, extracts ts.signal.* metadata, and delegates graph construction to the provided builder function.
func LoadTimeSeriesSignalConfig ¶
func LoadTimeSeriesSignalConfig(meta map[string]interface{}) (TimeSeriesSignalConfig, error)
LoadTimeSeriesSignalConfig extracts TimeSeriesSignalConfig from a GGUF metadata map. Required keys are ts.signal.patch_len and ts.signal.input_features; all others have defaults.