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
is kept during the evolution process. In each iteration, the solution
is modified by adding a random vector
. In this way the new solution is modeled under the following expression:
Considering that the solution has d dimensions
, each coordinate is modified
by the random disturbance
modeled by a
Gaussian probability distribution defined as:
where and
, represent the standard deviation and the mean value,
respectively for dimension i. Since the value of
adds a modification around
, the mean value is considered zero
.
Once
has been calculated, it is tested whether the new position improves the quality of the previous solution
.
In this way, if the quality of
is better than
, the value of
is accepted as the new solution, otherwise
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.
Metadata
Release files for randomsearch 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| randomsearch-0.0.1.tar.gz | 2.7 kB | Without provenance | Details for randomsearch-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| randomsearch-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for randomsearch-0.0.1-py3-none-any.whl |
Total release size: 6.5 kB
Release files / randomsearch-0.0.1.tar.gz
| Download URL | randomsearch-0.0.1.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85ea625514d6a6996a097b910b60239f639e2673bbdedd9729ea556ad4219a37
|
|
BLAKE2b-256 checksum How to use checksums |
83b2c21dbbadc2b302eaebbe04b6d2f5df954137ee34153a6f03a4f2e8fa1c37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3
|
Release files / randomsearch-0.0.1-py3-none-any.whl
| Download URL | randomsearch-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ae671836b0eaa3ae8a6b2b74511714bf8be396c8d76696d41f69801611716b6
|
|
BLAKE2b-256 checksum How to use checksums |
aa25cfd8ffabd8bcedc5a97c12ddd61dc5aaa1f05c14284172c742c167c951a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3
|
Security for randomsearch 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.