gd

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gd provides gradient descent implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converger added in v0.2.0

type Converger interface {
	Converge(context.Context, Stepper) ([]float64, error)
}

Converger is the interface that wraps the basic Converge method.

func NewConverger added in v0.2.0

func NewConverger(ct options.ConvergenceType, ci float64, c CostFunc) (Converger, error)

NewConverger returns a new converger. If unsupported ConvergenceType is passed, an error is returned.

type ConvergerFunc added in v0.2.0

type ConvergerFunc func(context.Context, Stepper) ([]float64, error)

ConvergerFunc is an adapter to allow the use of plain functions as convergers.

func (ConvergerFunc) Converge added in v0.2.0

func (f ConvergerFunc) Converge(ctx context.Context, s Stepper) ([]float64, error)

type CostFunc

type CostFunc func(x [][]float64, y []float64, coeffs []float64) (float64, error)

CostFunc is a function template for cost function used in gradient descent algorithm.

type GradientDescent added in v0.2.0

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

GradientDescent holds the hyphothesis and cost functions needed by gradient descent algorithm.

func New added in v0.2.0

New creates new gradient descent.

func (GradientDescent) Run added in v0.2.0

func (g GradientDescent) Run(ctx context.Context, o options.Options, x [][]float64, y []float64) ([]float64, error)

Run runs the gradient descent algorithm.

type Hyphothesis

type Hyphothesis func(x []float64, coeffs []float64) (float64, error)

Hyphothesis is a function template for a hyphothesis function used in gradient descent algorithm.

type Stepper added in v0.2.0

type Stepper interface {
	// TakeStep takes single step towards cost function minimum.
	TakeStep() error
	// CurrentCoefficients returns current coefficients calculated by stepper.
	CurrentCoefficients() []float64
	// X returns design matrix used in calculations.
	X() [][]float64
	// Y returns target vector used in calculations.
	Y() []float64
}

A Stepper wraps logic around taking steps (calculating new coefficients' values).

func NewStepper added in v0.2.0

func NewStepper(gdv options.GradientDescentVariant, h Hyphothesis, x [][]float64, y []float64, lr float64) (Stepper, error)

Jump to

Keyboard shortcuts

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