base

package
v0.0.0-...-0705f78 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Activations = map[string]Activation{"identity": Identity{}, "logistic": Logistic{}, "relu": ReLU{}, "tanh": Tanh{}}

Activations is the map of implemented activation functions

View Source
var GOMethodCreators = map[string]GOMethodCreator{
	"sgd":             func() optimize.Method { return NewSGDOptimizer() },
	"adagrad":         func() optimize.Method { return NewAdagradOptimizer() },
	"rmsprop":         func() optimize.Method { return NewRMSPropOptimizer() },
	"adadelta":        func() optimize.Method { return NewAdadeltaOptimizer() },
	"adam":            func() optimize.Method { return NewAdamOptimizer() },
	"bfgs":            func() optimize.Method { return &optimize.BFGS{} },
	"cg":              func() optimize.Method { return &optimize.CG{} },
	"gradientdescent": func() optimize.Method { return &optimize.GradientDescent{} },
	"lbfgs":           func() optimize.Method { return &optimize.LBFGS{} },
	"neldermead":      func() optimize.Method { return &optimize.NelderMead{} },
}

GOMethodCreators is the map of all gonum optimize method creators (gonum native method creators + base.Optimizer creators)

View Source
var Solvers = map[string]OptimCreator{
	"sgd":      func() Optimizer { return NewSGDOptimizer() },
	"adagrad":  func() Optimizer { return NewAdagradOptimizer() },
	"rmsprop":  func() Optimizer { return NewRMSPropOptimizer() },
	"adadelta": func() Optimizer { return NewAdadeltaOptimizer() },
	"adam":     func() Optimizer { return NewAdamOptimizer() },
}

Solvers is the map for common Optimizer creators agd,adagrad,rmsprop,adadelta,adam

Functions

func CopyStruct

func CopyStruct(m interface{}) interface{}

CopyStruct create an new *struct with copied fields using reflection. it's not a deep copy.

func MatColStr

func MatColStr(X mat.Matrix, j int) string

MatColStr return the string for a matrix column

func MatDenseFirstColumnRemoved

func MatDenseFirstColumnRemoved(src *mat.Dense) *mat.Dense

MatDenseFirstColumnRemoved returns a *mat.Dense with the same underlaying data as M but 1st column removed

func MatDenseRowSlice

func MatDenseRowSlice(src mat.RawMatrixer, i, k int) *mat.Dense

MatDenseRowSlice returns a *mat.Dense with the same underlaying data as src but rows and columns removed

func MatDenseSlice

func MatDenseSlice(src mat.RawMatrixer, i, k, j, l int) *mat.Dense

MatDenseSlice returns a *mat.Dense with the same underlaying data as src but rows and columns removed

func MatDimsCheck

func MatDimsCheck(op string, R, X, Y mat.Matrix)

MatDimsCheck checks compat of operator op and its Matrix parameters Dims. R is result of op, X and Y are operands of op. "." is dot product. "+","-","*","/" are elementwize opts

func MatDimsString

func MatDimsString(mats ...mat.Matrix) string

MatDimsString returns a string representing Dims of its several Matrix parameters

func MatGeneralRowSlice

func MatGeneralRowSlice(M blas64.General, i, k int) blas64.General

MatGeneralRowSlice returns a blas64.General with the same underlaying data as M but rows and columns removed

func MatGeneralSlice

func MatGeneralSlice(M blas64.General, i, k, j, l int) blas64.General

MatGeneralSlice returns a blas64.General with the same underlaying data as M but rows and columns removed

func MatParallelGemm

func MatParallelGemm(tA, tB blas.Transpose, alpha float64, a, b blas64.General, beta float64, c blas64.General)

MatParallelGemm parallelize Gemm on A rows

func MatRowStr

func MatRowStr(X mat.Matrix, i int) string

MatRowStr returns the string for a matrix row

func MatShuffle

func MatShuffle(X, Y *mat.Dense)

MatShuffle shuffles the rows of X and Y matrices

func MatSigmoid

func MatSigmoid(dst *mat.Dense, X mat.Matrix) *mat.Dense

MatSigmoid put emelent-wise sigmoid of X into dst

func MatStr

func MatStr(Xs ...mat.Matrix) string

MatStr return a string from a mat.Matrix

Types

type Activation

type Activation interface {
	F(x float64) float64
	Fprime(y float64) float64
}

