提交 bc4be43e 编写于 作者: 郭飞

bug: #34 ASFS, ASFA, AFSA

上级 c39706d9
......@@ -22,7 +22,7 @@ script:
- coverage run -p examples/demo_sa_tsp.py examples/data/nctu.csv
- coverage run -p examples/demo_aca_tsp.py
- coverage run -p examples/demo_ia.py
- coverage run -p examples/demo_asfs.py
- coverage run -p examples/demo_afsa.py
- coverage run -p examples/demo_pso_ani.py
- coverage run -p examples/demo_de.py
......
......@@ -451,19 +451,19 @@ print('best routine:', best_points, 'best_distance:', best_distance)
![IA](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/ia2.png?raw=true)
## 7. artificial fish swarm algorithm (AFSA)
-> Demo code: [examples/demo_asfs.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_asfs.py#L1)
## 7. Artificial Fish Swarm Algorithm (AFSA)
-> Demo code: [examples/demo_afsa.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_afsa.py#L1)
```python
def func(x):
x1, x2 = x
return 1 / x1 ** 2 + x1 ** 2 + 1 / x2 ** 2 + x2 ** 2
from sko.ASFA import ASFA
from sko.AFSA import AFSA
asfa = ASFA(func, n_dim=2, size_pop=50, max_iter=300,
afsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,
max_try_num=100, step=0.5, visual=0.3,
q=0.98, delta=0.5)
best_x, best_y = asfa.run()
best_x, best_y = afsa.run()
print(best_x, best_y)
```
......@@ -32,10 +32,6 @@ cd scikit-opt
pip install .
```
## News:
All algorithms will be available on ~~/Spark/Pytorch~~ **TensorFlow** on version ~~0.4~~ **1.x**, getting parallel performance.
Have fun!
### Feature1: UDF
......@@ -92,10 +88,9 @@ print('best_x:', best_x, '\n', 'best_y:', best_y)
```
> Until Now, the **udf** surport `crossover`, `mutation`, `selection`, `ranking` of GA
> scikit-opt provide a dozen of operators, see [here](https://github.com/guofei9987/scikit-opt/tree/master/sko/operators)
> For advanced users, there is another OOP style:
For advanced users:
-> Demo code: [examples/demo_ga_udf.py#s6](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L31)
```python
......@@ -118,8 +113,11 @@ my_ga = MyGA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -
best_x, best_y = my_ga.run()
print('best_x:', best_x, '\n', 'best_y:', best_y)
```
### feature2: GPU computation
We are developing GPU computation, which will be stable on version 1.0.0
An example is already available: [https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_gpu.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_gpu.py)
### feature2: continue to run
### feature3: continue to run
(New in version 0.3.6)
Run an algorithm for 10 iterations, and then run another 20 iterations base on the 10 iterations before:
```python
......@@ -433,19 +431,19 @@ print('best routine:', best_points, 'best_distance:', best_distance)
![IA](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/ia2.png?raw=true)
## 7. artificial fish swarm algorithm (AFSA)
-> Demo code: [examples/demo_asfs.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_asfs.py#L1)
## 7. Artificial Fish Swarm Algorithm (AFSA)
-> Demo code: [examples/demo_afsa.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_afsa.py#L1)
```python
def func(x):
x1, x2 = x
return 1 / x1 ** 2 + x1 ** 2 + 1 / x2 ** 2 + x2 ** 2
from sko.ASFA import ASFA
from sko.AFSA import AFSA
asfa = ASFA(func, n_dim=2, size_pop=50, max_iter=300,
afsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,
max_try_num=100, step=0.5, visual=0.3,
q=0.98, delta=0.5)
best_x, best_y = asfa.run()
best_x, best_y = afsa.run()
print(best_x, best_y)
```
......@@ -420,19 +420,19 @@ print('best routine:', best_points, 'best_distance:', best_distance)
## 7. 人工鱼群算法
人工鱼群算法(artificial fish swarm algorithm, AFSA)
-> Demo code: [examples/demo_asfs.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_asfs.py#L1)
-> Demo code: [examples/demo_afsa.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_afsa.py#L1)
```python
def func(x):
x1, x2 = x
return 1 / x1 ** 2 + x1 ** 2 + 1 / x2 ** 2 + x2 ** 2
from sko.ASFA import ASFA
from sko.AFSA import AFSA
asfa = ASFA(func, n_dim=2, size_pop=50, max_iter=300,
afsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,
max_try_num=100, step=0.5, visual=0.3,
q=0.98, delta=0.5)
best_x, best_y = asfa.run()
best_x, best_y = afsa.run()
print(best_x, best_y)
```
......@@ -3,10 +3,10 @@ def func(x):
return 1 / x1 ** 2 + x1 ** 2 + 1 / x2 ** 2 + x2 ** 2
from sko.ASFA import ASFA
from sko.AFSA import AFSA
asfa = ASFA(func, n_dim=2, size_pop=50, max_iter=300,
afsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,
max_try_num=100, step=0.5, visual=0.3,
q=0.98, delta=0.5)
best_x, best_y = asfa.run()
best_x, best_y = afsa.run()
print(best_x, best_y)
......@@ -96,7 +96,7 @@ from scipy import spatial
# return self.best_X, self.best_Y
# %%
class ASFA:
class AFSA:
def __init__(self, func, n_dim, size_pop=50, max_iter=300,
max_try_num=100, step=0.5, visual=0.3,
q=0.98, delta=0.5):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册