Skip to content

Repository files navigation


Build StatusMIT 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:

fromrandomimportchoice, randint, randomfromstringimportlowercasefromSolid.EvolutionaryAlgorithmimportEvolutionaryAlgorithmclassAlgorithm(EvolutionaryAlgorithm):
""" Tries to get a randomly-generated string to match string "clout" """def_initial_population(self):
returnlist(''.join([choice(lowercase) for_inrange(5)]) for_inrange(50))
def_fitness(self, member):
returnfloat(sum(member[i] =="clout"[i] foriinrange(5)))
def_crossover(self, parent1, parent2):
partition=randint(0, len(self.population[0]) -1)
returnparent1[0:partition] +parent2[partition:]
def_mutate(self, member):
ifself.mutation_rate>=random():
member=list(member)
member[randint(0,4)] =choice(lowercase)
member=''.join(member)
returnmemberdeftest_algorithm():
algorithm=Algorithm(.5, .7, 500, max_fitness=None)
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.