Documentation
¶
Overview ¶
Package components provides reusable components for neural network layers.
Index ¶
- type HeInitializer
- type HeInitializerOption
- type HeInitializerOptions
- type LinearGradientComputer
- func (g *LinearGradientComputer[T]) ComputeBothGradients(ctx context.Context, input, weights, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], *tensor.TensorNumeric[T], error)
- func (g *LinearGradientComputer[T]) ComputeInputGradient(ctx context.Context, weights, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (g *LinearGradientComputer[T]) ComputeWeightGradient(ctx context.Context, input, outputGradient *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- type LinearGradientComputerOption
- type LinearGradientComputerOptions
- type MatrixMultiplier
- func (m *MatrixMultiplier[T]) Multiply(ctx context.Context, a, b *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (m *MatrixMultiplier[T]) MultiplyWithDestination(ctx context.Context, a, b, dst *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (m *MatrixMultiplier[T]) Transpose(ctx context.Context, a *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- func (m *MatrixMultiplier[T]) TransposeWithDestination(ctx context.Context, a, dst *tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)
- type MatrixMultiplierOption
- type MatrixMultiplierOptions
- type UniformInitializer
- type UniformInitializerOption
- type UniformInitializerOptions
- type WeightInitializer
- type XavierInitializer
- type XavierInitializerOption
- type XavierInitializerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HeInitializer ¶
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
HeInitializerOptions holds configuration options for HeInitializer.
type LinearGradientComputer ¶
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
LinearGradientComputerOptions holds configuration options for LinearGradientComputer.
type MatrixMultiplier ¶
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
MatrixMultiplierOptions represents configuration options for MatrixMultiplier.
type UniformInitializer ¶
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.
type UniformInitializerOptions ¶ added in v0.3.0
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 ¶
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
XavierInitializerOptions holds configuration options for XavierInitializer.