components

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package components provides reusable components for neural network layers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeInitializer

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

HeInitializer implements He initialization. Weights are sampled from a normal distribution with variance 2/fan_in.

func NewHeInitializer

func NewHeInitializer[T tensor.Numeric](ops numeric.Arithmetic[T], opts ...HeInitializerOption[T]) *HeInitializer[T]

NewHeInitializer creates a new He initializer.

func (*HeInitializer[T]) Initialize

func (h *HeInitializer[T]) Initialize(inputSize, outputSize int) ([]T, error)

Initialize generates weights using He initialization.

type HeInitializerOption added in v0.3.0

type HeInitializerOption[T tensor.Numeric] func(*HeInitializerOptions[T])

HeInitializerOption is a function that applies an option to HeInitializerOptions.

type HeInitializerOptions added in v0.3.0

type HeInitializerOptions[T tensor.Numeric] struct {
}

HeInitializerOptions holds configuration options for HeInitializer.

type LinearGradientComputer

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

LinearGradientComputer handles gradient computation for linear layers.

func NewLinearGradientComputer

func NewLinearGradientComputer[T tensor.Numeric](engine compute.Engine[T], opts ...LinearGradientComputerOption[T]) *LinearGradientComputer[T]

NewLinearGradientComputer creates a new linear gradient computer.

func (*LinearGradientComputer[T]) ComputeBothGradients

func (g *LinearGradientComputer[T]) ComputeBothGradients(ctx context.Context, input, weights, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], *tensor.TensorNumeric[T], error)

ComputeBothGradients computes both weight and input gradients in one call. This can be more efficient when both gradients are needed.

func (*LinearGradientComputer[T]) ComputeInputGradient

func (g *LinearGradientComputer[T]) ComputeInputGradient(ctx context.Context, weights, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

ComputeInputGradient computes the gradient with respect to input. Formula: input_gradient = output_gradient * weights^T.

func (*LinearGradientComputer[T]) ComputeWeightGradient

func (g *LinearGradientComputer[T]) ComputeWeightGradient(ctx context.Context, input, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

ComputeWeightGradient computes the gradient with respect to weights. Formula: weight_gradient = input^T * output_gradient.

type LinearGradientComputerOption added in v0.3.0

type LinearGradientComputerOption[T tensor.Numeric] func(*LinearGradientComputerOptions[T])

LinearGradientComputerOption applies an option to LinearGradientComputerOptions.

type LinearGradientComputerOptions added in v0.3.0

type LinearGradientComputerOptions[T tensor.Numeric] struct {
}

LinearGradientComputerOptions holds configuration options for LinearGradientComputer.

type MatrixMultiplier

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

MatrixMultiplier handles matrix multiplication operations for layers.

func NewMatrixMultiplier

func NewMatrixMultiplier[T tensor.Numeric](engine compute.Engine[T], opts ...MatrixMultiplierOption[T]) *MatrixMultiplier[T]

NewMatrixMultiplier creates a new matrix multiplier.

func (*MatrixMultiplier[T]) Multiply

func (m *MatrixMultiplier[T]) Multiply(ctx context.Context, a, b *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Multiply performs matrix multiplication: result = a * b.

func (*MatrixMultiplier[T]) MultiplyWithDestination

func (m *MatrixMultiplier[T]) MultiplyWithDestination(ctx context.Context, a, b, dst *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

MultiplyWithDestination performs matrix multiplication with a pre-allocated destination tensor.

func (*MatrixMultiplier[T]) Transpose

func (m *MatrixMultiplier[T]) Transpose(ctx context.Context, a *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Transpose transposes a matrix.

func (*MatrixMultiplier[T]) TransposeWithDestination

func (m *MatrixMultiplier[T]) TransposeWithDestination(ctx context.Context, a, dst *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

TransposeWithDestination transposes a matrix with a pre-allocated destination tensor.

type MatrixMultiplierOption added in v0.3.0

type MatrixMultiplierOption[T tensor.Numeric] func(*MatrixMultiplierOptions[T])

MatrixMultiplierOption applies an option to MatrixMultiplierOptions.

type MatrixMultiplierOptions added in v0.3.0

type MatrixMultiplierOptions[T tensor.Numeric] struct {
}

MatrixMultiplierOptions represents configuration options for MatrixMultiplier.

type UniformInitializer

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

UniformInitializer implements simple uniform initialization.

func NewUniformInitializer

func NewUniformInitializer[T tensor.Numeric](ops numeric.Arithmetic[T], opts ...UniformInitializerOption[T]) *UniformInitializer[T]

NewUniformInitializer creates a new uniform initializer with the given scale.

func (*UniformInitializer[T]) Initialize

func (u *UniformInitializer[T]) Initialize(inputSize, outputSize int) ([]T, error)

Initialize generates weights using uniform initialization.

type UniformInitializerOption added in v0.3.0

type UniformInitializerOption[T tensor.Numeric] func(*UniformInitializerOptions[T])

UniformInitializerOption is a function that applies an option to UniformInitializerOptions.

func WithScale added in v0.3.0

func WithScale[T tensor.Numeric](scale float64) UniformInitializerOption[T]

WithScale sets the scale parameter for UniformInitializer.

type UniformInitializerOptions added in v0.3.0

type UniformInitializerOptions[T tensor.Numeric] struct {
	Scale float64
}

UniformInitializerOptions holds configuration options for UniformInitializer.

type WeightInitializer

type WeightInitializer[T tensor.Numeric] interface {
	Initialize(inputSize, outputSize int) ([]T, error)
}

WeightInitializer defines the interface for weight initialization strategies.

type XavierInitializer

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

XavierInitializer implements Xavier/Glorot initialization. Weights are sampled from a uniform distribution with variance 2/(fan_in + fan_out).

func NewXavierInitializer

func NewXavierInitializer[T tensor.Numeric](ops numeric.Arithmetic[T], opts ...XavierInitializerOption[T]) *XavierInitializer[T]

NewXavierInitializer creates a new Xavier initializer.

func (*XavierInitializer[T]) Initialize

func (x *XavierInitializer[T]) Initialize(inputSize, outputSize int) ([]T, error)

Initialize generates weights using Xavier initialization.

type XavierInitializerOption added in v0.3.0

type XavierInitializerOption[T tensor.Numeric] func(*XavierInitializerOptions[T])

XavierInitializerOption is a function that applies an option to XavierInitializerOptions.

type XavierInitializerOptions added in v0.3.0

type XavierInitializerOptions[T tensor.Numeric] struct {
}

XavierInitializerOptions holds configuration options for XavierInitializer.

Jump to

Keyboard shortcuts

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