Documentation
¶
Overview ¶
Package timeseries provides time-series specific neural network layers.
Stability: alpha
Index ¶
- type GRN
- type PatchEmbed
- func (pe *PatchEmbed[T]) Attributes() map[string]interface{}
- func (pe *PatchEmbed[T]) Backward(ctx context.Context, mode types.BackwardMode, ...) ([]*tensor.TensorNumeric[T], error)
- func (pe *PatchEmbed[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (pe *PatchEmbed[T]) Name() string
- func (pe *PatchEmbed[T]) OpType() string
- func (pe *PatchEmbed[T]) OutputShape() []int
- func (pe *PatchEmbed[T]) Parameters() []*graph.Parameter[T]
- func (pe *PatchEmbed[T]) SetName(name string)
- type VSN
- func (v *VSN[T]) Attributes() map[string]interface{}
- func (v *VSN[T]) Backward(ctx context.Context, mode types.BackwardMode, ...) ([]*tensor.TensorNumeric[T], error)
- func (v *VSN[T]) Forward(ctx context.Context, inputs []*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], []float32, error)
- func (v *VSN[T]) Name() string
- func (v *VSN[T]) OpType() string
- func (v *VSN[T]) OutputShape() []int
- func (v *VSN[T]) Parameters() []*graph.Parameter[T]
- func (v *VSN[T]) SetName(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GRN ¶
GRN implements a Gated Residual Network:
GRN(x) = LayerNorm(x + ELU(W1*x + b1) * sigmoid(W2*x + b2))
where LayerNorm is approximated as mean-subtraction and variance-normalization.
func NewGRN ¶
func NewGRN[T tensor.Numeric]( name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputDim, hiddenDim, outputDim int, ) (*GRN[T], error)
NewGRN creates a new Gated Residual Network layer.
func (*GRN[T]) Forward ¶
func (g *GRN[T]) Forward(ctx context.Context, x *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
Forward computes GRN(x) = LayerNorm(residual + ELU(W1*x + b1) * sigmoid(W2*x + b2)) projected through wOut to outputDim. Input x: [batch, inputDim]. Output: [batch, outputDim].
func (*GRN[T]) Parameters ¶
Parameters returns the trainable parameters.
type PatchEmbed ¶
PatchEmbed splits a 1D time series into non-overlapping patches and projects each patch to embed_dim using a learned linear projection.
func NewPatchEmbed ¶
func NewPatchEmbed[T tensor.Numeric]( name string, engine compute.Engine[T], ops numeric.Arithmetic[T], patchSize, embedDim int, ) (*PatchEmbed[T], error)
NewPatchEmbed creates a new PatchEmbed layer.
func (*PatchEmbed[T]) Attributes ¶
func (pe *PatchEmbed[T]) Attributes() map[string]interface{}
Attributes returns the attributes of the layer.
func (*PatchEmbed[T]) Backward ¶
func (pe *PatchEmbed[T]) Backward(ctx context.Context, mode types.BackwardMode, outputGradient *tensor.TensorNumeric[T], inputs ...*tensor.TensorNumeric[T]) ([]*tensor.TensorNumeric[T], error)
Backward computes the gradients for the patch embedding layer.
func (*PatchEmbed[T]) Forward ¶
func (pe *PatchEmbed[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
Forward takes [batch, seq_len] input and returns [batch, num_patches, embed_dim]. seq_len is padded with zeros if not divisible by PatchSize.
func (*PatchEmbed[T]) Name ¶
func (pe *PatchEmbed[T]) Name() string
Name returns the name of the layer.
func (*PatchEmbed[T]) OpType ¶
func (pe *PatchEmbed[T]) OpType() string
OpType returns the operation type of the layer.
func (*PatchEmbed[T]) OutputShape ¶
func (pe *PatchEmbed[T]) OutputShape() []int
OutputShape returns the output shape of the layer.
func (*PatchEmbed[T]) Parameters ¶
func (pe *PatchEmbed[T]) Parameters() []*graph.Parameter[T]
Parameters returns the trainable parameters.
func (*PatchEmbed[T]) SetName ¶
func (pe *PatchEmbed[T]) SetName(name string)
SetName sets the name of the layer.
type VSN ¶
VSN implements a Variable Selection Network for the Temporal Fusion Transformer.
Each of N input variables is projected to d_model via a learned linear projection. The flat concatenation of all variable embeddings is passed through a GRN and softmax to produce N importance weights. The output is the weighted sum of the variable embeddings.
func NewVSN ¶
func NewVSN[T tensor.Numeric]( name string, engine compute.Engine[T], ops numeric.Arithmetic[T], numVars, varInputDim, dModel int, ) (*VSN[T], error)
NewVSN creates a new Variable Selection Network. numVars is the number of input variables. varInputDim is the input dimension of each variable. dModel is the projection/output dimension.
func (*VSN[T]) Attributes ¶
Attributes returns the attributes of the layer.
func (*VSN[T]) Backward ¶
func (v *VSN[T]) Backward(ctx context.Context, mode types.BackwardMode, outputGradient *tensor.TensorNumeric[T], inputs ...*tensor.TensorNumeric[T]) ([]*tensor.TensorNumeric[T], error)
Backward computes gradients for the VSN layer.
func (*VSN[T]) Forward ¶
func (v *VSN[T]) Forward(ctx context.Context, inputs []*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], []float32, error)
Forward computes the variable selection network. inputs is a slice of N tensors, each [batch, varInputDim]. Returns (weighted_embedding [batch, dModel], importance_weights [numVars], error).
func (*VSN[T]) OutputShape ¶
OutputShape returns the output shape of the layer.
func (*VSN[T]) Parameters ¶
Parameters returns the trainable parameters.