Python
云桥落羽
这个作者很懒,什么都没留下…
展开
-
优化算法(一)粒子群算法
import numpy as np def pso(fitness, D=1, c1=2, c2=2, w=0.8, N=200, M=1000): # 函数返回待优化函数的最小值和对应的解 # fitness 表示待优化函数 # D 表示数据的维度 # c1,c2 表示学习因子 # w 表示惯性权重 # N 表示粒子数量 # M ...原创 2018-09-04 20:11:51 · 449 阅读 · 0 评论 -
优化算法(二)模拟退火算法
import numpy as np # 随机确定变化的方向 def direction2(): if np.random.random() > 0.5: return 1 return -1 # 随机确定是否接受较差的解 def direction3(delta, T): chance = np.exp(-1*delta/T) if ...原创 2018-09-04 21:30:09 · 289 阅读 · 0 评论 -
优化算法(五)元胞自动机
import numpy as np import matplotlib.pyplot as plt # 空间大小 number = 200 # 细胞分布 cells = np.zeros((number, number)) cells[int(number/2)][int(number/2)-1] = 1 cells[int(number/2)][int(number/2)] = 1 cel...原创 2018-09-07 20:29:54 · 5806 阅读 · 0 评论 -
优化算法(三)遗传算法
import numpy as np # 二进制基因编码转十进制 def conv_2_10(x): val = 0 for v in range(len(x)): if x[-1*(v+1)] == 1: val += 2 ** v return val # 十进制转二进制基因编码 def conv_10_2(x): ...原创 2018-09-05 15:59:01 · 216 阅读 · 0 评论 -
优化算法(四)蚁群算法
import numpy as np import matplotlib.pyplot as plt # 计算距离和 def distance_sum(point, distances): res = 0. for index in range(len(point)-1): res += distances[point[index]][point[index+1...原创 2018-09-06 17:18:31 · 732 阅读 · 0 评论