Skip to content

Commit

Permalink
docs: complete for v0.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Mar 27, 2021
1 parent 26164eb commit 3c69c11
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ 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)

## feature3: continue to run
## feature2: 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 All @@ -153,6 +150,21 @@ ga.run(10)
ga.run(20)
```

## feature3: 4-ways to accelerate
- [x] vectorization
- [x] multithreading
- [x] multiprocessing
- [x] cached

see [https://github.com/guofei9987/scikit-opt/blob/master/examples/example_function_modes.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/example_function_modes.py)



## feature4: 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)


# Quick start

## 1. Differential Evolution
Expand Down Expand Up @@ -227,19 +239,24 @@ ga = GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, lb=[-1, -1], ub=[1, 1
best_x, best_y = ga.run()
print('best_x:', best_x, '\n', 'best_y:', best_y)

```
print(ga)
# # %% Plot the result
# import pandas as pd
# import matplotlib.pyplot as plt
#
# Y_history = pd.DataFrame(ga.all_history_Y)
# fig, ax = plt.subplots(2, 1)
# ax[0].plot(Y_history.index, Y_history.values, '.', color='red')
# Y_history.min(axis=1).cummin().plot(kind='line')
# plt.show()

a=1
if a!=1 :
print(1)```

**Step3**: plot the result
-> Demo code: [examples/demo_ga.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga.py#L21)
-> Demo code: [examples/demo_ga.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga.py#LNone)
```python
import pandas as pd
import matplotlib.pyplot as plt

Y_history = pd.DataFrame(ga.all_history_Y)
fig, ax = plt.subplots(2, 1)
ax[0].plot(Y_history.index, Y_history.values, '.', color='red')
Y_history.min(axis=1).cummin().plot(kind='line')
plt.show()
```

![Figure_1-1](https://img1.github.io/heuristic_algorithm/ga_1.png)
Expand Down
19 changes: 14 additions & 5 deletions docs/en/speed_up.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Totally speaking, **vectorization** is much faster then **parallel**, which is f

To compare the speed of **common**, **vectorization**, **parallel**:

see [/examples/example_function_modes.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/example_function_modes.py)

```python
import numpy as np
Expand Down Expand Up @@ -82,9 +83,15 @@ for task_type in ('io_costly', 'cpu_costly'):
```

output:
>common mode, time costs: 5.284991
vector mode, time costs: 0.608695
parallel mode, time costs: 1.114424
>on io_costly task,use common mode, costs 5.116588s
on io_costly task,use multithreading mode, costs 3.113499s
on io_costly task,use multiprocessing mode, costs 3.119855s
on io_costly task,use vectorization mode, costs 0.604762s
on cpu_costly task,use common mode, costs 1.625032s
on cpu_costly task,use multithreading mode, costs 1.60131s
on cpu_costly task,use multiprocessing mode, costs 1.673792s
on cpu_costly task,use vectorization mode, costs 0.192595s


To compare the speed of **common** and **cached**:

Expand Down Expand Up @@ -119,7 +126,9 @@ print('cache mode, time costs: ', (datetime.datetime.now() - start_time).total_s
```

output:
>common mode, time costs: 6.29733
cache mode, time costs: 0.308823
>on io_costly task,use common mode, costs 6.120317s
on io_costly task,use cached mode, costs 1.106842s
on cpu_costly task,use common mode, costs 1.914744s
on cpu_costly task,use cached mode, costs 0.222713s


18 changes: 13 additions & 5 deletions docs/zh/speed_up.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

下面比较 **不加速****矢量化****多线程****多进程** 的性能:

see [/examples/example_function_modes.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/example_function_modes.py)

```python
import numpy as np
Expand Down Expand Up @@ -82,9 +83,14 @@ for task_type in ('io_costly', 'cpu_costly'):
```

output:
>common mode, time costs: 5.284991
vector mode, time costs: 0.608695
parallel mode, time costs: 1.114424
>>on io_costly task,use common mode, costs 5.116588s
on io_costly task,use multithreading mode, costs 3.113499s
on io_costly task,use multiprocessing mode, costs 3.119855s
on io_costly task,use vectorization mode, costs 0.604762s
on cpu_costly task,use common mode, costs 1.625032s
on cpu_costly task,use multithreading mode, costs 1.60131s
on cpu_costly task,use multiprocessing mode, costs 1.673792s
on cpu_costly task,use vectorization mode, costs 0.192595s


下面比较 **不加速****缓存化** 的性能
Expand Down Expand Up @@ -119,8 +125,10 @@ print('cache mode, time costs: ', (datetime.datetime.now() - start_time).total_s
```

output:
>common mode, time costs: 6.29733
cache mode, time costs: 0.308823
>on io_costly task,use common mode, costs 6.120317s
on io_costly task,use cached mode, costs 1.106842s
on cpu_costly task,use common mode, costs 1.914744s
on cpu_costly task,use cached mode, costs 0.222713s


## 算子优化加速
Expand Down

0 comments on commit 3c69c11

Please sign in to comment.