This an implementation of Gaining-sharing knowledge algorithm (GSK) in python. GSK is a nature inspired algorithm for solving real parameter optimization problems. GSK has two main stages the junior and senior phases each has a different mutation, the dimensions (or parameters) are changed by the mutations of both the junior and senior phases. at the same time. GSK is a reliable and stable optimization algorithm. The repository also includes a visualization module for visualizing GSK runs. The code have been tested on CEC 2017 benchmark functions. The module provide a testbed optimization framework that is easy to use with GSK.
Examples
To run GSK on CEC 2017 or CEC 2020 benchmark functions use run.py example NOTE: the compiled binaries of functions only work in Linux environment
$ python run.py
❤️ How to use GSK as a solver
An objective function of 10 dimensions with -100, 100 as lower and upper bounds Just define your objective_function to have x (numpy array of shape (pop size, dim)) and func_args any function arguments required.
def ackley(x,func_args=[20,0.2,2*pi]):
#The objective function should take x
x = np.asarray_chkfinite(x) # ValueError if any NaN or Inf
a= func_args[0]
b= func_args[1]
c=func_args[2]
n = len(x[0])
s1 = sum( x**2 ,axis=1)
s2 = sum( cos( c * x ),axis=1)
return -a*exp( -b*sqrt( s1 / n )) - exp( s2 / n ) + a + exp(1)
from GSKpy.BasicGSK import BasicGSK
solver = BasicGSK(objective_function,10,100,[-100]*10,[-100]*10,max_nfes=100000)
g, best , best_fit, errors = solver.run()
you can also use the get_statstics functions and Viz (visualization class) after the run
from GSKpy.viz import Viz
vis = Viz(ackley,-100,100,dim,func_args=[20,0.2,2*pi])
best_hist,fitness_vals, best, middle, worst,junior_dim = solver.getstatistics()
best_hist = np.array(best_hist)
best_hist = np.vstack((best_hist))
best_hist = best_hist.reshape((best_hist.shape[0],dim))
vis.set(dim,best_hist,fitness_vals,best,middle,worst)
vis.build_plot()
There is also an example on using GSK for linear regression using scikit-learn
📫 We would love to hear from you
If you have any comments or questions just email h.nomer@nu.edu.eg We intend to realse a pip package soon with more examples. More work is done to GSK as a solver for different optimization problems.
✅ Requirements
**python 2.7 or higher **matplotlib (for visualization) **CSVDataFrame (or any other package for saving results) **numpy
Metadata
Release files for GSKpy 1.4.0
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 |
|---|---|---|---|---|
| GSKpy-1.4.0.tar.gz | 12.5 kB | Without provenance | Details for GSKpy-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| GSKpy-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for GSKpy-1.4.0-py3-none-any.whl |
Total release size: 26.8 kB
Release files / GSKpy-1.4.0.tar.gz
| Download URL | GSKpy-1.4.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d435ef206425af68aa2f4194f324411a9e4be35c1a88c35702e880a802ac643d
|
|
BLAKE2b-256 checksum How to use checksums |
d1043c5b8f15b723b47d1be8f35da875465ddd6aae1028e9f59d8b27c01ff423
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / GSKpy-1.4.0-py3-none-any.whl
| Download URL | GSKpy-1.4.0-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3be479e9ad74b9a2b728b3c8e29ab32286795fe6d81cc0e167bfefc56f00cd62
|
|
BLAKE2b-256 checksum How to use checksums |
7a577d3ca66fb4bb1f09960cbf785e26d0e5ceb9e7b697dd09bf4e3a18b01421
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for GSKpy 1.4.0
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.