Quick and dirty optimization. The goal is to extend to Go similar functionality to the Optimization library in SciPy.
The package is still early in development and its implementation is subject to change.
The package exports three functions:
- A Monte-Carlo optimization for functions of two inputs.
- func MonteCarlo(f Function2, xMin float64, xMax float64, yMin float64, yMax float64) float64
- where Function2 is type Function func(x, y float64) float64
- A Monte-Carlo optimization for functions of two inputs, with a functional constraint
- func MonteCarloCons(f Function2, cons Constraint2, xMin float64, xMax float64, yMin float64, yMax float64) float64
- where Constraint2 is type Constraint2 func(x, y float64) bool
- A Gradient Descent algorithm, requires the derivative of the function you are trying to optimize.
- func GradientDescent(f Derivitive, deriv Derivitive, x float64, sign float64) float64
- where Derivitive is func(x float64, sign float64) float64
- A Bisection Algorithm to find a specified value in the range of the function.
- func Bisection(f Function, lBound float64, uBound float64, goal float64) float64
It relies on a few special, exported types:
- type Derivitive func(x float64, sign float64) float64
- type Function func(x float64) float64
- type Function2 func(x, y float64) float64 //a function with two inputs
- type Constraint2 func(x, y float64) bool
Also included are nascent unit tests.
go test -vto see expected and computed results for test cases.
go get github.com/thetwentyone/goptimize to install
go get -u github.com/thetwentyone/goptimize to update the package
- Improve unit tests, particularly on Gradient Descent
- Create uniformity between methods (i.e. inputs and outputs between methods)
- Add constraints to functions
- Add goroutines to MonteCarlo?
- Brent's Method