[ML] Genetic Algorithm 理论概述

Genetic Algorithm 遗传算法:
遗传算法受到达尔文自然选择理论的启发,以遗传/变异/择优的策略进行机器学习进程。

核心算法逻辑:

# Copyright:CMPUT 296, University of Alberta
# Pseudocode 伪代码
population = initialize populationSize random points
time = 0
while avg or best (F(population))<threshold and time<maxTime:
	time++
	MutatePopulation(population)
	population += CrossoverPopulation(population) 
	population = Reduce(population, populationSize)
return best (F(population))

其内容一般包括:
(此处伪代码以2D游戏环境举例,参考地牢游戏设定,包括B=障碍物,P=全体玩家,K=钥匙,M=怪兽,L=门锁)

Fitness Func*(适配函数:检测空间设定有效性,非必须存在)
e.g. 游戏环境下是否有有效路径抵达出口,是否有玩家生成于此,是否符合环境设定等

# Pseudocode 伪代码
fitnessFunc(P, K, L, B, M) {
    bool isValid = true;
    if (P != null):
        return 0;
    for (p in P):
        if (K or L in p.neighbors) or (L in K.neighbors):
            isValid = false;
            continue;
       Apply A* algorithm to find the possible pathes (from p.position to K) & (from K to L), if fails:
            isValid = false;
            continue;
    if (isValid):
        return 1.0;
    else return 0;
} 

Mutation Func(突变函数:在原有点位的邻点或特定空间范围内移动)
e.g. 由P(x, y, z) 移动至P‘(x+1, y+1, z+1)

# Pseudocode 伪代码
mutationFunc(P) {
    for (p in P):
        for (neighborCell in neighborCells around p):
               if (neighborCell is empty):
                   C.add(neighborCell);
            mutation = random(C, 1);
            p.position = mutation;
    return P;
}```

CrossOver Func(继承函数/跨域函数:针对某两个或多个点位,使用曼哈顿距离或其他距离计算算法获取两点的中位,并在此位置放置新的Agent)

```python
# Pseudocode 伪代码
crossoverFunc(P) {
    for (p1 in P):
       for (p2 in P):
            newX = min(p1.position.X, p2.position.X) + abs(p1.position.X - p2.position.X);
            newY = min(p1.position.Y, p2.position.Y) + abs(p1.position.Y - p2.position.Y);
            pNew = new player;    // compute coordination & create player in next generations 
            pNew.position = (newX, newY);
            if (pNew not in P):
                P.add(pNew);
    return P
}

算法优点:

  1. 可控性强,可以认为设定其中的遗传/突变策略以更好的获取优化;
  2. 具备贪婪算法(GreedySearch)和随机漫步(RandomWalk)的全部优势;
  3. 算法效率待补充;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值