Git Product home page Git Product logo

nelmead's Introduction

Nelder-Mead Optimization in Go

Package nelmead is a small implementation of the Nelder-Mead optimization algorithm in Go with minimal dependencies. It strictly follows the algorithm as described in https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method.

This is also my first contribution to GitHub, and a bit of a trial for me how this works.

It requires a yield or optimizing function, and the number of parameters to be optimized (dim)

	func NewNelderMeadOptimizer(f func([]float64) float64, dim int) *NelderMeadOptimizer 

Default values for the optimizer can be used, but if you want to tweak the performance you can adjust various parameter in the struct NelderMeadOptimizer.

type NelderMeadOptimizer struct {

    // ConvTreshold is the minimimal difference between two successive trials
    // for an optimization to be classified as an improvement.
    ConvTreshold float64

    // ConvLimit is the number of iterations with no significant improvement in
    // the optimizing function for the solution to be classified as converged.
    ConvLimit int

	// These are the parameters used for the reflection, expansion,
	// contraction, and shrink stages in the optimzation process
    Alpha     float64
    Gamma     float64
    Rho       float64
    Sigma     float64
}

The actual optimization trial is started by using the Optimize method associated with an instance of the NelderMeadOptimizer:

func (nmo *NelderMeadOptimizer) Optimize(max_iter int, start []float64, step float64) ([]float64, float64, bool) 

As input it requires the maximum number of iterations max_iter, and a start-value for the parameters of the function, and a step-size.

It returns the solution vector, the value of the minimum found for the solution, and a boolean indicating if the solution has converged or not.

The solution is strongly dependent on the start and step values and might require tweaking to get the best solution. For more detailed information see godoc. Also see the nelmead_test.go file as example how to use this function.

License

Copyright 2018 Gerard Harbers

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

nelmead's People

Contributors

srebrah avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.