代码拉取完成,页面将自动刷新
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. 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型