An alternative implementation of the Nelder-Mead method, there is no need of knowing the function being optimized. The code is completely implemented in python.
This implementation is based on the following article:
pip install git+https://github.com/bmartins95/NelderMead
- numpy
If you wish to run the examples the matplotlib dependency will also be needed.
The most simple example of the class usage is:
from nelder_mead import NelderMead
def sphere(x):
return sum([value**2 for value in x])
def main():
f_variables = np.array([1.0, 1.0])
nelder = NelderMead(f_variables)
for step in range(0, 30):
f_value = sphere(f_variables)
nelder.run(f_value)
if __name__ == "__main__":
main()
You can change the initial simplex construction by inheriting the NelderMead class and modifying the buildSimplexPoints function as follows:
class NewNelderMead(NelderMead):
def buildSimplexPoints(self):
x0 = np.array([1.0, 1.0])
x1 = np.array([2.5, 1.0])
self.simplex = np.vstack((x0, x1, self.f_variables))
The last line of the simplex must aways be f_variables.
The original implementation of the simplex construction is based on this answer: