Documentation
¶
Overview ¶
Package components provides reusable components for neural network layers.
Index ¶
- type HeInitializer
- type LinearGradientComputer
- func (g *LinearGradientComputer[T]) ComputeBothGradients(ctx context.Context, input, weights, outputGradient *tensor.Tensor[T]) (*tensor.Tensor[T], *tensor.Tensor[T], error)
- func (g *LinearGradientComputer[T]) ComputeInputGradient(ctx context.Context, weights, outputGradient *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (g *LinearGradientComputer[T]) ComputeWeightGradient(ctx context.Context, input, outputGradient *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- type MatrixMultiplier
- func (m *MatrixMultiplier[T]) Multiply(ctx context.Context, a, b *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (m *MatrixMultiplier[T]) MultiplyWithDestination(ctx context.Context, a, b, dst *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (m *MatrixMultiplier[T]) Transpose(ctx context.Context, a *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (m *MatrixMultiplier[T]) TransposeWithDestination(ctx context.Context, a, dst *tensor.Tensor[T]) (*tensor.Tensor[T], error)
- type UniformInitializer
- type WeightInitializer
- type XavierInitializer
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]) *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 LinearGradientComputer ¶
LinearGradientComputer handles gradient computation for linear layers.
func NewLinearGradientComputer ¶
func NewLinearGradientComputer[T tensor.Numeric](engine compute.Engine[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.Tensor[T]) (*tensor.Tensor[T], *tensor.Tensor[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.Tensor[T]) (*tensor.Tensor[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.Tensor[T]) (*tensor.Tensor[T], error)
ComputeWeightGradient computes the gradient with respect to weights. Formula: weight_gradient = input^T * output_gradient.
type MatrixMultiplier ¶
MatrixMultiplier handles matrix multiplication operations for layers.
func NewMatrixMultiplier ¶
func NewMatrixMultiplier[T tensor.Numeric](engine compute.Engine[T]) *MatrixMultiplier[T]
NewMatrixMultiplier creates a new matrix multiplier.
func (*MatrixMultiplier[T]) Multiply ¶
func (m *MatrixMultiplier[T]) Multiply(ctx context.Context, a, b *tensor.Tensor[T]) (*tensor.Tensor[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.Tensor[T]) (*tensor.Tensor[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.Tensor[T]) (*tensor.Tensor[T], error)
Transpose transposes a matrix.
func (*MatrixMultiplier[T]) TransposeWithDestination ¶
func (m *MatrixMultiplier[T]) TransposeWithDestination(ctx context.Context, a, dst *tensor.Tensor[T]) (*tensor.Tensor[T], error)
TransposeWithDestination transposes a matrix with a pre-allocated destination tensor.
type UniformInitializer ¶
UniformInitializer implements simple uniform initialization.
func NewUniformInitializer ¶
func NewUniformInitializer[T tensor.Numeric](ops numeric.Arithmetic[T], scale float64) *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 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]) *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.