module

package module
v0.0.0-...-e2bb1e6 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReLU = Activation(_ReLU, _ReLUGrad)
View Source
var Sigmoid = Activation(_Sigmoid, _SigmoidGrad)
View Source
var Tanh = Activation(_Tanh, _TanhGrad)

Functions

func CrossEntropy

func CrossEntropy(dist, target *autograd.Node) *autograd.Node

func FusedCrossEntropy

func FusedCrossEntropy(logits, target *autograd.Node) *autograd.Node

func MSE

func MSE(dist, target *autograd.Node) *autograd.Node

Types

type AffineModule

type AffineModule struct {
	W, B *autograd.Node
}

func Affine

func Affine(i, o int) *AffineModule

func (*AffineModule) Forward

func (a *AffineModule) Forward(x *autograd.Node) *autograd.Node

func (*AffineModule) GetState

func (a *AffineModule) GetState() map[string]*tensor.Tensor[float32]

func (*AffineModule) InitHe

func (a *AffineModule) InitHe() *AffineModule

func (*AffineModule) InitKaiming

func (a *AffineModule) InitKaiming() *AffineModule

func (*AffineModule) InitXavier

func (a *AffineModule) InitXavier() *AffineModule

func (*AffineModule) Params

func (a *AffineModule) Params() []*autograd.Node

func (*AffineModule) SetState

func (a *AffineModule) SetState(m map[string]*tensor.Tensor[float32])

type BranchModule

type BranchModule struct {
	When  *bool
	True  Module
	False Module
}

func Branch

func Branch(cond *bool, _true, _false Module) *BranchModule

func DoWhen

func DoWhen(when *bool, what Module) *BranchModule

func SkipWhen

func SkipWhen(when *bool, what Module) *BranchModule

func (*BranchModule) Forward

func (b *BranchModule) Forward(node *autograd.Node) *autograd.Node

func (*BranchModule) GetState

func (b *BranchModule) GetState() map[string]*tensor.Tensor[float32]

func (*BranchModule) Params

func (b *BranchModule) Params() []*autograd.Node

func (*BranchModule) SetState

func (b *BranchModule) SetState(m map[string]*tensor.Tensor[float32])

type Conv2DModule

type Conv2DModule struct {
	W       *autograd.Node
	B       *autograd.Node
	StrideH int
	StrideW int
	PadH    int
	PadW    int
}

func Conv2D

func Conv2D(
	cin, cout,
	kh, kw,
	sH, sW,
	pH, pW int,
) *Conv2DModule

func (*Conv2DModule) Forward

func (c *Conv2DModule) Forward(x *autograd.Node) *autograd.Node

func (*Conv2DModule) GetState

func (c *Conv2DModule) GetState() map[string]*tensor.Tensor[float32]

func (*Conv2DModule) InitHe

func (c *Conv2DModule) InitHe() *Conv2DModule

func (*Conv2DModule) InitKaiming

func (c *Conv2DModule) InitKaiming() *Conv2DModule

func (*Conv2DModule) InitXavier

func (c *Conv2DModule) InitXavier() *Conv2DModule

func (*Conv2DModule) Params

func (c *Conv2DModule) Params() []*autograd.Node

func (*Conv2DModule) SetState

func (c *Conv2DModule) SetState(m map[string]*tensor.Tensor[float32])

type Func

type Func func(*autograd.Node) *autograd.Node
var Flatten Func = func(x *autograd.Node) *autograd.Node {
	val := x.Val.Flatten()
	out := autograd.MakeResult(val, x)

	out.AddEdge(x, func(dy *tensor.Tensor[float32]) {

		g := tensor.ZerosLike(x.Grad)

		for i := x.Grad.IterStride(); i.Done(); i.Next() {
			g.Data[i.Offset()] = dy.Data[i.Count()]
		}

		x.Grad.Add(g)
	})

	return out
}
var Softmax Func = func(logits *autograd.Node) *autograd.Node {
	exp := autograd.Exp(autograd.Sub(
		logits,
		autograd.FillLike(autograd.Max(logits), logits),
	))
	dist := autograd.Div(
		exp,
		autograd.FillLike(autograd.Sum(exp), exp),
	)

	return dist
}

func Activation

func Activation(
	f func(x float32) float32,
	g func(x, dy float32) float32,
) Func

func Dropout

func Dropout(p float32, eval *bool) Func

func LeakyReLU

func LeakyReLU(alpha float32) Func

func MaxPool2D

func MaxPool2D(kH, kW, sH, sW int) Func

func (Func) Forward

func (f Func) Forward(x *autograd.Node) *autograd.Node

func (Func) GetState

func (f Func) GetState() map[string]*tensor.Tensor[float32]

func (Func) Params

func (f Func) Params() []*autograd.Node

func (Func) SetState

func (f Func) SetState(map[string]*tensor.Tensor[float32])

type Module

type Module interface {
	Params() []*autograd.Node
	Forward(*autograd.Node) *autograd.Node
	GetState() map[string]*tensor.Tensor[float32]
	SetState(map[string]*tensor.Tensor[float32])
}

type Sequential

type Sequential []Module

func (Sequential) Forward

func (s Sequential) Forward(x *autograd.Node) *autograd.Node

func (Sequential) GetState

func (s Sequential) GetState() map[string]*tensor.Tensor[float32]

func (Sequential) Params

func (s Sequential) Params() []*autograd.Node

func (Sequential) SetState

func (s Sequential) SetState(m map[string]*tensor.Tensor[float32])

Jump to

Keyboard shortcuts

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