op

package
v0.0.0-...-d6e1657 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2015 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(param Parameter, value float32)

This func is useful to fill the parameter with the same value

func Sum

func Sum(param Parameter, compute func(float32) float32) float32

Compute the sum of the element of parameter after some transformation.

Types

type Function

type Function interface {
	Evaluate(param Parameter, gradient Parameter) float32
}

There are many different ways one can optimize a function, but the most effective ones need gradient. The interface is designed so that one can compose function easily. The semantics is simply add gradient from this function to corresponding dimensions on the output paramenter gradient.

type IndexIterator

type IndexIterator interface {
	Index() int
	Next() bool
	Rewind()
	Size() int
}

For more information read: http://ewencp.org/blog/golang-iterators/ We need an reasonably efficient way to enumerate all indexes.

For example, we can do: sum := 0.0

for it := param.IndexIterator(); it.Next(); {
   sum += param.Get(it.Index());
}

func MakeRangeIndexIterator

func MakeRangeIndexIterator(psize int) IndexIterator

type Minimizer

type Minimizer interface {
	Minimize(function Function, stopCriteria StopCriteria, param Parameter) (float32, error)
}

High level interface for minimization. This assume that we start with one point in the parameter space, and end with an optimal point. Return true if we find optimal point.

type Parameter

type Parameter interface {
	Get(index int) float32
	Set(index int, value float32)
	Add(index int, value float32)

	// This allow us to generate parameter with same width.
	CloneWithoutCopy() Parameter

	// This allow one to enumerate through all parameters
	IndexIterator() IndexIterator

	// Return raw data pointer
	Data() []float32
}

We need some interface to define function and how we optimize them.

func NewAllTheSameParameter

func NewAllTheSameParameter(v float32, s int) Parameter

This creates a parameter that has the same value on all dimensions

func NewVecParameter

func NewVecParameter(size int) Parameter

This creates a new Vector based parameter

func NewVecParameterWithData

func NewVecParameterWithData(data []float32) Parameter

type ProjectedGradient

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

This defines how we do projected gradient.

func NewProjectedGradient

func NewProjectedGradient(projector *Projection, beta, sigma, alpha float32) *ProjectedGradient

func (*ProjectedGradient) Minimize

func (pg *ProjectedGradient) Minimize(loss Function, stop StopCriteria, vec Parameter) (float32, error)

This implementation is based on "Projected Gradient Methods for Non-negative Matrix Factorization" by Chih-Jen Lin. Particularly it is based on the discription of an improved projected gradient method in page 10 of that paper.

type Projection

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

Project is used to clip the parameter and gradient.

func NewProjection

func NewProjection(ub, lb Parameter) *Projection

this creates a Project with specified upper and lower bound. NOTE(baigang): to fix scope visibility of `upper_bound` and `lower_bound` inside `Projection`.

func (*Projection) ClipGradient

func (p *Projection) ClipGradient(base, gradient Parameter)

We assume the base and gradient are in the same dimensions. In another words, the IndexIterator will return the same from base and gradient.

func (*Projection) ClipPoint

func (p *Projection) ClipPoint(vec Parameter)

type Regularization

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

This implements l1 l2 regularization.

func (*Regularization) Evaluate

func (r *Regularization) Evaluate(param Parameter, gradient Parameter) float32

type Rosenbrock

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

Rosenbrock is used as standard test function for optimization.

f(x, y) = (1-x)^2 + 100(y-x^2)^2, it has a global minimum of 0

We can have multiple copies of this function, and different scaling too to make it harder to solve.

func (*Rosenbrock) Evaluate

func (r *Rosenbrock) Evaluate(in, out Parameter) float32

This implementation should only work with parameter that have indexes range from [0, 2*numOfCopies).

type StopCriteria

type StopCriteria interface {
	Done(param Parameter, value float32, gradient Parameter) bool
}

This is used to figure out where one can stop the optimization. Implementation can be count based, or gradient norm based.

func MakeComposedCriterion

func MakeComposedCriterion(criteria ...StopCriteria) StopCriteria

func MakeFixCountStopCriteria

func MakeFixCountStopCriteria(iter int) StopCriteria

func MakeGradientNormStopCriteria

func MakeGradientNormStopCriteria(thres float32) StopCriteria

func MakeTimeoutCriterion

func MakeTimeoutCriterion(limit time.Duration) StopCriteria

type SumFunction

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

This defines an additive function. One can compose the function this way easily.

func (*SumFunction) Evaluate

func (rf *SumFunction) Evaluate(param Parameter, gradient Parameter) float32

Jump to

Keyboard shortcuts

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