components

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 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]) *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

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

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

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], 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

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]) *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.

Jump to

Keyboard shortcuts

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