Version: v0.0.0-...-beb861e Latest Latest

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

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 12 Imported by: 1



Package base contains miscellaneous utilities common to other packages



This section is empty.


View Source
var Activations map[string]Activation

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


func FromDense

func FromDense(dst mat.Mutable, dense *mat.Dense) *mat.Dense

FromDense fills dst (mat.Mutable) with src (mat.Dense)

func MatDenseColSlice

func MatDenseColSlice(src mat.RawMatrixer, j, l int) *mat.Dense

MatDenseColSlice returns a *mat.Dense view of partial underlaying data of M

func MatDenseRowSlice

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

MatDenseRowSlice returns a *mat.Dense view of partial underlaying data of M

func MatDenseSlice

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

MatDenseSlice returns a *mat.Dense view of partial underlaying data of M

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 MatGeneralColSlice

func MatGeneralColSlice(M blas64.General, j, l int) blas64.General

MatGeneralColSlice returns a blas64.General view of partial underlaying data of M

func MatGeneralRowSlice

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

MatGeneralRowSlice returns a blas64.General view of partial underlaying data of M

func MatGeneralSlice

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

MatGeneralSlice returns a blas64.General view of partial underlaying data of M

func MatStr

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

MatStr return a string from a mat.Matrix

func NewSource

func NewSource(seed uint64) *randomkit.RKState

NewSource returns a new pseudo-random Source seeded with the given value.

func Parallelize

func Parallelize(threads, NSamples int, f func(th, start, end int))

Parallelize split execution over NSamples across threads

func ToDense

func ToDense(m mat.Matrix) *mat.Dense

ToDense returns w view of m if m is a RawMatrixer, et returns a dense copy of m


type Activation

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

Activation is the inteface for an activation function

type Fiter

type Fiter interface {
	Fit(X, Y mat.Matrix) Fiter

Fiter have a Fit(Matrix,Matrix) Fitter method. may be a Predicter or a Transformer

type Float64er

type Float64er interface {
	Float64() float64

Float64er is implemented by a random source having a method Float64() float64

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 Intner

type Intner interface {
	Intn(int) int

Intner is implemented by a random source having a method Intn() float64

type LockedSource

type LockedSource struct {
	// contains filtered or unexported fields

LockedSource is an implementation of Source that is concurrency-safe. It is just a standard Source with its operations protected by a sync.Mutex.

func NewLockedSource

func NewLockedSource(seed uint64) *LockedSource

NewLockedSource returns a rand.Source safe for concurrent access

func (*LockedSource) Seed

func (s *LockedSource) Seed(seed uint64)

Seed ...

func (*LockedSource) SourceClone

func (s *LockedSource) SourceClone() Source

SourceClone ...

func (*LockedSource) Uint64

func (s *LockedSource) Uint64() (n uint64)

Uint64 ...

func (*LockedSource) WithLock

func (s *LockedSource) WithLock(f func(Source))

WithLock executes f while s is locked

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 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 MatOnesPrepended

type MatOnesPrepended struct{ mat.Matrix }

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

type MatRowSlice

type MatRowSlice struct {
	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 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 NormFloat64er

type NormFloat64er interface {
	NormFloat64() float64

NormFloat64er is implemented by a random source having a method NormFloat64() float64

type OptimCreator

type OptimCreator func() Optimizer

OptimCreator is the type for functions returning an Optimizer

func NewSolver

func NewSolver(name string) OptimCreator

NewSolver returns an OptimCreator

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 Permer

type Permer interface {
	Perm(int) []int

Permer is implemented by a random source having a method Perm(int) []int

type Predicter

type Predicter interface {
	GetNOutputs() int
	Predict(X mat.Matrix, Y mat.Mutable) *mat.Dense
	Score(X, Y mat.Matrix) float64
	IsClassifier() bool
	PredicterClone() Predicter

Predicter have Predict(Matrix,Mutable). if 2nd arg (result receiver) is nil, il will be allocated and returned by Predict

type RandomState

type RandomState = Source

RandomState represents a bit more than random_state pythonic attribute. it's not only a seed but a source with a state as it's name states

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 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

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(dim, tasks int) int

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) Run

func (s *SGDOptimizer) Run(operation chan<- optimize.Task, result <-chan optimize.Task, tasks []optimize.Task)

Run implements optimize.Method.Run for SGDOptimizer

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

func (*SGDOptimizer) Uses

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

type Shuffler

type Shuffler interface {
	Shuffler(int, func(int, int))

Shuffler is implemented by a random source having a method Shuffle(int,func(int,int))

type Sigmoid

type Sigmoid = Logistic

Sigmoid ...

type Source

type Source = rand.Source

A Source represents a source of uniformly-distributed pseudo-random int64 values in the range [0, 1<<64).

type SourceCloner

type SourceCloner interface {
	SourceClone() Source

SourceCloner is an "".Source with a Clone method

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 {
	Transform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)
	FitTransform(X, Y mat.Matrix) (Xout, Yout *mat.Dense)
	TransformerClone() Transformer

Transformer transforms X,Y into Xout,Yout

Jump to

Keyboard shortcuts

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