实数的染色体表示?

发布于 2024-09-26 21:42:36 字数 443 浏览 1 评论 0原文

我正在尝试使用遗传算法解决问题。

问题是找到优化函数的积分和实数值集。

我需要使用二进制字符串来表示问题(仅仅是因为当应用于二进制字符串染色体时,我更好地理解交叉/突变等概念)。

候选解 S 是集合 {I1, I2, ... IN, R1, R2, RM },

其中 I 变量是整数,R 变量是浮点数。

我希望能够将候选解 S 转换为二进制字符串,但我不知道如何对浮点数进行编码。

关于如何将集合 S 编码到染色体中,有什么想法吗?

尽管该解决方案应该与语言无关,但我首选的语言(按此特定任务的偏好降序排列)是:

Python、C++、C

顺便说一句,我正在使用 Pyevolve

I am trying to solve a problem using genetic algorithms.

The problem is to find the set of integral and real values that optimizes a function.

I need to represent the problem using a binary string (simply because I understand the concept of crossover/mutation etc much better when applied to binary string chromosomes).

A candidate solution S would be the set {I1, I2, ... IN, R1, R2, RM }

Where the I variables are integers and the R variables are floating point numbers.

I want to be able to transform the candidate solution S into a binary string, but I don't know how to encode the floating point numbers.

Any ideas on how to encode the set S into a chromosome?

Although the solution is supposed to be language agnostic, my prefered choice of language (in decreasing order of preference for this particular task) is:

Python, C++, C

BTW, I am coding the problem using Pyevolve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

东走西顾 2024-10-03 21:42:36

不,我认为二进制表示对于您的问题来说是错误的。你的基础数据不是二进制的,那么,为什么要使用二进制呢?对实数和整数进行变异和交叉,而不是对它们的二进制表示。

最简单的交叉:第一个父代:ABCDE,其中 A、B、... 是浮点数,第二个父代 MNOPQ。随机选择D,第一个春天:ABCDQ,第二个:MNOPE。

No, I think that binary representation is wrong for your problem. Your basic data is not binary, so, why use binary? Do mutation and crossover on real and integer numbers, not on their binary representation.

Simplest crossover: first parent: ABCDE where A, B, ... are floating points numbers, second parents MNOPQ. Choose randomly D, first spring: ABCDQ, second: MNOPE.

娇柔作态 2024-10-03 21:42:36

我建议您重新考虑是否确实需要位字符串表示形式。从浮点到位再转换回来的转换可能有点多。如果您可以只使用浮点值,即单个解决方案候选是 N 个浮点数的数组,您可以轻松地将其传递给您的评估函数(目标函数)。然后使用交叉方法,如模拟二进制交叉(SBX,http:// www.slideshare.net/paskorn/self-adaptive-simulated-binary-crossover-presentation)它模仿了将浮点数转换为二进制表示并对其执行交叉后得到的效果。 SBX 的结果非常好,并且一段时间后,如果您处理位字符串,将会发生什么的类比变得非常清楚.. 它看起来像这张幻灯片中的很多内容.. 但这一切都归结为几行实现 sbx 交叉。

i would suggest rethinking if you actually need the bit string representation.. the conversion from float to bit and back is a bit much maybe. if you could just stay with floating point values i.e. a single solution candidate is an array of N floats you can pass that easily to your evaluation function (objective function). then use crossover methods like simulated binary crossover (SBX, http://www.slideshare.net/paskorn/self-adaptive-simulated-binary-crossover-presentation) which mimics the effects you'd get after converting your floats to a binary representation and performing crossover on that. the results of SBX are pretty good and also the analogy to what woudl happen if you'd deal with bit strings becomes pretty clear after a while.. it looks like much in this slideshow.. but it all comes down to just a few lines of implementing the sbx crossover.

眼趣 2024-10-03 21:42:36

您可以使用 struct 模块中提供的功能将二进制数据打包到缓冲区中。 : http://docs.python.org/library/struct.html

请参阅此处 说,我个人喜欢Python,但是:如果你想重复有效地获取一组整数和浮点数,将其视为一个大位串,并对其应用按位变异,我不认为Python是最好的选择对于一种语言。这在较低级语言中更加简单(并且快速)——我会选择 C。

祝算法好运!

You can pack binary data into buffers with the facilities provided in the struct module. See here: http://docs.python.org/library/struct.html

That said, I personally love Python, BUT: if you want to repeatedly and efficiently take a set of integers and floating point numbers, treat it as one big bitsring, and apply bitwise mutation to it, I don't think Python is the best choice for a language. This is much more straightforward (and fast) in lower-level languages -- I'd go for C.

Good luck with the algorithm!

春风十里 2024-10-03 21:42:36

浮点数使用 IEEE754 表示形式,整数使用二进制补码表示形式。或者,使用整数和浮点数,因为您的计算机已经在幕后使用这些二进制表示形式,因此很安全。

Use IEEE754 representation for floating-point numbers and two's complement representation for integers. Or, use integers and floating-point numbers, safe in the knowledge that behind the scenes your computer is already using these binary representations.

缱倦旧时光 2024-10-03 21:42:36

如果我正确理解这个问题,这完全与语言无关。您应该能够用标准化 IEEE 表示法来表示浮点数。这是一个教程

一旦你有了这种表示,你就不知道什么是什么了,你只需将任何交叉(单点、双点等)应用到你的位上。

If I understand the problem correctly, this is completely language agnostic. You should be able to represent the floating point number in the standardized IEEE representation. Here's a tutorial.

Once you have that representation you don't what is what, you just apply whatever crossover (single, double point whatever) to your bits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文