1 Star 0 Fork 2

赵广志/snowland-algorithm-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.rst 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
A.Star 提交于 2018-10-05 04:05 +08:00 . 1. 增加AOE网络python实现

slapy

1. install from pypi:

pip install snowland-algorithm

or from source code:

download code from https://gitee.com/hoops/snowland-algorithm-python, you can choose a release version pip install -r requirements.txt python setup.py install
  1. dirs
    1. graph
      1. dijkstra(v0.0.1+)
      2. spfa(v0.0.1+)
    2. swarm
      1. pso(v0.0.1+)
      2. gso(v0.0.2+)
      3. fa(v0.0.3+)
      4. cso(v0.0.6+)
      5. ba(v0.0.6+)
      6. sfla(v0.0.6+)
      7. bas(v0.0.6+)
      8. sa(v0.0.6+)
      9. fwa(v0.0.6+)
  2. quick use

    1. import package >>> from slapy.swarm.package_name import engine_name 2. define the fitness function example:

    >>> fun = lambda x: np.cos(x[0]) + np.sin(x[0]) - x[0] * x[1]
    

    note: arg need to be 1 X n vector 3. run the model >>> engine = engine_name(your_args) >>> engine.run() 4. show result >>> x, y = engine.gbest.chromosome >>> print('max value', fun(engine.gbest.chromosome)) >>> print('x:', x, 'y:', y) There is a example for 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.chromosome
    >>>    print('max value', fun(engine.gbest.chromosome))
    >>>    print('x:', x, 'y:', y)
    
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zgzwelldone/snowland-algorithm-python.git
git@gitee.com:zgzwelldone/snowland-algorithm-python.git
zgzwelldone
snowland-algorithm-python
snowland-algorithm-python
master

搜索帮助