Documentation ¶
Index ¶
- Variables
- func CopyStruct(m interface{}) interface{}
- func MatColStr(X mat.Matrix, j int) string
- func MatDenseFirstColumnRemoved(src *mat.Dense) *mat.Dense
- func MatDenseRowSlice(src mat.RawMatrixer, i, k int) *mat.Dense
- func MatDenseSlice(src mat.RawMatrixer, i, k, j, l int) *mat.Dense
- func MatDimsCheck(op string, R, X, Y mat.Matrix)
- func MatDimsString(mats ...mat.Matrix) string
- func MatGeneralRowSlice(M blas64.General, i, k int) blas64.General
- func MatGeneralSlice(M blas64.General, i, k, j, l int) blas64.General
- func MatParallelGemm(tA, tB blas.Transpose, alpha float64, a, b blas64.General, beta float64, ...)
- func MatRowStr(X mat.Matrix, i int) string
- func MatShuffle(X, Y *mat.Dense)
- func MatSigmoid(dst *mat.Dense, X mat.Matrix) *mat.Dense
- func MatStr(Xs ...mat.Matrix) string
- type Activation
- type GOMethodCreator
- type Identity
- type Logistic
- type MatApply0
- type MatApply1
- type MatApply2
- type MatConst
- type MatFirstColumnRemoved
- type MatFirstRowZeroed
- type MatMulElem
- type MatOneMinus
- type MatOnesPrepended
- type MatRowSlice
- type MatScaled
- type MatSub
- type MatTranspose
- type OptimCreator
- type Optimizer
- type ReLU
- type Regressor
- type SGDOptimizer
- func (s *SGDOptimizer) GetTheta() *mat.Dense
- func (s *SGDOptimizer) GetTimeStep() uint64
- func (s *SGDOptimizer) GetUpdate(update *mat.Dense, grad mat.Matrix)
- func (s *SGDOptimizer) Init(loc *optimize.Location) (op optimize.Operation, err error)
- func (s *SGDOptimizer) Iterate(loc *optimize.Location) (op optimize.Operation, err error)
- func (*SGDOptimizer) Needs() struct{ ... }
- func (s *SGDOptimizer) SetTheta(Theta *mat.Dense)
- func (s *SGDOptimizer) String() string
- func (s *SGDOptimizer) UpdateParams(grad mat.Matrix)
- type Sigmoid
- type Softmax
- type Tanh
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var Activations = map[string]Activation{"identity": Identity{}, "logistic": Logistic{}, "relu": ReLU{}, "tanh": Tanh{}}
Activations is the map of implemented activation functions
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)
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 MatDenseFirstColumnRemoved ¶
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 ¶
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 ¶
MatDimsString returns a string representing Dims of its several Matrix parameters
func MatGeneralRowSlice ¶
MatGeneralRowSlice returns a blas64.General with the same underlaying data as M but rows and columns removed
func MatGeneralSlice ¶
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 MatSigmoid ¶
MatSigmoid put emelent-wise sigmoid of X into dst
Types ¶
type Activation ¶
Activation is the inteface for an activation function
type GOMethodCreator ¶
GOMethodCreator is a func that creates a gonum/optimize.Method
type MatApply1 ¶
MatApply1 is a mat.Matrix override where At returns a func-trancformed value whose inputs are elements from its initializers
type MatApply2 ¶
MatApply2 is a mat.Matric overrides returning a function where args are elements from its two Matrix initializers
type MatFirstColumnRemoved ¶
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 ¶
func (m MatFirstColumnRemoved) T() mat.Matrix
T for MatFirstColumnRemoved
type MatFirstRowZeroed ¶
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
type MatMulElem ¶
MatMulElem is a mat.Matrix override returning elementwize product from its two initializers
type MatOneMinus ¶
MatOneMinus is a mat.Matrix override returning 1.-value from its initializer
type MatOnesPrepended ¶
MatOnesPrepended is a matrix override representing its initializer with an initial column of ones added
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 ¶
MatRowSlice is a matrix row chunk
type MatTranspose ¶
MatTranspose is a matrix override to transpose a mat.Matrix from its initializer
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 ¶
NewOptimizer only accepts SGD|adagrad|adadelta|rmsprop|adam
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 ¶
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 ¶
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 Transformer ¶
type Transformer interface { Fit(X, Y *mat.Dense) Transformer Transform(X, T *mat.Dense) (Xout, Yout *mat.Dense) }
Transformer transforms X,Y