gradfn

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Abs

type Abs[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Abs is an operator to perform element-wise absolute value function.

func NewAbs

func NewAbs[O mat.Tensor](x O) *Abs[O]

NewAbs returns a new UnaryElementwise absolute value function.

type Add

type Add[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Add is an operator to perform element-wise sum over two values. y = x1 + x2

func NewAdd

func NewAdd[O mat.Tensor](x1, x2 O) *Add[O]

NewAdd returns a new Add Function.

func (*Add[O]) Backward

func (r *Add[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Add[O]) Forward

func (r *Add[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Add[O]) Operands

func (r *Add[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type AddScalar

type AddScalar[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

AddScalar is an operator to perform element-wise addition over two values.

func NewAddScalar

func NewAddScalar[O mat.Tensor](x1, x2 O) *AddScalar[O]

NewAddScalar returns a new AddScalar Function.

func (*AddScalar[O]) Backward

func (r *AddScalar[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*AddScalar[O]) Forward

func (r *AddScalar[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function. It doesn't backward on the scalar value x2.

func (*AddScalar[O]) Operands

func (r *AddScalar[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Affine

type Affine[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Affine is an operator to apply the affine function y = b + W1x1 + W2x2 + ... + WnXn.

func NewAffine

func NewAffine[O mat.Tensor](b, w1, x1 O, wxPairs ...O) *Affine[O]

NewAffine returns a new Affine Function.

The affine transformation is in the form y = b + W1x1 + W2x2 + ... + WnXn. The function accepts the bias "b", the first mandatory pair of "w1" and "x1", and then an optional arbitrary list of (w, x) pairs, that is "w2", "x2", "w3", "x3", ..., "wN", "xN".

For each additional pair (w, x), x is allowed to be nil. In this case, the pair is completely ignored. For example, given the arguments (b, w1, x1, w2, x2, w3, x3), if only x2 is nil, the actual operation performed will be y = b + w1x1 + w3x3.

If no additional (w, x) pair is given, or all x values of wxPairs are nil, the actual function is just y = b + W1x1.

It panics if the length of wxs is not even.

func (*Affine[O]) Backward

func (a *Affine[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Affine[O]) Forward

func (a *Affine[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Affine[O]) Operands

func (a *Affine[O]) Operands() []O

Operands returns the list of operands.

type AppendRows

type AppendRows[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

AppendRows is a Function which appends new tail rows to a matrix.

func NewAppendRows

func NewAppendRows[O mat.Tensor](x O, vs ...O) *AppendRows[O]

NewAppendRows returns a new AppendRows Function.

func (*AppendRows[O]) Backward

func (a *AppendRows[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*AppendRows[O]) Forward

func (a *AppendRows[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*AppendRows[O]) Operands

func (a *AppendRows[O]) Operands() []O

Operands returns the list of operands.

type At

type At[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

At is an operator to obtain the i,j-th value of a matrix.

func NewAt

func NewAt[O mat.Tensor](x O, indices ...int) *At[O]

NewAt returns a new At Function.

func (*At[O]) Backward

func (r *At[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*At[O]) Forward

func (r *At[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*At[O]) Operands

func (r *At[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type CELU

type CELU[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

CELU is an operator to perform the CELU activation. CELU(x) = max(0,x) + min(0,α ∗ (exp(x/α) − 1))

func NewCELU

func NewCELU[O mat.Tensor](x O, alpha O) *CELU[O]

NewCELU returns a new CELU Function.

func (*CELU[O]) Backward

func (r *CELU[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*CELU[O]) Forward

func (r *CELU[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*CELU[O]) Operands

func (r *CELU[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ColView

type ColView[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ColView is an operator to extract the i-th column from a matrix.

func NewColView

func NewColView[O mat.Tensor](x O, i int) *ColView[O]

NewColView extracts the i-th column from the input matrix.

func (*ColView[O]) Backward

func (r *ColView[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ColView[O]) Forward

func (r *ColView[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*ColView[O]) Operands

func (r *ColView[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Concat

type Concat[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Concat is an operator to perform vector concatenation.

func NewConcat

func NewConcat[O mat.Tensor](xs []O) *Concat[O]

NewConcat returns a new Concat Function.

func (*Concat[O]) Backward

func (r *Concat[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Concat[O]) Forward

func (r *Concat[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Concat[O]) Operands

func (r *Concat[O]) Operands() []O

Operands returns the list of operands.

type Copy

type Copy[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Copy is an operator to perform copy function. y = x

func NewCopy

func NewCopy[O mat.Tensor](x O) *Copy[O]

NewCopy returns a new Copy Function.

func (*Copy[O]) Backward

func (r *Copy[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Copy[O]) Forward

func (r *Copy[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Copy[O]) Operands

func (r *Copy[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Cos

type Cos[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Cos is an operator to perform element-wise cos.

func NewCos

func NewCos[O mat.Tensor](x O) *Cos[O]

NewCos returns a new UnaryElementwise cos function.

type Div

type Div[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Div is an operator to perform element-wise division over two values.

func NewDiv

func NewDiv[O mat.Tensor](x1 O, x2 O) *Div[O]

NewDiv returns a new Div Function.

func (*Div[O]) Backward

func (r *Div[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Div[O]) Forward

func (r *Div[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Div[O]) Operands

func (r *Div[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type DivScalar

type DivScalar[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

DivScalar is an operator to perform element-wise division with a scalar value.

func NewDivScalar

func NewDivScalar[O mat.Tensor](x1 O, x2 O) *DivScalar[O]

NewDivScalar returns a new DivScalar Function.

func (*DivScalar[O]) Backward

func (r *DivScalar[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*DivScalar[O]) Forward

func (r *DivScalar[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*DivScalar[O]) Operands

func (r *DivScalar[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Dot

type Dot[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Dot is an operator to perform the dot product over two matrices. y = x1 dot x2

func NewDot

func NewDot[O mat.Tensor](x1 O, x2 O) *Dot[O]

NewDot returns a new Dot Function.

func (*Dot[O]) Backward

func (r *Dot[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Dot[O]) Forward

func (r *Dot[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Dot[O]) Operands

func (r *Dot[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Dropout

type Dropout[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Dropout is an operator to perform elements dropout with a probability.

func NewDropout

func NewDropout[O mat.Tensor](x O, p float64, randGen *rand.LockedRand) *Dropout[O]

NewDropout returns a new Dropout Function.

func (*Dropout[O]) Backward

func (r *Dropout[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Dropout[O]) Forward

func (r *Dropout[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Dropout[O]) Operands

func (r *Dropout[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ELU

type ELU[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ELU is an operator to perform the ELU activation function. ELU(x) = max(0,x) + min(0,α ∗ (exp(x) − 1))

func NewELU

func NewELU[O mat.Tensor](x O, alpha O) *ELU[O]

NewELU returns a new ELU Function.

func (*ELU[O]) Backward

func (r *ELU[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ELU[O]) Forward

func (r *ELU[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*ELU[O]) Operands

func (r *ELU[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Exp

type Exp[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Exp is an operator to perform element-wise base-e exponential function.

func NewExp

func NewExp[O mat.Tensor](x O) *Exp[O]

NewExp returns a new Exp Function.

func (*Exp[O]) Backward

func (e *Exp[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Exp[O]) Forward

func (e *Exp[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Exp[O]) Operands

func (e *Exp[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Flatten

type Flatten[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Flatten is a Function to reshape a matrix-operand into a "flattened" row vector.

func NewFlatten

func NewFlatten[O mat.Tensor](x O) *Flatten[O]

NewFlatten returns a new Flatten Function.

func (*Flatten[O]) Backward

func (r *Flatten[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Flatten[O]) Forward

func (r *Flatten[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*Flatten[O]) Operands

func (r *Flatten[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type GELU

type GELU[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

GELU is an operator to perform element-wise GELU.

func NewGELU

func NewGELU[O mat.Tensor](x O) *GELU[O]

NewGELU returns a new UnaryElementwise Gaussian Error Linear Unit (GELU) function.

type HardSigmoid

type HardSigmoid[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

HardSigmoid is an operator to perform element-wise hard sigmoid.

func NewHardSigmoid

func NewHardSigmoid[O mat.Tensor](x O) *HardSigmoid[O]

NewHardSigmoid returns a new UnaryElementwise hard sigmoid function.

type HardTanh

type HardTanh[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

HardTanh is an operator to perform element-wise hard hyperbolic tangent.

func NewHardTanh

func NewHardTanh[O mat.Tensor](x O) *HardTanh[O]

NewHardTanh returns a new UnaryElementwise hard hyperbolic tangent function.

type LeakyReLU

type LeakyReLU[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

LeakyReLU is an operator to perform the LeakyReLU activation function. LeakyReLU(x) = max(0,x) + slope ° min(0,x)

func NewLeakyReLU

func NewLeakyReLU[O mat.Tensor](x, alpha O) *LeakyReLU[O]

NewLeakyReLU returns a new LeakyReLU Function.

func (*LeakyReLU[O]) Backward

func (r *LeakyReLU[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*LeakyReLU[O]) Forward

func (r *LeakyReLU[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*LeakyReLU[O]) Operands

func (r *LeakyReLU[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Log

type Log[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Log is an operator to perform element-wise natural logarithm function.

func NewLog

func NewLog[O mat.Tensor](x O) *Log[O]

NewLog returns a new Log Function.

func (*Log[O]) Backward

func (l *Log[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Log[O]) Forward

func (l *Log[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Log[O]) Operands

func (l *Log[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Max

type Max[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Max is an operator to perform element-wise max. y = max(x1, x2)

func NewMax

func NewMax[O mat.Tensor](x1 O, x2 O) *Max[O]

NewMax returns a new Max Function.

func (*Max[O]) Backward

func (r *Max[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Max[O]) Forward

func (r *Max[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Max[O]) Operands

func (r *Max[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type MaxPooling

type MaxPooling[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

MaxPooling is an operator to perform max pooling.

func NewMaxPooling

func NewMaxPooling[O mat.Tensor](x O, r, c int) *MaxPooling[O]

NewMaxPooling returns a new MaxPooling Function.

func (*MaxPooling[O]) Backward

func (r *MaxPooling[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*MaxPooling[O]) Forward

func (r *MaxPooling[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*MaxPooling[O]) Operands

func (r *MaxPooling[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Min

type Min[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Min is an operator to perform element-wise min. y = min(x1, x2)

func NewMin

func NewMin[O mat.Tensor](x1 O, x2 O) *Min[O]

NewMin returns a new Min Function.

func (*Min[O]) Backward

func (r *Min[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Min[O]) Forward

func (r *Min[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Min[O]) Operands

func (r *Min[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Mish

type Mish[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Mish is an operator to perform element-wise mish.

func NewMish

func NewMish[O mat.Tensor](x O) *Mish[O]

NewMish returns a new UnaryElementwise Mish function.

Mish is a self-regularized non-monotonic activation function which can be mathematically defined as f(x) = x * tanh(softplus(x)).

Reference: "Mish: A Self Regularized Non-Monotonic Neural Activation Function" by Diganta Misra, 2019 (https://arxiv.org/pdf/1908.08681.pdf)

type Mul

type Mul[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Mul is an operator to perform matrix-vector multiplication.

func NewMul

func NewMul[O mat.Tensor](x1 O, x2 O) *Mul[O]

NewMul returns a new Mul Function.

func (*Mul[O]) Backward

func (r *Mul[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Mul[O]) Forward

func (r *Mul[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Mul[O]) Operands

func (r *Mul[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type MulT

type MulT[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

MulT is an operator to perform matrix-vector multiplication.

func NewMulT

func NewMulT[O mat.Tensor](x1 O, x2 O) *MulT[O]

NewMulT returns a new MulT Function.

func (*MulT[O]) Backward

func (r *MulT[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*MulT[O]) Forward

func (r *MulT[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*MulT[O]) Operands

func (r *MulT[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Neg

type Neg[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Neg is an operator to perform element-wise f(x) = -x

func NewNeg

func NewNeg[O mat.Tensor](x O) *Neg[O]

NewNeg returns a new UnaryElementwise f(x) = -x function.

type Pow

type Pow[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Pow is an operator to perform element-wise pow function.

func NewPow

func NewPow[O mat.Tensor](x O, power float64) *Pow[O]

NewPow returns a new Pow Function.

func (*Pow[O]) Backward

func (r *Pow[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Pow[O]) Forward

func (r *Pow[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Pow[O]) Operands

func (r *Pow[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Prod

type Prod[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Prod is an operator to perform element-wise product over two values.

func NewProd

func NewProd[O mat.Tensor](x1 O, x2 O) *Prod[O]

NewProd returns a new Prod Function.

func (*Prod[O]) Backward

func (r *Prod[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Prod[O]) Forward

func (r *Prod[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*Prod[O]) Operands

func (r *Prod[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ProdScalar

type ProdScalar[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ProdScalar is an operator to perform element-wise product with a scalar value.

func NewProdScalar

func NewProdScalar[O mat.Tensor](x1 O, x2 O) *ProdScalar[O]

NewProdScalar returns a new ProdScalar Function.

func (*ProdScalar[O]) Backward

func (r *ProdScalar[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ProdScalar[O]) Forward

func (r *ProdScalar[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*ProdScalar[O]) Operands

func (r *ProdScalar[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ReLU

type ReLU[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

ReLU is an operator to perform element-wise Rectified Linear Unit (ReLU)

func NewReLU

func NewReLU[O mat.Tensor](x O) *ReLU[O]

NewReLU returns a new UnaryElementwise Rectified Linear Unit (ReLU) function.

type Reciprocal

type Reciprocal[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Reciprocal is an operator to perform element-wise reciprocal.

func NewReciprocal

func NewReciprocal[O mat.Tensor](x O) *Reciprocal[O]

NewReciprocal returns a new UnaryElementwise reciprocal function.

type ReduceMax

type ReduceMax[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ReduceMax is an operator to perform reduce-max function. It gets the maximum element of the Operand x

func NewReduceMax

func NewReduceMax[O mat.Tensor](x O) *ReduceMax[O]

NewReduceMax returns a new ReduceMax Function.

func (*ReduceMax[O]) Backward

func (r *ReduceMax[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ReduceMax[O]) Forward

func (r *ReduceMax[O]) Forward() (mat.Tensor, error)

Forward computes the output of this function.

func (*ReduceMax[O]) Operands

func (r *ReduceMax[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ReduceMean

type ReduceMean[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ReduceMean is an operator to perform reduce-mean function.

func NewReduceMean

func NewReduceMean[O mat.Tensor](x O) *ReduceMean[O]

NewReduceMean returns a new ReduceMean Function.

func (*ReduceMean[O]) Backward

func (r *ReduceMean[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ReduceMean[O]) Forward

func (r *ReduceMean[O]) Forward() (mat.Tensor, error)

Forward computes the output of this node.

func (*ReduceMean[O]) Operands

func (r *ReduceMean[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ReduceSum

type ReduceSum[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ReduceSum is an operator to perform reduce-sum function.

func NewReduceSum

func NewReduceSum[O mat.Tensor](x O) *ReduceSum[O]

NewReduceSum returns a new ReduceSum Function.

func (*ReduceSum[O]) Backward

func (r *ReduceSum[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ReduceSum[O]) Forward

func (r *ReduceSum[O]) Forward() (mat.Tensor, error)

Forward computes the output of this function.

func (*ReduceSum[O]) Operands

func (r *ReduceSum[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Reshape

type Reshape[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Reshape is a Function which reshapes an operand into a new matrix of given rows × columns size.

func NewReshape

func NewReshape[O mat.Tensor](x O, r, c int) *Reshape[O]

NewReshape returns a new Reshape Function.

func (*Reshape[O]) Backward

func (r *Reshape[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Reshape[O]) Forward

func (r *Reshape[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*Reshape[O]) Operands

func (r *Reshape[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ReverseSubScalar

type ReverseSubScalar[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ReverseSubScalar is the element-wise subtraction function over two values.

func NewReverseSubScalar

func NewReverseSubScalar[O mat.Tensor](x1 O, x2 O) *ReverseSubScalar[O]

NewReverseSubScalar returns a new ReverseSubScalar Function.

func (*ReverseSubScalar[O]) Backward

func (r *ReverseSubScalar[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ReverseSubScalar[O]) Forward

func (r *ReverseSubScalar[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*ReverseSubScalar[O]) Operands

func (r *ReverseSubScalar[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type RotateR

type RotateR[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

RotateR is a function to perform a right circular shift of a vector.

func NewRotateR

func NewRotateR[O mat.Tensor](x O, i int) *RotateR[O]

NewRotateR returns a new RotateR Function. `i` is the number of places by which the elements are shifted.

func (*RotateR[O]) Backward

func (r *RotateR[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*RotateR[O]) Forward

func (r *RotateR[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*RotateR[O]) Operands

func (r *RotateR[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type RowView

type RowView[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

RowView is a function to extract the i-th row from the input matrix.

func NewRowView

func NewRowView[O mat.Tensor](x O, i int) *RowView[O]

NewRowView returns a new RowView Function.

func (*RowView[O]) Backward

func (r *RowView[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*RowView[O]) Forward

func (r *RowView[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*RowView[O]) Operands

func (r *RowView[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SELU

type SELU[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SELU function: f(x) = scale ∗ (max(0,x) + min(0, α ∗ (exp(x) − 1)))

func NewSELU

func NewSELU[O mat.Tensor](x O, alpha, scale O) *SELU[O]

NewSELU returns a new SELU Function.

func (*SELU[O]) Backward

func (r *SELU[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SELU[O]) Forward

func (r *SELU[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SELU[O]) Operands

func (r *SELU[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type ScalarMax

type ScalarMax[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

ScalarMax is an operator to perform reduce-max function on a list of scalars. It gets the maximum element of the Operand x

func NewScalarMax

func NewScalarMax[O mat.Tensor](xs []O) *ScalarMax[O]

NewScalarMax returns a new ScalarMax Function.

func (*ScalarMax[O]) Backward

func (r *ScalarMax[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*ScalarMax[O]) Forward

func (r *ScalarMax[O]) Forward() (mat.Tensor, error)

Forward computes the output of this function.

func (*ScalarMax[O]) Operands

func (r *ScalarMax[O]) Operands() []O

Operands returns the list of operands.

type Sigmoid

type Sigmoid[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Sigmoid is an operator to perform element-wise sigmoid function.

func NewSigmoid

func NewSigmoid[O mat.Tensor](x O) *Sigmoid[O]

NewSigmoid returns a new Log Function.

func (*Sigmoid[O]) Backward

func (l *Sigmoid[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Sigmoid[O]) Forward

func (l *Sigmoid[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Sigmoid[O]) Operands

func (l *Sigmoid[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Sin

type Sin[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Sin is an operator to perform element-wise sin.

func NewSin

func NewSin[O mat.Tensor](x O) *Sin[O]

NewSin returns a new UnaryElementwise sine function.

type Slice

type Slice[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Slice is a function to extract a portion of a matrix.

func NewSlice

func NewSlice[O mat.Tensor](x O, fromRow, fromCol, toRow, toCol int) *Slice[O]

NewSlice returns a new Slice Function.

func (*Slice[O]) Backward

func (s *Slice[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Slice[O]) Forward

func (s *Slice[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Slice[O]) Operands

func (s *Slice[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SoftPlus

type SoftPlus[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SoftPlus function: f(x) = 1 / β ∗ log(1 + exp(β ∗ x))

func NewSoftPlus

func NewSoftPlus[O mat.Tensor](x O, beta, threshold O) *SoftPlus[O]

NewSoftPlus returns a new SoftPlus Function.

func (*SoftPlus[O]) Backward

func (r *SoftPlus[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SoftPlus[O]) Forward

func (r *SoftPlus[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SoftPlus[O]) Operands

func (r *SoftPlus[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SoftShrink

type SoftShrink[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SoftShrink function: f(x) = x − λ if x > λ; x + λ if x < −λ; 0 otherwise.

func NewSoftShrink

func NewSoftShrink[O mat.Tensor](x O, lambda O) *SoftShrink[O]

NewSoftShrink returns a new SoftShrink Function.

func (*SoftShrink[O]) Backward

func (r *SoftShrink[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SoftShrink[O]) Forward

func (r *SoftShrink[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SoftShrink[O]) Operands

func (r *SoftShrink[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Softmax

type Softmax[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Softmax is a single-input softmax function.

func NewSoftmax

func NewSoftmax[O mat.Tensor](x O) *Softmax[O]

NewSoftmax returns a new Softmax Function.

func (*Softmax[O]) Backward

func (r *Softmax[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Softmax[O]) Forward

func (r *Softmax[O]) Forward() (mat.Tensor, error)

Forward computes the output of this function.

func (*Softmax[O]) Operands

func (r *Softmax[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Softsign

type Softsign[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Softsign is an operator to perform element-wise softsign.

func NewSoftsign

func NewSoftsign[O mat.Tensor](x O) *Softsign[O]

NewSoftsign returns a new UnaryElementwise softsign function.

type SparseMax

type SparseMax[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SparseMax function implementation, based on https://github.com/gokceneraslan/SparseMax.torch

func NewSparseMax

func NewSparseMax[O mat.Tensor](x O) *SparseMax[O]

NewSparseMax returns a new SparseMax Function.

func (*SparseMax[O]) Backward

func (r *SparseMax[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SparseMax[O]) Forward

func (r *SparseMax[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SparseMax[O]) Operands

func (r *SparseMax[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SparseMaxLoss

type SparseMaxLoss[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SparseMaxLoss function implementation, based on https://github.com/gokceneraslan/SparseMax.torch

func NewSparseMaxLoss

func NewSparseMaxLoss[O mat.Tensor](x O) *SparseMaxLoss[O]

NewSparseMaxLoss returns a new SparseMaxLoss Function.

func (*SparseMaxLoss[O]) Backward

func (r *SparseMaxLoss[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SparseMaxLoss[O]) Forward

func (r *SparseMaxLoss[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SparseMaxLoss[O]) Operands

func (r *SparseMaxLoss[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Sqrt

type Sqrt[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Sqrt is an operator to perform element-wise square root function.

func NewSqrt

func NewSqrt[O mat.Tensor](x O) *Sqrt[O]

NewSqrt returns a new Sqrt Function.

func (*Sqrt[O]) Backward

func (r *Sqrt[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Sqrt[O]) Forward

func (r *Sqrt[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Sqrt[O]) Operands

func (r *Sqrt[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Square

type Square[O mat.Tensor] struct {
	*Prod[O]
}

Square is an operator to perform element-wise square.

func NewSquare

func NewSquare[O mat.Tensor](x O) *Square[O]

NewSquare returns a new Square Function.

type Stack

type Stack[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Stack is a Function which stacks together all given operand matrices, producing a single bigger matrix as result.

func NewStack

func NewStack[O mat.Tensor](xs []O) *Stack[O]

NewStack returns a new Stack Function.

func (*Stack[O]) Backward

func (r *Stack[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Stack[O]) Forward

func (r *Stack[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Stack[O]) Operands

func (r *Stack[O]) Operands() []O

Operands returns the list of operands.

type Sub

type Sub[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Sub is an element-wise subtraction function over two values.

func NewSub

func NewSub[O mat.Tensor](x1 O, x2 O) *Sub[O]

NewSub returns a new Sub Function.

func (*Sub[O]) Backward

func (r *Sub[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Sub[O]) Forward

func (r *Sub[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*Sub[O]) Operands

func (r *Sub[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SubScalar

type SubScalar[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SubScalar is an element-wise subtraction function with a scalar value.

func NewSubScalar

func NewSubScalar[O mat.Tensor](x1 O, x2 O) *SubScalar[O]

NewSubScalar returns a new SubScalar Function.

func (*SubScalar[O]) Backward

func (r *SubScalar[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SubScalar[O]) Forward

func (r *SubScalar[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*SubScalar[O]) Operands

func (r *SubScalar[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Swish

type Swish[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Swish is an operator to perform element-wise swish function: y = x * sigmoid(x).

func NewSiLU

func NewSiLU[O mat.Tensor](x O) *Swish[O]

NewSiLU (Sigmoid Linear Unit) returns a new function of the form f(x) = x * sigmoid(x). The function in an alias of NewSwish.

func NewSwish

func NewSwish[O mat.Tensor](x O) *Swish[O]

NewSwish returns a new Swish Function.

func (*Swish[O]) Backward

func (l *Swish[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Swish[O]) Forward

func (l *Swish[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Swish[O]) Operands

func (l *Swish[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type SwishB

type SwishB[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

SwishB function: f(x) = x * sigmoid.

Reference: "Searching for Activation Functions" by Ramachandran et al, 2017. (https://arxiv.org/pdf/1710.05941.pdf)

func NewSwishB

func NewSwishB[O mat.Tensor](x O, beta O) *SwishB[O]

NewSwishB returns a new SwishB Function.

func (*SwishB[O]) Backward

func (r *SwishB[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*SwishB[O]) Forward

func (r *SwishB[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*SwishB[O]) Operands

func (r *SwishB[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Tan

type Tan[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Tan is an operator to perform element-wise tangent.

func NewTan

func NewTan[O mat.Tensor](x O) *Tan[O]

NewTan returns a new UnaryElementwise tangent function.

type Tanh

type Tanh[O mat.Tensor] struct {
	*UnaryElementwise[O]
}

Tanh is an operator to perform element-wise hyperbolic tangent.

func NewTanh

func NewTanh[O mat.Tensor](x O) *Tanh[O]

NewTanh returns a new UnaryElementwise hyperbolic tangent function.

type Threshold

type Threshold[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Threshold function: f(x) = x if x > threshold; k otherwise.

func NewThreshold

func NewThreshold[O mat.Tensor](x O, threshold, k O) *Threshold[O]

NewThreshold returns a new Threshold Function.

func (*Threshold[O]) Backward

func (r *Threshold[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Threshold[O]) Forward

func (r *Threshold[O]) Forward() (mat.Tensor, error)

Forward computes the output of the function.

func (*Threshold[O]) Operands

func (r *Threshold[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type Transpose

type Transpose[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

Transpose is a Function to calculate the transpose of the matrix-operand.

func NewTranspose

func NewTranspose[O mat.Tensor](x O) *Transpose[O]

NewTranspose returns a new Transpose Function.

func (*Transpose[O]) Backward

func (r *Transpose[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*Transpose[O]) Forward

func (r *Transpose[O]) Forward() (mat.Tensor, error)

Forward computes the output of the node.

func (*Transpose[O]) Operands

func (r *Transpose[O]) Operands() []mat.Tensor

Operands returns the list of operands.

type UnaryElementwise

type UnaryElementwise[O mat.Tensor] struct {
	// contains filtered or unexported fields
}

UnaryElementwise is a single-input element-wise function.

func (*UnaryElementwise[O]) Backward

func (r *UnaryElementwise[O]) Backward(gy mat.Tensor) error

Backward computes the backward pass.

func (*UnaryElementwise[O]) Forward

func (r *UnaryElementwise[O]) Forward() (mat.Tensor, error)

Forward computes the output of this node.

func (*UnaryElementwise[O]) Operands

func (r *UnaryElementwise[O]) Operands() []mat.Tensor

Operands returns the list of operands.

Jump to

Keyboard shortcuts

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