简体   繁体   English

适应度函数遗传算法中的随机元素

[英]Random element in fitness function genetic algorithm

So I am using a genetic algorithm to train a feedforward neural network, tasked with recognizing a function given to the genetic algorithm. 因此,我正在使用一种遗传算法来训练前馈神经网络,其任务是识别赋予遗传算法的功能。 Ie x = x**2 or something more complicated obviously. 即x = x ** 2或更明显地更复杂。

I realized I am using random inputs in my fitness function, which causes the fitness to be somewhat random for a member of the population, however, still in line with how close it is to the given function obviously. 我意识到我在适应度函数中使用了随机输入,这使适应度对于一部分人口来说是随机的,但是,显然仍与给定函数有多接近。 A colleague remarked that it is stranged that the same member of the population doesnt always get the same fitness, which I agree is a little unconventional. 一位同事指出,奇怪的是,同一批人并不总是具有同样的健康状况,我同意这有点不合常规。 However, it got me thinking, is there any reason why this would be bad for the genetic algorithm? 但是,这让我开始思考,对于遗传算法来说,这有什么不好的理由吗? I actually think it might be quite good because it enables me to have a rather small testset, speeding up number of generations while still avoiding overfitting to any given testest. 我实际上认为这可能会很好,因为它使我拥有一个相当小的测试集,可以加快世代的生成,同时又可以避免过度拟合任何给定的测试集。

Does anyone have experience with this? 有人对此有经验吗?

(fitness function is MSE compared to given function, for a randomly generated testset of 10 iterations) (对于给定的函数,针对10次迭代的随机生成的测试集,适应度函数为MSE)

A consistent fitness value is necessary for efficient progression of your evolutionary algorithm. 为了使进化算法高效进行,必须具有一致的适应性值。 Imagine the extreme case: if fitness evaluation for your candidates is always 100% random, then your algorithm will perform random search (which is not efficient). 想象一个极端的情况:如果对候选人的适应性评估始终是100%随机的,那么您的算法将执行随机搜索(效率不高)。

If your fitness evaluation is not consistent, it usually means you have not successfully abstracted the meaning of "value" in your problem (and this is sometimes hard!) or it may be the result of random factors (more similar to what I understand from your description). 如果您的适应性评估不一致,则通常意味着您没有成功抽象出问题中“价值”的含义(有时很难!),或者可能是随机因素的结果(与我从中了解的更相似)您的描述)。 These are often countered by averaging. 这些通常通过平均来抵消。

If, in your case, those random inputs are truly and advantage, consider having some averaging, which might make fitness evaluation more consistent, even though slower. 如果在您的情况下,这些随机输入确实是一种优势,请考虑进行平均,这可能会使适应性评估更加一致,即使速度较慢。

But, in short, slow evaluations are not good (you are right about that) and neither are inconsistent fitness values. 但是,总而言之,缓慢的评估并不好(您对此是正确的),并且两者的适应性值都不矛盾。 In the end, feel free to find your own balance. 最后,随时找到自己的平衡点。

Edit based on the comments: 根据评论进行编辑

Imagine the task where an artificial neural network (ANN) has to reproduce a function, for example f(x) = x (where the ANN only has one input, x, and one output, f(x), but perhaps many hidden units needed for more complex cases). 想象一下一个任务,其中人工神经网络(ANN)必须重现一个函数,例如f(x)= x(其中ANN只有一个输入x和一个输出f(x),但也许有许多隐藏单元需要更复杂的案例)。

We could imagine testing for fitness using always a set of points, eg, test f(x) for x = {0.2, 0.4, 0.6, 0.8}. 我们可以想象总是使用一组点进行适合性测试,例如,对于x = {0.2,0.4,0.6,0.8}的测试f(x)。 The closer f(x) is to the expected f(x) = x in each case, the higher the fitness. 在每种情况下,f(x)越接近期望的f(x)= x,则适用性越高。 This will be consistent, but may result in overfitting, as the image shows: 如图所示,这将是一致的,但可能会导致过度拟合:

