项目作者: 100

项目描述 :
🎯 A comprehensive gradient-free optimization framework written in Python
高级语言: Python
项目地址: git://github.com/100/Solid.git
创建时间: 2017-06-12T05:02:08Z
项目社区:https://github.com/100/Solid

开源协议:MIT License

下载





Build Status
MIT License

Solid is a Python framework for gradient-free optimization.

It contains basic versions of many of the most common optimization algorithms that do not require the calculation of gradients, and allows for very rapid development using them.

It’s a very versatile library that’s great for learning, modifying, and of course, using out-of-the-box.

See the detailed documentation here.


Current Features:


Usage:

  • pip install solidpy
  • Import the relevant algorithm
  • Create a class that inherits from that algorithm, and that implements the necessary abstract methods
  • Call its .run() method, which always returns the best solution and its objective function value

Example:

  1. from random import choice, randint, random
  2. from string import lowercase
  3. from Solid.EvolutionaryAlgorithm import EvolutionaryAlgorithm
  4. class Algorithm(EvolutionaryAlgorithm):
  5. """
  6. Tries to get a randomly-generated string to match string "clout"
  7. """
  8. def _initial_population(self):
  9. return list(''.join([choice(lowercase) for _ in range(5)]) for _ in range(50))
  10. def _fitness(self, member):
  11. return float(sum(member[i] == "clout"[i] for i in range(5)))
  12. def _crossover(self, parent1, parent2):
  13. partition = randint(0, len(self.population[0]) - 1)
  14. return parent1[0:partition] + parent2[partition:]
  15. def _mutate(self, member):
  16. if self.mutation_rate >= random():
  17. member = list(member)
  18. member[randint(0,4)] = choice(lowercase)
  19. member = ''.join(member)
  20. return member
  21. def test_algorithm():
  22. algorithm = Algorithm(.5, .7, 500, max_fitness=None)
  23. best_solution, best_objective_value = algorithm.run()

Testing

To run tests, look in the tests folder.

Use pytest; it should automatically find the test files.


Contributing

Feel free to send a pull request if you want to add any features or if you find a bug.

Check the issues tab for some potential things to do.