Documentation
¶
Overview ¶
Package core provides core neural network layer implementations.
Package core provides core neural network layer implementations.
Index ¶
- type Bias
- func (b *Bias[T]) Backward(outputGradient *tensor.Tensor[T]) ([]*tensor.Tensor[T], error)
- func (b *Bias[T]) Forward(inputs ...*tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (b *Bias[T]) OutputShape() []int
- func (b *Bias[T]) Parameters() []*graph.Parameter[T]
- func (b *Bias[T]) SetName(name string)
- type Dense
- func (d *Dense[T]) Backward(outputGradient *tensor.Tensor[T]) ([]*tensor.Tensor[T], error)
- func (d *Dense[T]) Forward(inputs ...*tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (d *Dense[T]) OutputShape() []int
- func (d *Dense[T]) Parameters() []*graph.Parameter[T]
- func (d *Dense[T]) SetName(name string)
- type Linear
- func NewLinear[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], ...) (*Linear[T], error)
- func NewLinearWithFactories[T tensor.Numeric](name string, engine compute.Engine[T], _ numeric.Arithmetic[T], ...) (*Linear[T], error)
- func NewLinearWithHe[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], ...) (*Linear[T], error)
- func NewLinearWithInitializer[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], ...) (*Linear[T], error)
- func NewLinearWithUniform[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], ...) (*Linear[T], error)
- func NewLinearWithXavier[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], ...) (*Linear[T], error)
- func (l *Linear[T]) Backward(outputGradient *tensor.Tensor[T]) ([]*tensor.Tensor[T], error)
- func (l *Linear[T]) Forward(inputs ...*tensor.Tensor[T]) (*tensor.Tensor[T], error)
- func (l *Linear[T]) OutputShape() []int
- func (l *Linear[T]) Parameters() []*graph.Parameter[T]
- func (l *Linear[T]) SetName(name string)
- type PolynomialExpansion
- func (p *PolynomialExpansion[T]) Backward(outputGradient *tensor.Tensor[T]) []*tensor.Tensor[T]
- func (p *PolynomialExpansion[T]) Forward(inputs ...*tensor.Tensor[T]) *tensor.Tensor[T]
- func (p *PolynomialExpansion[T]) GetDegree() int
- func (p *PolynomialExpansion[T]) GetInputSize() int
- func (p *PolynomialExpansion[T]) GetOutputSize() int
- func (p *PolynomialExpansion[T]) GetTermIndices() [][]int
- func (p *PolynomialExpansion[T]) HasBias() bool
- func (p *PolynomialExpansion[T]) OutputShape() []int
- func (p *PolynomialExpansion[T]) Parameters() []*tensor.Tensor[T]
- func (p *PolynomialExpansion[T]) SetName(_ string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bias ¶
Bias adds a bias vector to its input.
func NewBias ¶
func NewBias[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], size int) (*Bias[T], error)
NewBias creates a new Bias layer with default tensor and parameter creation.
func NewBiasWithFactories ¶
func NewBiasWithFactories[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], size int, newTensor func([]int, []T) (*tensor.Tensor[T], error), newParameter func(string, *tensor.Tensor[T], func([]int, []T) (*tensor.Tensor[T], error)) (*graph.Parameter[T], error)) (*Bias[T], error)
NewBiasWithFactories creates a new Bias layer with custom tensor and parameter creation functions.
func (*Bias[T]) OutputShape ¶
OutputShape returns the output shape of the Bias layer.
func (*Bias[T]) Parameters ¶
Parameters returns the parameters of the Bias layer.
type Dense ¶
Dense is a fully connected layer that combines a linear transformation and a bias.
func NewDense ¶
func NewDense[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int) (*Dense[T], error)
NewDense creates a new Dense layer.
func (*Dense[T]) OutputShape ¶
OutputShape returns the output shape of the Dense layer.
func (*Dense[T]) Parameters ¶
Parameters returns the parameters of the Dense layer.
type Linear ¶
Linear performs a linear transformation: output = input * weights. Uses component-based architecture for better modularity and testability.
func NewLinear ¶
func NewLinear[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int) (*Linear[T], error)
NewLinear creates a new Linear layer with Xavier initialization (default).
func NewLinearWithFactories ¶
func NewLinearWithFactories[T tensor.Numeric](name string, engine compute.Engine[T], _ numeric.Arithmetic[T], inputSize, outputSize int, initializer components.WeightInitializer[T], newTensor func([]int, []T) (*tensor.Tensor[T], error), newParameter func(string, *tensor.Tensor[T], func([]int, []T) (*tensor.Tensor[T], error)) (*graph.Parameter[T], error)) (*Linear[T], error)
NewLinearWithFactories creates a new Linear layer with custom tensor and parameter creation functions.
func NewLinearWithHe ¶
func NewLinearWithHe[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int) (*Linear[T], error)
NewLinearWithHe creates a Linear layer with He initialization.
func NewLinearWithInitializer ¶
func NewLinearWithInitializer[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int, initializer components.WeightInitializer[T]) (*Linear[T], error)
NewLinearWithInitializer creates a Linear layer with a custom weight initializer.
func NewLinearWithUniform ¶
func NewLinearWithUniform[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int, scale float64) (*Linear[T], error)
NewLinearWithUniform creates a Linear layer with uniform initialization.
func NewLinearWithXavier ¶
func NewLinearWithXavier[T tensor.Numeric](name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize, outputSize int) (*Linear[T], error)
NewLinearWithXavier creates a Linear layer with Xavier initialization.
func (*Linear[T]) OutputShape ¶
OutputShape returns the output shape of the Linear layer.
func (*Linear[T]) Parameters ¶
Parameters returns the parameters of the Linear layer.
type PolynomialExpansion ¶
PolynomialExpansion layer transforms input features into polynomial combinations up to a specified degree. This is useful for capturing non-linear relationships in data through feature engineering.
For input [x1, x2] with degree 2, it generates: [1, x1, x2, x1^2, x1*x2, x2^2]
The layer supports: - Configurable polynomial degree - Optional bias term (constant 1) - Interaction terms between features - Efficient computation using tensor operations.
func NewPolynomialExpansion ¶
func NewPolynomialExpansion[T tensor.Numeric]( name string, engine compute.Engine[T], ops numeric.Arithmetic[T], inputSize int, degree int, includeBias bool, ) (*PolynomialExpansion[T], error)
NewPolynomialExpansion creates a new polynomial expansion layer.
Parameters: - name: layer name (currently not used but kept for consistency) - engine: compute engine for tensor operations - ops: arithmetic operations for the numeric type - inputSize: number of input features - degree: maximum polynomial degree (must be >= 1) - includeBias: whether to include a bias term (constant 1)
Returns the polynomial expansion layer or an error if parameters are invalid.
func (*PolynomialExpansion[T]) Backward ¶
func (p *PolynomialExpansion[T]) Backward(outputGradient *tensor.Tensor[T]) []*tensor.Tensor[T]
Backward computes gradients for the polynomial expansion layer. This computes the derivative of each polynomial term with respect to the input features.
func (*PolynomialExpansion[T]) Forward ¶
func (p *PolynomialExpansion[T]) Forward(inputs ...*tensor.Tensor[T]) *tensor.Tensor[T]
Forward performs the polynomial expansion transformation. Input shape: [batch_size, input_size] Output shape: [batch_size, output_size].
func (*PolynomialExpansion[T]) GetDegree ¶
func (p *PolynomialExpansion[T]) GetDegree() int
GetDegree returns the polynomial degree of the layer.
func (*PolynomialExpansion[T]) GetInputSize ¶
func (p *PolynomialExpansion[T]) GetInputSize() int
GetInputSize returns the input size of the layer.
func (*PolynomialExpansion[T]) GetOutputSize ¶
func (p *PolynomialExpansion[T]) GetOutputSize() int
GetOutputSize returns the output size of the layer.
func (*PolynomialExpansion[T]) GetTermIndices ¶
func (p *PolynomialExpansion[T]) GetTermIndices() [][]int
GetTermIndices returns the polynomial term indices for inspection/debugging.
func (*PolynomialExpansion[T]) HasBias ¶
func (p *PolynomialExpansion[T]) HasBias() bool
HasBias returns whether the layer includes a bias term.
func (*PolynomialExpansion[T]) OutputShape ¶
func (p *PolynomialExpansion[T]) OutputShape() []int
OutputShape returns the shape of the output tensor.
func (*PolynomialExpansion[T]) Parameters ¶
func (p *PolynomialExpansion[T]) Parameters() []*tensor.Tensor[T]
Parameters returns the parameters of the layer. Polynomial expansion has no trainable parameters.
func (*PolynomialExpansion[T]) SetName ¶
func (p *PolynomialExpansion[T]) SetName(_ string)
SetName sets the name of the layer (for consistency with other layers). SetName sets the name of the layer (for consistency with other layers).