crossasset

package
v1.37.0 Latest Latest
Warning

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

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

Documentation

Overview

Experimental — this package is not yet wired into the main framework.

Package crossasset provides a cross-attention model for multi-source feature processing. Each source attends to features of all other sources via scaled dot-product multi-head attention, enabling the model to learn inter-source dependencies. This is useful for scenarios where multiple correlated data sources (e.g., different financial instruments or sensor streams) must be jointly analyzed.

The model architecture applies cross-attention layers where each source computes queries from its own features and keys/values from all sources' features. Layer normalization and residual connections stabilize training.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NSources          int
	FeaturesPerSource int
	DModel            int
	NHeads            int
	NLayers           int
	DropoutRate       float64
	LearningRate      float64
}

Config holds the configuration for a cross-asset attention model.

type Direction

type Direction int

Direction represents a trading signal direction.

const (
	// Long indicates a buy signal.
	Long Direction = iota
	// Short indicates a sell signal.
	Short
	// Flat indicates no signal.
	Flat
)

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model implements a cross-attention model for multi-source features.

func NewModel

func NewModel(config Config) *Model

NewModel creates a new cross-asset attention model with the given configuration.

func (*Model) AttentionWeights

func (m *Model) AttentionWeights(features [][]float64) ([][]float64, error)

AttentionWeights computes the attention weight matrix showing how much each source attends to each other source. Returns [n_sources][n_sources] where result[i][j] is how much source i attends to source j. Weights sum to 1 across the attended (j) dimension.

func (*Model) Forward

func (m *Model) Forward(features [][]float64) ([][]float64, error)

Forward processes features through the cross-attention model. features shape: [n_sources][features_per_source]. Returns: [n_sources][d_model].

func (*Model) Predict

func (m *Model) Predict(features [][]float64) ([]int, []float64, error)

Predict returns per-source direction and confidence. features shape: [n_sources][features_per_source]. Returns: directions [n_sources], confidences [n_sources].

func (*Model) Train

func (m *Model) Train(data [][][]float64, labels [][]int, tc TrainConfig) error

Train trains the model on the given data. data shape: [n_samples][n_sources][features_per_source]. labels shape: [n_samples][n_sources] with values in {0=Long, 1=Short, 2=Flat}.

type TrainConfig

type TrainConfig struct {
	Epochs       int
	BatchSize    int
	LearningRate float64
}

TrainConfig holds training hyperparameters.

Jump to

Keyboard shortcuts

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