Skip to content

Commit

Permalink
bug: #34 ASFS, ASFA, AFSA
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Jan 31, 2020
1 parent c39706d commit bc4be43
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
22 changes: 10 additions & 12 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
```
8 changes: 4 additions & 4 deletions docs/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

6 changes: 3 additions & 3 deletions examples/demo_asfs.py → examples/demo_afsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion sko/ASFA.py → sko/AFSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
# 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):
Expand Down

0 comments on commit bc4be43

Please sign in to comment.