Giter Club home page Giter Club logo

100 / solid Goto Github PK

View Code? Open in Web Editor NEW
574.0 12.0 64.0 274 KB

๐ŸŽฏ A comprehensive gradient-free optimization framework written in Python

Home Page: https://100.github.io/Solid/

License: MIT License

Python 100.00%
metaheuristics optimization optimization-algorithms python algorithm library machine-learning machine-learning-algorithms artificial-intelligence stochastic-optimizers discrete-optimization continuous-optimization genetic-algorithm evolutionary-algorithm genetic-algorithm-framework simulated-annealing particle-swarm-optimization hill-climbing tabu-search harmony-search

solid's Introduction


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:

from random import choice, randint, random
from string import lowercase
from Solid.EvolutionaryAlgorithm import EvolutionaryAlgorithm


class Algorithm(EvolutionaryAlgorithm):
    """
    Tries to get a randomly-generated string to match string "clout"
    """
    def _initial_population(self):
        return list(''.join([choice(lowercase) for _ in range(5)]) for _ in range(50))

    def _fitness(self, member):
        return float(sum(member[i] == "clout"[i] for i in range(5)))

    def _crossover(self, parent1, parent2):
        partition = randint(0, len(self.population[0]) - 1)
        return parent1[0:partition] + parent2[partition:]

    def _mutate(self, member):
        if self.mutation_rate >= random():
            member = list(member)
            member[randint(0,4)] = choice(lowercase)
            member = ''.join(member)
        return member


def test_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.

solid's People

Contributors

100 avatar emre-e avatar fikisipi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solid's Issues

Numerical Stabilitity

It would be good to find all of the instances where the algorithms may be unstable and handle these cases appropriately (such as overflow). Some cases are handled, but there are probably more.

Better Testing?

Currently, the testing just makes sure that the algorithm runs without error on a toy problem.

It would be nice to do something more akin to unit testing, but I'm not quite sure how to do it in this situation since a lot of the testable functionality is provided by the user.

More Algorithms

Of course, more algorithms are always great.

Some suggestions:

  • Coordinate descent
  • Ant colony optimization
  • Differential evolution
  • Cuckoo search
  • Cross-entropy method

Simulated annealing: bug in run method

Description of the bug

The run() method of the SimulatedAnnealing class has a bug when the annealing method does not find a better state than the initial one.

When does it happens

The bug happens when the annealing algorithm fails to find a better state than the initial one. This can happen when the maximum number of steps is low or when the initial guess is already very good.

What is the current behaviour

The tuple returned by the run() method is (None, cost_of_initial_state).

How to fix

Add the line

self.best_state = deepcopy(self.current_state)

between L142 and L143.

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.