项目作者: gyrov

项目描述 :
Python implementation of a Nelder-Mead simplex algorithm using numpy
高级语言: Python
项目地址: git://github.com/gyrov/Simplex_Algorithm.git
创建时间: 2020-02-07T13:52:45Z
项目社区:https://github.com/gyrov/Simplex_Algorithm

开源协议:MIT License

下载


Simplex_Algorithm

Python implementation of a Nelder-Mead simplex algorithm adapted from the original paper [1] using numpy functions. Simplex method is contained within the simplex.py python module.

  1. import simplex
  2. # Arbitrary function to minimise, input is a
  3. # vertex of the simplex as a numpy array, e.g. numpy.array((10,20))
  4. def F(vertex):
  5. return vertex[0] ** 2 - 5 * vertex[1]
  6. # Simplex class object
  7. splx = simplex.Simplex()
  8. # Calculate the minimum of function F with the simplex method
  9. # ALPHA, GAMMA, BETA are the reflection, expansion, contraction coefficients
  10. # THRESHOLD is the minimisation check for the smallest vertex of the simplex.
  11. # F is the function to minimise as described above.
  12. minimum = splx.simplex(ALPHA, GAMMA, BETA, THRESHOLD, F)
  13. print(minimum)
  1. # Output
  2. >> numpy.array((MIN_VECTOR)), number_of_iterations

simplex_test.py contains an example in which we minimise the Rosenbrock function with a = 1, b = 100 and is able to converge on the minimum at (1,1).

[1] J. A. Nelder, R. Mead, A Simplex Method for Function Minimization, The Computer Journal, Volume 7, Issue 4, January 1965, Pages 308–313, https://doi.org/10.1093/comjnl/7.4.308