nncore

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TanhActivation    ActivationType = "tanh"
	SigmoidActivation ActivationType = "sigmoid"
	EluActivation     ActivationType = "elu"
	ReLUActivation    ActivationType = "relu"

	ModeRegression ModeType = "regression" // linear output with mse loss
	ModeMultiClass ModeType = "multiclass" // softmax output with cross entropy loss
	ModeMultiLabel ModeType = "multilabel" // sigmoid output with binary cross entropy loss
)

Variables

This section is empty.

Functions

func ApplyDropoutMask

func ApplyDropoutMask(a *mat.Dense, mask []bool, p float64)

inverted dropout: during training, surviving activations are scaled by 1/(1-p) so that no scaling is required during inference.

func BinaryCrossEntropy

func BinaryCrossEntropy(y_hat, y *mat.Dense, parameters map[string]*mat.Dense, lambd float64) float64

computing the binary cross entropy loss function

func CrossEntropy

func CrossEntropy(y_hat, y *mat.Dense, parameters map[string]*mat.Dense, lambd float64) float64

computing the cross entropy loss function

func DropoutMask

func DropoutMask(a *mat.Dense, p float64) []bool

creates a binary mask for inverted dropout. each element has probability (1-p) of being kept.

func Elu

func Elu(a *mat.Dense) *mat.Dense

implements the elu function for use in activation functions.

func EluDerivative

func EluDerivative(a *mat.Dense) *mat.Dense

implements the derivative of the elu function for backpropagation.

func Linear

func Linear(a *mat.Dense) *mat.Dense

applies linear function for output layer

func MeanSquaredError

func MeanSquaredError(yHat, y *mat.Dense, parameters map[string]*mat.Dense, lambd float64) float64

computing the mean squared error loss function

func ReLU

func ReLU(a *mat.Dense) *mat.Dense

implements the relu function for use in activation functions.

func ReLUDerivative

func ReLUDerivative(a *mat.Dense) *mat.Dense

implements the derivative of the relu function for backpropagation.

func Sigmoid

func Sigmoid(a *mat.Dense) *mat.Dense

implements the sigmoid function for use in activation functions.

func SigmoidDerivative

func SigmoidDerivative(a *mat.Dense) *mat.Dense

implements the derivative of the sigmoid function for backpropagation.

func SigmoidScalar

func SigmoidScalar(x float64) float64

implements the sigmoid function for use in activation functions.

func Softmax

func Softmax(a *mat.Dense) *mat.Dense

applies softmax function for output layer

func Tanh

func Tanh(a *mat.Dense) *mat.Dense

implements the Tanh function for use in activation functions.

func TanhDerivative

func TanhDerivative(a *mat.Dense) *mat.Dense

implements the derivative of the Tanh function for backpropagation.

Types

type Activation

type Activation struct {
	Name       ActivationType
	Function   ActivationFunction
	Derivative ActivationFunction
}

func NewActivation

func NewActivation(actType ActivationType) Activation

type ActivationFunction

type ActivationFunction func(*mat.Dense) *mat.Dense

type ActivationType

type ActivationType string

type Dense

type Dense struct {
	Activation       Activation
	OutputActivation OutputActivation
	Optimizer        Optimizer
	Parameters       map[string]*mat.Dense
	Iter             float64
	L2Regularization float64
	Dropout          float64
}

func NewDense

func NewDense(config DenseConfig) *Dense

func (*Dense) BackwardPropagation

func (dn *Dense) BackwardPropagation(Z, A map[string]*mat.Dense, D map[string][]bool, y *mat.Dense) (*mat.Dense, map[string]*mat.Dense, map[string]*mat.Dense)

backward propagation step

func (*Dense) ForwardPropagation

func (dn *Dense) ForwardPropagation(x *mat.Dense, training bool) (*mat.Dense, map[string]*mat.Dense, map[string]*mat.Dense, map[string][]bool)

forward propagation step

func (*Dense) MarshalParameters

func (dn *Dense) MarshalParameters() ([]byte, error)

func (*Dense) TrainableParameters

func (dn *Dense) TrainableParameters(dW, db map[string]*mat.Dense) []*Parameter

func (*Dense) UnmarshalParameters

func (dn *Dense) UnmarshalParameters(data []byte) error

func (*Dense) UpdateParameters

func (dn *Dense) UpdateParameters(dW, db map[string]*mat.Dense, learningRate float64)

update parameters (optimization algorithm)

type DenseConfig

type DenseConfig struct {
	NNStructure      []int
	Activation       Activation
	OutputActivation OutputActivation
	Optimizer        OptimizerType
}

type LossFunction

type LossFunction func(*mat.Dense, *mat.Dense, map[string]*mat.Dense, float64) float64

type Mode

type Mode struct {
	OutputActivation OutputActivation
	LossFunction     LossFunction
}

func NewMode

func NewMode(mode ModeType) Mode

type ModeType

type ModeType string

type Optimizer

type Optimizer interface {
	Name() OptimizerType
	Step(parameters []*Parameter, learningRate, t float64)

	MarshalState() ([]byte, error)
	UnmarshalState([]byte) error
}

func NewOptimizer

func NewOptimizer(optType OptimizerType) Optimizer

type OptimizerType

type OptimizerType string
const (
	AdamOptimizer            OptimizerType = "adam"
	GradientDescentOptimizer OptimizerType = "gradientdescent"
)

type OutputActivation

type OutputActivation struct {
	Mode     ModeType
	Function OutputActivationFunction
}

type OutputActivationFunction

type OutputActivationFunction func(*mat.Dense) *mat.Dense

type Parameter

type Parameter struct {
	Value    *mat.Dense
	Gradient *mat.Dense
	Update   func(*mat.Dense) // callback function to update the source parameter
}

Jump to

Keyboard shortcuts

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