Skip to content

angelgaspar/randomsearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random search algorithm

A simple n-dimensional random search algorithm.

Introduction

The Random search algorithm was the first method that based its optimization strategy on a stochastic process. Only one solution equation is kept during the evolution process. In each iteration, the solution equation is modified by adding a random vector equation . In this way the new solution is modeled under the following expression:

equation

Considering that the solution equation has d dimensions equation , each coordinate is modified equation by the random disturbance equation modeled by a Gaussian probability distribution defined as:

equation

where equation and equation, represent the standard deviation and the mean value, respectively for dimension i. Since the value of equation adds a modification around equation , the mean value is considered zero equation .

Once equation has been calculated, it is tested whether the new position improves the quality of the previous solution equation. In this way, if the quality of equation is better than equation, the value of equation is accepted as the new solution, otherwise equation remains unchanged.

Installation

GitHub

To install this library from GitHub run the following commands in the terminal:

$ git clone https://github.com/angelgaspar/randomsearch.git
$ cd randomsearch
$ python setup.py install

PyPi

If you have pip installed run the following commands in the terminal:

$ pip install randomsearch

Usage

This is an usage example:

import randomsearch as rs


def your_function(x):
    return -(x[0] ** 2 + x[1] ** 2) + 4


a, b = rs.optimize(function=your_function, dimensions=2, lower_boundary=[-14, -14], upper_boundary= [10, 10], max_iter=10000, maximize=True)
print(a, ",", b)
Note: The optimize function returns the best fitness and the best solution.
If you want to minimize a function maximize should be False.