timeseries

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package timeseries provides time-series specific neural network layers.

Stability: alpha

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRN

type GRN[T tensor.Numeric] struct {
	// contains filtered or unexported fields
}

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

func (g *GRN[T]) Parameters() []*graph.Parameter[T]

Parameters returns the trainable parameters.

type PatchEmbed

type PatchEmbed[T tensor.Numeric] struct {
	// contains filtered or unexported fields
}

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

type VSN[T tensor.Numeric] struct {
	// contains filtered or unexported fields
}

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

func (v *VSN[T]) Attributes() map[string]interface{}

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]) Name

func (v *VSN[T]) Name() string

Name returns the name of the layer.

func (*VSN[T]) OpType

func (v *VSN[T]) OpType() string

OpType returns the operation type of the layer.

func (*VSN[T]) OutputShape

func (v *VSN[T]) OutputShape() []int

OutputShape returns the output shape of the layer.

func (*VSN[T]) Parameters

func (v *VSN[T]) Parameters() []*graph.Parameter[T]

Parameters returns the trainable parameters.

func (*VSN[T]) SetName

func (v *VSN[T]) SetName(name string)

SetName sets the name of the layer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL