资源简介
遗传算法的python实现(二进制编码),适用于python3.x环境,有详细的注释和两个给出的测试函数。
代码片段和文件信息
import numpy as np
import matplotlib.pyplot as plt
from math import sincospiceillog
from mpl_toolkits.mplot3d import axes3d
from functools import reduce
from itertools import accumulate
from bisect import bisect_right
from copy import deepcopy
import warnings
warnings.filterwarnings(‘error‘)
def select_fun_lunpan(individuals):
‘‘‘
选出双亲,根据适应度值,每次只选出一对。
父系为选择较优个体,母系可以认为是随机选择
‘‘‘
‘‘‘
初始化赌轮
‘‘‘
#归一化每个个体的适应度值
fitness =[indv.fitness for indv in individuals]
min_fitness = min(fitness)
fitness = [(f - min_fitness) for f in fitness]
#创建赌轮
sum_fitness = sum(fitness)
if sum_fitness == 0:
wheel = list(accumulate([1/len(fitness) for f in range(len(fitness))]))
else:
wheel = list(accumulate([f/sum_fitness for f in fitness]))
#选择合适的双亲
father_idx = bisect_right(wheel np.random.uniform(0wheel[-1]))
father = individuals[father_idx]
rand_idx = np.random.randint(
- 上一篇:DSP2812 SCI通信例程
- 下一篇:易语言:批量生成随机姓名源码
相关资源
- iBATIS实战.pdf
- zw_new_smile-7110337-ImageAnimationTest.zip
- zw_jhn199388-9911706-基于51单片机都_自动
- zw_fan7983377-9600053-RecyclerViewDemo.zip
- zw_CHINA__.zip
- 我的第一本算法书+算法图解.zip
- 数学物理方法_德顾樵编著_2012.01_545页
- zw_WKTConvert.zip
- tdxw.exe
- zw_LabVIEW_8.20程序设计从入门到精通.
- zw_20170105220330215.zip
- unlocker-master最新版.rar
- Nginx核心知识100讲全套课件.zip
- navicat.11.2.16.premium_cs_x64破解版.zip
- 凸优化_Boyd_王书宁译.rar
- 云盘.rar
- Xshell5.exe
- 20170121135652618.rar
- DiskGenius4.7.0专业版.rar
- AlphaControlsv11.16StableFullSource(D5和D10
- 雅奇880官方开源赠品30多个雅奇4.rar
- 2009_LabVIEW编程样式_清晰版.pdf
- tiger_newhu5.99.24.zip
- 大数据架构详解:从数据获取到深度
- 程序是怎样跑起来的_PDF电子书带书签
- MongodbSample.rar
- EtherCATSlaveStackCodeTool5.12.rar
- 重构_改善既有代码的设计.rar
- 矩阵分析与应用第二版高清带书签.
- 通达网络智能办公系统OfficeAnywhere20
评论
共有 条评论