English 中文(简体)
轮轮轮轮轮轮轮选择程序
原标题:Roulette Wheel selection procedure

是否可以使用健身价值来评估人口中的每个人,而不会发现以下假代码的概率:

For all members of population
    sum += fitness ( member)
End for 
Loop until new population is full 
      Do this twice 
            Number = Random between 0 and sum
            Currentfitness = 0.0
            For each member in population
               Currentfitness += fitness (member)
               if Number > Currentfitness then select member
            End for 
      End
Create offspring 
End loop

代码的下一部分是做什么的?

Do this twice

我真的搞不懂轮轮轮轮轮如何选择双亲。有什么可以帮忙的吗?

最佳回答

代码意在选择随机元素,但概率取决于一定的重量。

示例:

  • We want to select from a two-element array with the following weights: { 1, 9 }
  • The cumulative weight is { 1, 10 }
  • The total weight is 10
  • We choose a random number between 1 and 10
  • We look into the cumulative weight array and find the first index where our random number is greater than the element
  • This index is the index of the randomly chosen element

直观地说,这个例子是有道理的:随机数字的十倍中有九倍在1到9之间,导致第一个元素的概率为0.9(正视规定的重量)。

问题回答

数字应小于/强小于当前,否则会严重偏向第一人口成员。

示例:

  • Consider weights {1, 2, 7}
  • Cumulative weights {1, 3, 10}
  • Total weight 10
  • Choose random double between 0 and 10 with r.NextDouble(10.0)
  • 90% of time 1 is chosen with given pseudo code. Should be 10%




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签