Code Monkey home page Code Monkey logo

pythonpso's Introduction

PythonPSO

Short and sweet particle swarm optimization implementation in python

Requirements

  • python 3
  • numpy

Example Usage

Minimize function:

def simple_error_function(args):
    return args[0]+args[1]

number_of_parameters = 2
max_iterations = 100
best_parameters, best_error_score = particle_swarm_optimize(simple_error_function,
                                        number_of_parameters, max_iterations)

returns the best found parameters and it's score for that function

Custom parameter weight initialization:

def simple_error_function(args):
    return args[0]+args[1]

def parameter_init():
    return random.random()*0.5-10

number_of_parameters = 2
max_iterations = 100
best_parameters, best_error_score = particle_swarm_optimize(simple_error_function, number_of_parameters,
                                        max_iterations, weight_init, parameter_init=parameter_init)

Other arguments

  • stopping_error: float = 0.001 # stop when we have a particle with this score
  • num_particles: int = 10 # number of particles to run
  • max_iterations_without_improvement: int = 10 # stop when we have this many consecutive turns without improvement
  • c1: float = 2.0 # c1 PSO parameter
  • c2: float = 2.0 # c1 PSO parameter

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.