nn

package
v0.0.0-...-f6f7014 Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layer

type Layer interface {
	InputShape() Shape
	OutputShape() Shape
	Init(inputShape Shape, factory OptimizerFactory) error
	Call(inputs []*Tensor) []*Tensor
	Forward(inputs []*Tensor) []*Tensor
	Backward(douts []*Tensor) []*Tensor
	Params() []*Tensor
	Update()
}

Layer is a layer of neural network.

func Dense

func Dense(units int) Layer

Dense is a fully connected layer.

func Dropout

func Dropout(rate float64) Layer

Dropout dropouts inputs.

func Flatten

func Flatten() Layer

Flatten flattens the inputs.

func Lambda

func Lambda(f func(*Tensor) *Tensor, outputShape func(inputShape Shape) Shape) Layer

Lambda is a user defined function layer.

func ReLU

func ReLU() Layer

ReLU is an activation function layer.

func Sigmoid

func Sigmoid() Layer

Sigmoid is an activation function layer.

func Softmax

func Softmax() Layer

Softmax is an activation function layer.

type Loss

type Loss interface {
	Call(y, t []*Tensor) float64
	Forward(y, t []*Tensor) float64
	Backward() []*Tensor
}

Loss is a loss function of a neural network.

func CrossEntropyError

func CrossEntropyError() Loss

CrossEntropyError is a loss function.

type Model

type Model interface {
	Layers() []Layer
	Fit(x, y []*Tensor, epochs, batchSize int)
	Predict([]*Tensor) []*Tensor
	Build(Loss) error
}

Model is a neural network model.

type Optimizer

type Optimizer interface {
	Update(params, grads *Tensor) *Tensor
}

Optimizer updates parameters.

type OptimizerFactory

type OptimizerFactory interface {
	Create(Shape) Optimizer
}

OptimizerFactory creates optimizer.

func MomentumSGD

func MomentumSGD(lr, momentum float64) OptimizerFactory

MomentumSGD is an optimizer that add momentum to SGD

func SGD

func SGD(lr float64) OptimizerFactory

SGD is stochastic gradient descent.

type Sequential

type Sequential struct {
	// contains filtered or unexported fields
}

Sequential is a model that stack of layers.

func NewSequential

func NewSequential(inputShape Shape) *Sequential

NewSequential creates an instance of sequential model.

func (*Sequential) Accuracy

func (s *Sequential) Accuracy(y, t []*Tensor) float64

Accuracy is accuracy of predicted value.

func (*Sequential) AddLayer

func (s *Sequential) AddLayer(layer Layer)

AddLayer adds layer to model.

func (*Sequential) Build

func (s *Sequential) Build(loss Loss, factory OptimizerFactory) error

Build builds a model by connecting the given layers.

func (*Sequential) Fit

func (s *Sequential) Fit(x, t []*Tensor, epochs, batchSize int)

Fit fits the model to the given dataset.

func (*Sequential) Layers

func (s *Sequential) Layers() []Layer

Layers returns layers that model has.

func (*Sequential) Loss

func (s *Sequential) Loss(y, t []*Tensor) float64

Loss is loss of predicted value.

func (*Sequential) Predict

func (s *Sequential) Predict(inputs []*Tensor) []*Tensor

Predict predicts output for the given data.

func (*Sequential) Summary

func (s *Sequential) Summary() string

Summary is summary of model.

type Shape

type Shape []int

Shape is a shape of a tensor.

func (Shape) Clone

func (s Shape) Clone() Shape

Clone clones a shape.

func (Shape) Elements

func (s Shape) Elements() int

Elements is a number of elements that tensor has.

func (Shape) Equal

func (s Shape) Equal(shape Shape) bool

Equal compares two shapes.

func (Shape) Rank

func (s Shape) Rank() int

Rank is rank of a tensor.

func (Shape) RawIndex

func (s Shape) RawIndex(at Shape) int

RawIndex is a index of raw data.

type Tensor

type Tensor struct {
	// contains filtered or unexported fields
}

Tensor is an algebraic object that describes a relationship between sets of algebraic objects related to a vector space.

func NewTensor

func NewTensor(shape Shape) *Tensor

NewTensor creates an instance of tensor.

func TensorFromSlice

func TensorFromSlice(shape Shape, p []float64) *Tensor

TensorFromSlice creates an instance of tensor initialized with a given data.

func (*Tensor) AddBroadCast

func (t *Tensor) AddBroadCast(a float64) *Tensor

AddBroadCast adds a value to all elements.

func (*Tensor) AddTensor

func (t *Tensor) AddTensor(tensor *Tensor) *Tensor

AddTensor adds a tensor.

func (*Tensor) BroadCast

func (t *Tensor) BroadCast(f func(float64) float64) *Tensor

BroadCast creates a tensor of the return value that inputs all the elements into the passed function.

func (*Tensor) Clone

func (t *Tensor) Clone() *Tensor

Clone clones a tensor.

func (*Tensor) DivBroadCast

func (t *Tensor) DivBroadCast(a float64) *Tensor

DivBroadCast divides all elements by a value.

func (*Tensor) DivTensor

func (t *Tensor) DivTensor(tensor *Tensor) *Tensor

DivTensor divides by a tensor.

func (*Tensor) Dot

func (t *Tensor) Dot(tensor *Tensor) *Tensor

Dot is a dot product of tensor.

func (*Tensor) Exp

func (t *Tensor) Exp() *Tensor

Exp is exp of a tensor.

func (*Tensor) Get

func (t *Tensor) Get(at Shape) float64

Get gets a value.

func (*Tensor) Log

func (t *Tensor) Log() *Tensor

Log is log of a tensor.

func (*Tensor) Max

func (t *Tensor) Max() float64

Max is maximum value of a tensor.

func (*Tensor) MaxIndex

func (t *Tensor) MaxIndex() int

MaxIndex is a index of a maximum value.

func (*Tensor) MulBroadCast

func (t *Tensor) MulBroadCast(a float64) *Tensor

MulBroadCast multiplies all elements by a value.

func (*Tensor) MulTensor

func (t *Tensor) MulTensor(tensor *Tensor) *Tensor

MulTensor multiplies by a tensor.

func (*Tensor) Rank

func (t *Tensor) Rank() int

Rank is rank of a tensor.

func (*Tensor) ReShape

func (t *Tensor) ReShape(shape Shape) *Tensor

ReShape reshapes a tensor.

func (*Tensor) Set

func (t *Tensor) Set(a float64, at Shape)

Set sets a value.

func (*Tensor) Shape

func (t *Tensor) Shape() Shape

Shape is shape of a tensor.

func (*Tensor) SubBroadCast

func (t *Tensor) SubBroadCast(a float64) *Tensor

SubBroadCast subtracts a value​from all elements.

func (*Tensor) SubTensor

func (t *Tensor) SubTensor(tensor *Tensor) *Tensor

SubTensor subtracts a tensor.

func (*Tensor) Sum

func (t *Tensor) Sum() float64

Sum is sum of all elements.

func (*Tensor) Transpose

func (t *Tensor) Transpose() *Tensor

Transpose transpose tensor.

Jump to

Keyboard shortcuts

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