过度拟合示例

The solution is very good close to the test points, but unpredictable elsewhere. 该解决方案非常接近测试点,但是在其他地方则无法预测。 The search algorithm will likely be efficient because of the consistent evaluation, but results may not be good. 由于一致性评估,搜索算法可能很有效,但结果可能不好。

An alternative approach is to use a random set of test points every iteration, eg, x = {0.13, 0.19, 0.56, 0.99}. 一种替代方法是在每次迭代中使用一组随机的测试点,例如x = {0.13,0.19,0.56,0.99}。 Because the test points are different every time, the result must be good everywhere. 因为每次测试点都不相同,所以结果在每个地方都必须是好的。 The downside is inconsistent evaluation, as shown in the image: 缺点是评估不一致,如图所示:

评估不一致

The same candidate solution seems good with the test set A, and quite bad for the test set B. Under this conditions the search algorithm may be more inefficient, but the solution will be better in the range of values we want. 对于测试集A,相同的候选解决方案看起来不错,而对于测试集B则相当糟糕。在这种情况下,搜索算法可能效率更低,但在我们想要的值范围内,解决方案会更好。

Depending on our specific case we can improve things by having more iterations, by having larger test sets (better average) or by trying intermediate solutions. 根据我们的具体情况,我们可以通过进行更多的迭代,通过使用更大的测试集(更好的平均值)或尝试中间解决方案来改善性能。 For example, one might consider testing always for three random points, where the first is always between 0 and 1/3, the second between 1/3 and 2/3, and the third between 2/3 and 1. The possibilities are really endless and the better choice will depend on each problem. 例如,一个人可能考虑始终对三个随机点进行测试,其中第一个总是在0到1/3之间,第二个总是在1/3到2/3之间,第三个在2/3到1之间。永无止境,更好的选择取决于每个问题。

Note that many tasks will not have this problem at all. 请注意 ,许多任务根本不会出现此问题。 For example, in the classic XOR we only need to test for {X1 = 0, X2 = 0; 例如,在经典XOR中,我们只需要测试{X1 = 0,X2 = 0; X1 = 1, X2 = 0; X1 = 1,X2 = 0; X1 = 0, X2 = 1; X1 = 0,X2 = 1; X1 = 1, X2 = 1}. X1 = 1,X2 = 1}。 Of course it will be fast to test all four cases! 当然,测试所有四种情况将很快!

Normally you use a seed for genetic algorithms, which should be fixed. 通常,您为遗传算法使用种子,该种子应固定。 It will always generate the same "random" childs sequentially, which makes your approach reproducible. 它将始终按顺序生成相同的“随机”子级,这使您的方法可重复。 So the genetic algorithm is kind of pseudo-random. 因此,遗传算法是一种伪随机算法。 That is state of art how to perform genetic algorithms. 这是如何执行遗传算法的最新技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这是否被认为是遗传算法的适应度 function? - Is this considered a fitness function for a genetic algorithm? 使用遗传算法的 rsi 健身 function - fitness function for rsi using genetic algorithms 我的上一代 g.netic 算法没有提高健身分数 - My genetic algorithm in last generation not improve fitness score 如何在多处理deap python遗传算法中添加最大或最小适应性停止条件 - how to add max(or min) fitness halting condition to multiprocessing deap python genetic algorithm f(x)= x 中的个数。 找到 g.netic 算法的最高和平均适应度,替代选项 Map 并减少 python - f(x)= number of ones in x . find the highest and average fitness for genetic algorithm , Alternate option to Map and reduce in python 在函数中使用遗传算法(局部) - 最小化函数 - Using genetic algorithm in a function (locally) - minimizing function 用离散值最小化函数的遗传算法 - Genetic Algorithm to Minimize Function using Discrete Values 如何为遗传算法编写交叉 function - how to write a crossover function for genetic algorithm Python - 遗传算法变异函数不起作用 - Python - Genetic Algorithm mutation function is not working 这是遗传算法吗? - Is this a genetic algorithm?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM