Python implementation algorithm
Project description
=========
slapy
=========
1. install
pip install -r requirements.txt
#. dirs
1. graph
#. swarm
a. pso(v0.0.1+)
b. ga(v0.0.1+)
#. gso(v0.0.2+)
#. fa(v0.0.3+)
#. quick use
1. pso
def fun(vars):
# fitness function
x, y = vars
if 1 <= x <= 2 * np.pi and 1 <= y <= np.pi:
return np.cos(x) + np.sin(x) - x * y
else:
return -2 - 4 * np.pi ** 2 # return a small float number can not reach
if __name__ == '__main__':
engine = PSOEngine(vmax=0.01, bound=[[1, 2 * np.pi]], min_fitness_value=-1, dim=2, fitness_function=fun, steps=100)
engine.run()
x, y = engine.gbest.indv
print('max value', fun(engine.gbest.indv))
print('x:', x, 'y:', y)
#. gso
def fun(vars):
# fitness function
x, y = vars
if 0 <= x <= 2 * np.pi and 0 <= y <= 2 * np.pi:
return -np.cos(x) - np.sin(y) + 10
else:
return -10 # return a small float number can not reach
if __name__ == '__main__':
engine = GSOEngine(vmax=0.01, bound=[[0, 2 * np.pi]], rs=1, min_fitness_value=np.inf, dim=2, l0=1, fitness_function=fun,
steps=30)
engine.run()
x, y = engine.gbest.indv
print('max value', fun(engine.gbest.indv))
print('x:', x, 'y:', y)
slapy
=========
1. install
pip install -r requirements.txt
#. dirs
1. graph
#. swarm
a. pso(v0.0.1+)
b. ga(v0.0.1+)
#. gso(v0.0.2+)
#. fa(v0.0.3+)
#. quick use
1. pso
def fun(vars):
# fitness function
x, y = vars
if 1 <= x <= 2 * np.pi and 1 <= y <= np.pi:
return np.cos(x) + np.sin(x) - x * y
else:
return -2 - 4 * np.pi ** 2 # return a small float number can not reach
if __name__ == '__main__':
engine = PSOEngine(vmax=0.01, bound=[[1, 2 * np.pi]], min_fitness_value=-1, dim=2, fitness_function=fun, steps=100)
engine.run()
x, y = engine.gbest.indv
print('max value', fun(engine.gbest.indv))
print('x:', x, 'y:', y)
#. gso
def fun(vars):
# fitness function
x, y = vars
if 0 <= x <= 2 * np.pi and 0 <= y <= 2 * np.pi:
return -np.cos(x) - np.sin(y) + 10
else:
return -10 # return a small float number can not reach
if __name__ == '__main__':
engine = GSOEngine(vmax=0.01, bound=[[0, 2 * np.pi]], rs=1, min_fitness_value=np.inf, dim=2, l0=1, fitness_function=fun,
steps=30)
engine.run()
x, y = engine.gbest.indv
print('max value', fun(engine.gbest.indv))
print('x:', x, 'y:', y)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for snowland_algorithm-0.0.4a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddee155647feb4048ecdfa2b76ca803321313c51940860ae828a740c454cfe0a |
|
MD5 | d7b9359092843dcfcffcb14700d9dbb8 |
|
BLAKE2b-256 | 7f0b94fdf19e570df2a2cf63460254c8f98df85348c6df919ae8ec2798f18b51 |