Activation is the inteface for an activation function

type GOMethodCreator

type GOMethodCreator func() optimize.Method

GOMethodCreator is a func that creates a gonum/optimize.Method

type Identity

type Identity struct{}

Identity ...

func (Identity) F

func (Identity) F(x float64) float64

F ...

func (Identity) Fprime

func (Identity) Fprime(y float64) float64

Fprime ...y=F(X*Theta)

type Logistic

type Logistic struct{}

Logistic ...

func (Logistic) F

func (Logistic) F(x float64) float64

F ...

func (Logistic) Fprime

func (Logistic) Fprime(y float64) float64

Fprime ...

type MatApply0

type MatApply0 struct {
	Rows, Columns int
	Func          func() float64
}

MatApply0 is a mat.Matrix override where At returns a func-generated value

func (MatApply0) At

func (m MatApply0) At(i, j int) float64

At for MatApply0

func (MatApply0) Dims

func (m MatApply0) Dims() (int, int)

Dims for MatApply0

func (MatApply0) T

func (m MatApply0) T() mat.Matrix

T for MatApply0

type MatApply1

type MatApply1 struct {
	mat.Matrix
	Func func(float64) float64
}

MatApply1 is a mat.Matrix override where At returns a func-trancformed value whose inputs are elements from its initializers

func (MatApply1) At

func (m MatApply1) At(i, j int) float64

At for MatApply1

func (MatApply1) Dims

func (m MatApply1) Dims() (int, int)

Dims for MatApply1

func (MatApply1) T

func (m MatApply1) T() mat.Matrix

T for MatApply1 returns a MatTranspose

type MatApply2

type MatApply2 struct {
	A, B mat.Matrix
	Func func(a, b float64) float64
}

MatApply2 is a mat.Matric overrides returning a function where args are elements from its two Matrix initializers

func (MatApply2) At

func (m MatApply2) At(i, j int) float64

At for MatApply2

func (MatApply2) Dims

func (m MatApply2) Dims() (int, int)

Dims for MatApply2

func (MatApply2) T

func (m MatApply2) T() mat.Matrix

T for MatApply2

type MatConst

type MatConst struct {
	Rows, Columns int
	Value         float64
}

MatConst is a matrix where all cless have the same value

func (MatConst) At

func (m MatConst) At(i, j int) float64

At for MatConst

func (MatConst) Dims

func (m MatConst) Dims() (int, int)

Dims for MatConst

func (MatConst) T

func (m MatConst) T() mat.Matrix

T for MatConst

type MatFirstColumnRemoved

type MatFirstColumnRemoved struct{ mat.Matrix }

MatFirstColumnRemoved is a matrix whose an initial column has been removed respective to its initializer

func (MatFirstColumnRemoved) At

func (m MatFirstColumnRemoved) At(i, j int) float64

At for MatFirstColumnRemoved

func (MatFirstColumnRemoved) Dims

func (m MatFirstColumnRemoved) Dims() (int, int)

Dims for MatFirstColumnRemoved

func (MatFirstColumnRemoved) Set

func (m MatFirstColumnRemoved) Set(i, j int, v float64)

Set for MatFirstColumnRemoved

func (MatFirstColumnRemoved) T

T for MatFirstColumnRemoved

type MatFirstRowZeroed

type MatFirstRowZeroed struct{ mat.Matrix }

MatFirstRowZeroed is a matrix whose an initial Row has been set to zeros respective to its initializer

func (MatFirstRowZeroed) At

func (m MatFirstRowZeroed) At(i, j int) float64

At for MatFirstRowZeroed

func (MatFirstRowZeroed) Dims

func (m MatFirstRowZeroed) Dims() (int, int)

Dims for MatFirstRowZeroed

func (MatFirstRowZeroed) Set

func (m MatFirstRowZeroed) Set(i, j int, v float64)

Set for MatFirstRowZeroed

func (MatFirstRowZeroed) T

T for MatFirstRowZeroed

type MatMulElem

type MatMulElem struct{ A, B mat.Matrix }

MatMulElem is a mat.Matrix override returning elementwize product from its two initializers

func (MatMulElem) At

func (m MatMulElem) At(i, j int) float64

At for MatMulElem

func (MatMulElem) Dims

func (m MatMulElem) Dims() (int, int)

Dims for MatMuilElem

func (MatMulElem) T

func (m MatMulElem) T() mat.Matrix

