并行遗传算法库pgapack的python包装器

PGA的Python项目详细描述


Author:Ralf Schlatterbeck <rsc@runtux.com>

pgapy是并行遗传算法库pgapack的包装器。 (参见pgapack Readme),一个强大的遗传算法库 D.Levine,阿贡国家数学和计算机科学部 实验室。库是用c编写的。pgapy将此库包装为 与python一起使用。原来的pgapack库已经很旧了,但是 是一个最完整和准确的(和快速,虽然这不是 我最关心的是把它包装成python)遗传算法 有很多关于 实验。它还显示了非常少的错误 多年来。它通过消息支持并行执行 除了正常的“串行”版本外,还传递接口MPI。那是 为什么我也想在python中使用它。

目前没有太多关于pgapy的文档。 你真的,绝对需要阅读下面的文档 使用pgapack-当然你需要pgapack库。

原始的pgapack库仍然可以从pgapack下载 ftp站点,它是用ansi c编写的,因此应该在大多数 平台。注意,这个版本并没有得到很好的维护。我已经 启动了一个pgapack fork on github,在那里我将库移植到 最新版本的MPI标准,并修复了一些次要的 文件不一致。

我只在Linux上测试过PGAPY,目前不提供Windows 版本。你也可以找到我的pgapack fork on github这个 repository在git和 包含有关支持较新MPI版本和 文件更新。我还在git存储库中包含了补丁 软件包的Debian维护者,Dirk Eddelbuettel。

对于debian linux发行版,pgapack包含在oldstable中 (杰西),你仍然可以在当前的稳定版本中安装这个 (伸展)。此版本尚未包含更新的MPI的修复程序 版本和文档更新。

对于debian,预构建的文档位于 /usr/share/doc/pgapack/user_guide.ps.gz

为了让你开始,我在 examples,例如,one-max.py实现了“maxbit”示例 类似于pgapack文档中的一个。这些例子受到启发 由《python中的遗传算法》一书撰写,但都是白手起家 也不包括书中的任何代码。这些例子说明 几点:

  • Your class implementing the genetic algorithm needs to inherit from pga.PGA (pga is the PGAPy wrapper module).
  • You need to define an evaluation function called ^{tt4}$ that returns a number indicating the fitness of the gene given with the parameters ^{tt5}$ and ^{tt6}$ that can be used to fetch allele values from the gene using the ^{tt7}$ method, for more details refer to the pgapack documentation.
  • You can define additional functions overriding built-in functions of the pgapack library, illustrated by the example of ^{tt8}$. Note that we could call the original print_string method of our PGA superclass. In the same way you can implement, e.g., your own crossover method.
  • The constructor of the class needs to define the Gene type, in the examples we use int and bool built-in datatypes.
  • The length of the gene needs to be given in the constructor.
  • We often want to maximize the numbers returned by our evaluation function, set the parameter ^{tt9}$ to False if you want to minimize.
  • We can define an array of init values, each entry containing a sequence with lower and upper bound. The array has to have the length of the gene. Note that the upper bound is included in the range of possible values (unlike the python range operator but compatible with the pgapack definition).
  • In the constructor of the class we can add parameters of the genetic algorithm. Not all parameters of pgapack are wrapped yet, currently you would need to consult the sourcecode of PGAPy to find out which parameters are wrapped. In the example we define several print options.
  • Finally the genetic algorithm is started with the ^{tt10}$ method.

pgapy中的命名约定

当您扩展pgapy时-请记住,并非pgapack的所有函数都是 包装好了,您可能需要额外的功能-您应该坚持 更改时的命名约定。 包装器使用了以下命名约定:

  • Constants of pgapack like ^{tt11}$ are used as-is in uppercase. These constants can be directly imported from the wrapper module. Not all constants are wrapped so far, if you need more, add them to the constdef array in pgamodule.c and send me a patch.
  • For methods of the pga.PGA class I’ve removed the ^{tt12}$ prefix used throughout pgapack and converted the method to lowercase with underscores between uppercase words in the original function name, so ^{tt13}$ becomes ^{tt10}$, ^{tt15}$ becomes ^{tt16}$.
  • Where possible I’ve made a single class method where pgapack needs a separate function for each datatype, so ^{tt17}$, ^{tt18}$, ^{tt19}$, ^{tt20}$ all become ^{tt7}$. Same holds true for ^{tt22}$.
  • Internal method names in the wrapper program have a leading PGA_ — so the class method ^{tt22}$ is implemented by the C-function ^{tt24}$ in ^{tt25}$.

缺少功能

如前所述,并非pgapack的所有函数和常量都是 已包装-对于许多应用程序,给定的集合应该是 够了。如果需要其他函数,可以将这些 send给我一块补丁。

pgapack的另一个特性目前没有在包装器中实现, 自定义数据类型的使用。使用pgapack,您可以定义自己的 数据类型及其自定义的遗传实现 算法功能,如交叉,变异等,我不期望 不过,在实现这些方面存在问题。

报告错误

请使用Sourceforge Bug TrackerGithub Bug Tracker

  • give a short description of what you think is the correct behaviour
  • give a description of the observed behaviour
  • tell me exactly what you did.
  • if you can publish your source code this makes it a lot easier to debug for me

资源

项目信息和下载自Sourceforge main page

或者从Github

或者直接通过pypi安装。

更改

版本0.3:功能增强,错误修复

端口到python3,python2仍受支持,许可证更改。

  • C-Code of wrapper updated to support both, Python2 and Python3
  • Update documentation
  • Fix some memory leaks that could result when errors occurred during some callback methods
  • License change: We now have the 2-clause BSD license (similar to the MPICH license of pgapack), this used to be LGPL.

版本0.2:功能增强,错误修复

64位支持,包装了更多的pgapack函数和属性, 自述文件更新:SourceForge徽标,更改章节。

  • Bug-fixes for 64 bit architectures
  • More functions and attributes of pgapack wrapped
  • Add a build-rule to setup.py to allow building for standard-install of pgapack — this currently needs editing of setup.py — should use autodetect here but this would require that I set up a machine with standard install of pgapack for testing.
  • Add Sourceforge logo as required
  • Add Changes chapter for automagic releases

版本0.1:iniTial FreshMeat公告

pgapy是并行遗传算法库pgapack的包装器, 一个强大的遗传算法库。pgapy包装此库以供使用 和Python一起。pgapack是最完整和准确的基因之一 算法实现有很多特性 实验。

  • Initial Release

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
交换数组中重复值的位置(Java)   java搜索使用百分比匹配Elasticsearch SpringBoot中的文本   java Spring JPA和按输入字段排序   java我在输入CSV时出错了   java如何在RecyclerView中精确显示5项   使用java安全吗。util。servlet中的计时器?   使用Cp1252编码的java比较字符串   javafx打包java桌面应用程序,并引用开源许可证   java Spring和Camel CXF在战争中表现出色   java当EJB客户端失去与应用服务器的连接时,是否存在可以捕获的异常?   更改字符串值的java注释   java如何在sharedperfernce中保存自定义数组列表   RequestResponseLink:当使用java客户端读取队列时,Azure服务总线上RequestResponseLink到“$cbs”的内部发送链接因错误而关闭