T for MatMulElem

type MatOneMinus

type MatOneMinus struct {
	mat.Matrix
}

MatOneMinus is a mat.Matrix override returning 1.-value from its initializer

func (MatOneMinus) At

func (m MatOneMinus) At(i, j int) float64

At for MatOneMinus

func (MatOneMinus) Dims

func (m MatOneMinus) Dims() (int, int)

Dims for MatOnesMinus

func (MatOneMinus) T

func (m MatOneMinus) T() mat.Matrix

T for MatOneMinus

type MatOnesPrepended

type MatOnesPrepended struct{ mat.Matrix }

MatOnesPrepended is a matrix override representing its initializer with an initial column of ones added

func (MatOnesPrepended) At

func (m MatOnesPrepended) At(i, j int) float64

At for MatOnesPrepended

func (MatOnesPrepended) Dims

func (m MatOnesPrepended) Dims() (int, int)

Dims for MatOnesPrepended

func (MatOnesPrepended) Set

func (m MatOnesPrepended) Set(i, j int, v float64)

Set for MatOnesPrepended

func (MatOnesPrepended) T

func (m MatOnesPrepended) T() mat.Matrix

T for MatOnesPrepended not implemented

type MatRowSlice

type MatRowSlice struct {
	mat.Matrix
	Start, End int
}

MatRowSlice is a matrix row chunk

func (MatRowSlice) At

func (m MatRowSlice) At(i, j int) float64

At for MatRowSlice

func (MatRowSlice) Dims

func (m MatRowSlice) Dims() (int, int)

Dims for MatRowSlice

func (MatRowSlice) Set

func (m MatRowSlice) Set(i, j int, v float64)

Set for MatRowSlice

func (MatRowSlice) T

func (m MatRowSlice) T() mat.Matrix

T for MatRowSlice

type MatScaled

type MatScaled struct {
	mat.Matrix
	Scale float64
}

MatScaled is a mat.Matrix override returning scaled value from its initializer

func (MatScaled) At

func (m MatScaled) At(i, j int) float64

At for MatScaled

func (MatScaled) Dims

func (m MatScaled) Dims() (int, int)

Dims for MatScaled

func (MatScaled) T

func (m MatScaled) T() mat.Matrix

T for MatScaled

type MatSub

type MatSub struct{ A, B mat.Matrix }

MatSub is a mat.Matrix override returning difference from its two initializers

func (MatSub) At

func (m MatSub) At(i, j int) float64

At for MatSub

func (MatSub) Dims

func (m MatSub) Dims() (int, int)

Dims for MatSub

func (MatSub) T

func (m MatSub) T() mat.Matrix

T for MatSub

type MatTranspose

type MatTranspose struct{ mat.Matrix }

MatTranspose is a matrix override to transpose a mat.Matrix from its initializer

func (MatTranspose) At

func (m MatTranspose) At(i, j int) float64

At for MatTranspose

func (MatTranspose) Dims

func (m MatTranspose) Dims() (int, int)

Dims for MatTranspose

func (MatTranspose) Set

func (m MatTranspose) Set(i, j int, v float64)

Set for MatTranspose

func (MatTranspose) T

func (m MatTranspose) T() mat.Matrix

T for MatTranspose

type OptimCreator

type OptimCreator func() Optimizer

OptimCreator is the type for functions returning an Optimizer

type Optimizer

type Optimizer interface {
	GetUpdate(update *mat.Dense, grad mat.Matrix)
	UpdateParams(grad mat.Matrix)
	SetTheta(Theta *mat.Dense)
	GetTheta() *mat.Dense
	GetTimeStep() uint64
	String() string
}

Optimizer has updateParams method to update theta from gradient

func NewOptimizer

func NewOptimizer(name string) Optimizer

NewOptimizer only accepts SGD|adagrad|adadelta|rmsprop|adam

type ReLU

type ReLU struct{}

ReLU ...

func (ReLU) F

func (ReLU) F(x float64) float64

F ...

func (ReLU) Fprime

func (ReLU) Fprime(y float64) float64

Fprime ...

type Regressor

type Regressor interface {
	Transformer
	Predict(X, Y *mat.Dense) Regressor
	Score(X, T *mat.Dense) float64
}

Regressor is the common interface for all regressors

type SGDOptimizer

type SGDOptimizer struct {
	// StepSize is used for all variants
	// Momentum can be used for all variants
	// GradientClipping is used if >0 to limit gradient L2 norm
	// RMSPropGamma is the momentum for rmsprop and adadelta
	// Epsilon is used to avoid division by zero in adagrad,rmsprop,adadelta,adam
	StepSize, Momentum, GradientClipping, RMSPropGamma, Epsilon, BatchPart float64
	// Adagrad, Adadelta, RMSProp, Adam are variants. At most one should be true
	Adagrad, Adadelta, RMSProp, Adam bool
	// NFeature,NOutputs need only to be initialized wher SGDOptimizer is used as an optimize.Method
	NFeatures, NOutputs int

	// running Parameters (don't set them yourself)
	GtNorm, Theta, PrevUpdate, Update, AdagradG, AdadeltaU *mat.Dense
	TimeStep                                               float64
	// Adam specific
	Beta1, Beta2 float64
	Mt, Vt       *mat.Dense
	// contains filtered or unexported fields
}

SGDOptimizer is struct for SGD solver v https://en.wikipedia.org/wiki/Stochastic_gradient_descent

func NewAdadeltaOptimizer

func NewAdadeltaOptimizer() *SGDOptimizer

NewAdadeltaOptimizer return a *SGDOptimizer setup for adadelta

func NewAdagradOptimizer

func NewAdagradOptimizer() *SGDOptimizer

NewAdagradOptimizer return a *SGDOptimizer setup for adagrad

func NewAdamOptimizer

func NewAdamOptimizer() *SGDOptimizer

NewAdamOptimizer returns an initialized adam solver

func NewRMSPropOptimizer

func NewRMSPropOptimizer() *SGDOptimizer

NewRMSPropOptimizer return a *SGDOptimizer setup for rmsprop

func NewSGDOptimizer

func NewSGDOptimizer() *SGDOptimizer

NewSGDOptimizer returns an initialized *SGDOptimizer with stepsize 1e-4 and momentum 0.9

func (*SGDOptimizer) GetTheta

func (s *SGDOptimizer) GetTheta() *mat.Dense

GetTheta can be called anytime after SetTheta to get read access to theta

func (*SGDOptimizer) GetTimeStep

func (s *SGDOptimizer) GetTimeStep() uint64

GetTimeStep return the number of theta updates already occurred

func (*SGDOptimizer) GetUpdate

func (s *SGDOptimizer) GetUpdate(update *mat.Dense, grad mat.Matrix)

GetUpdate compute the update from grad

func (*SGDOptimizer) Init

func (s *SGDOptimizer) Init(loc *optimize.Location) (op optimize.Operation, err error)

Init initializes the method based on the initial data in loc, updates it and returns the first operation to be carried out by the caller. The initial location must be valid as specified by Needs.

func (*SGDOptimizer) Iterate

func (s *SGDOptimizer) Iterate(loc *optimize.Location) (op optimize.Operation, err error)

Iterate retrieves data from loc, performs one iteration of the method, updates loc and returns the next operation.

func (*SGDOptimizer) Needs

func (*SGDOptimizer) Needs() struct {
	Gradient bool
	Hessian  bool
}

Needs is for when SGDOptimizer is used as an optimize.Method

func (*SGDOptimizer) SetTheta

func (s *SGDOptimizer) SetTheta(Theta *mat.Dense)

SetTheta should be called before first call to UpdateParams to let the solver know the theta pointer

func (*SGDOptimizer) String

func (s *SGDOptimizer) String() string

func (*SGDOptimizer) UpdateParams

func (s *SGDOptimizer) UpdateParams(grad mat.Matrix)

UpdateParams updates theta from gradient. first call allocates required temporary storage

type Sigmoid

type Sigmoid = Logistic

Sigmoid ...

type Softmax

type Softmax struct{}

Softmax ...

func (Softmax) F

func (Softmax) F(z mat.Vector, output int) float64

F for Softmax

type Tanh

type Tanh struct{}

Tanh ...

func (Tanh) F

func (Tanh) F(x float64) float64

F ...

func (Tanh) Fprime

func (Tanh) Fprime(y float64) float64

Fprime ...

type Transformer

type Transformer interface {
	Fit(X, Y *mat.Dense) Transformer
	Transform(X, T *mat.Dense) (Xout, Yout *mat.Dense)
}

Transformer transforms X,Y

Jump to

Keyboard shortcuts

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