本文整理汇总了Python中genotypes.Genotype方法的典型用法代码示例。如果您正苦于以下问题:Python genotypes.Genotype方法的具体用法?Python genotypes.Genotype怎么用?Python genotypes.Genotype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genotypes
的用法示例。
在下文中一共展示了genotypes.Genotype方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def genotype(self):
def _parse(probs):
gene = []
start = 0
for i in range(STEPS):
end = start + i + 1
W = probs[start:end].copy()
j = sorted(range(i + 1), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[0]
k_best = None
for k in range(len(W[j])):
if k != PRIMITIVES.index('none'):
if k_best is None or W[j][k] > W[j][k_best]:
k_best = k
gene.append((PRIMITIVES[k_best], j))
start = end
return gene
gene = _parse(F.softmax(self.weights, dim=-1).data.cpu().numpy())
genotype = Genotype(recurrent=gene, concat=range(STEPS+1)[-CONCAT:])
return genotype
示例2: parse_results
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def parse_results(results, n_nodes):
concat = range(2, 2 + n_nodes)
normal_gene = []
reduction_gene = []
for i in range(n_nodes):
normal_node = []
reduction_node = []
for j in range(2 + i):
normal_key = 'normal_n{}_p{}'.format(i + 2, j)
reduction_key = 'reduce_n{}_p{}'.format(i + 2, j)
normal_op = results[normal_key].cpu().numpy()
reduction_op = results[reduction_key].cpu().numpy()
if sum(normal_op == 1):
normal_index = np.argmax(normal_op)
normal_node.append((PRIMITIVES[normal_index], j))
if sum(reduction_op == 1):
reduction_index = np.argmax(reduction_op)
reduction_node.append((PRIMITIVES[reduction_index], j))
normal_gene.append(normal_node)
reduction_gene.append(reduction_node)
genotypes = Genotype(normal=normal_gene, normal_concat=concat,
reduce=reduction_gene, reduce_concat=concat)
return genotypes
示例3: parse_arch
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def parse_arch(arch):
arch = list(map(int, arch.split()))
lenth = len(arch) // 2
recurrent = []
concat = [i for i in range(lenth+1)]
ACT = {
0: 'tanh',
1: 'relu',
2: 'identity',
3: 'sigmoid'
}
for i in range(lenth):
pre_node = arch[2*i]
activation = ACT[arch[2*i+1]]
recurrent.append((activation, pre_node))
"""
if pre_node in concat:
concat.remove(pre_node)"""
concat = range(1, lenth+1)
return Genotype(recurrent=recurrent, concat=concat)
示例4: get_genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def get_genotype(self, force=False):
if force:
gene_normal = self.parse_gene_force(self.normal_candidate_flags,
self.normal_selected_idxs,
self.alphas_normal)
gene_reduce = self.parse_gene_force(self.reduce_candidate_flags,
self.reduce_selected_idxs,
self.alphas_reduce)
else:
gene_normal = self.parse_gene(self.normal_selected_idxs)
gene_reduce = self.parse_gene(self.reduce_selected_idxs)
n = 2
concat = range(n + self._steps - self._multiplier, self._steps + n)
genotype = Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat
)
return genotype
示例5: genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def genotype(self):
gene_normal = gt.parse(self.alpha_normal, k=2)
gene_reduce = gt.parse(self.alpha_reduce, k=2)
concat = range(2, 2+self.n_nodes) # concat all intermediate nodes
return gt.Genotype(normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat)
示例6: genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def genotype(self):
def _parse(weights):
gene = []
n = 2
start = 0
for i in range(self._steps):
end = start + n
W = weights[start:end].copy()
edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
for j in edges:
k_best = None
for k in range(len(W[j])):
if k != PRIMITIVES.index('none'):
if k_best is None or W[j][k] > W[j][k_best]:
k_best = k
gene.append((PRIMITIVES[k_best], j))
start = end
n += 1
return gene
gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy())
gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy())
concat = range(2+self._steps-self._multiplier, self._steps+2)
genotype = Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat
)
return genotype
示例7: parse_network
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def parse_network(switches_normal, switches_reduce):
def _parse_switches(switches):
n = 2
start = 0
gene = []
step = 4
for i in range(step):
end = start + n
for j in range(start, end):
for k in range(len(switches[j])):
if switches[j][k]:
gene.append((PRIMITIVES[k], j - start))
start = end
n = n + 1
return gene
gene_normal = _parse_switches(switches_normal)
gene_reduce = _parse_switches(switches_reduce)
concat = range(2, 6)
genotype = Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat
)
return genotype
示例8: get_genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def get_genotype(self, force=False):
if force:
gene_normal = self.parse_gene_force(self.normal_candidate_flags,
self.normal_selected_idxs,
self.alphas_normal)
else:
gene_normal = self.parse_gene(self.normal_selected_idxs)
n = 2
concat = range(n + self._steps - self._multiplier, self._steps + n)
genotype = Genotype(
normal=gene_normal, normal_concat=concat
)
return genotype
示例9: get_genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def get_genotype(self, force=False):
if force:
gene_normal = self.parse_gene_force(self.normal_candidate_flags,
self.normal_selected_idxs,
self.alphas_normal)
else:
gene_normal = self.parse_gene(self.normal_selected_idxs)
n = 2
concat = range(n + self._steps - self._multiplier, self._steps + n)
genotype = Genotype(normal=gene_normal, normal_concat=concat)
return genotype
示例10: genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def genotype(self):
def _parse(weights,weights2):
gene = []
n = 2
start = 0
for i in range(self._steps):
end = start + n
W = weights[start:end].copy()
W2 = weights2[start:end].copy()
for j in range(n):
W[j,:]=W[j,:]*W2[j]
edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
#edges = sorted(range(i + 2), key=lambda x: -W2[x])[:2]
for j in edges:
k_best = None
for k in range(len(W[j])):
if k != PRIMITIVES.index('none'):
if k_best is None or W[j][k] > W[j][k_best]:
k_best = k
gene.append((PRIMITIVES[k_best], j))
start = end
n += 1
return gene
n = 3
start = 2
weightsr2 = F.softmax(self.betas_reduce[0:2], dim=-1)
weightsn2 = F.softmax(self.betas_normal[0:2], dim=-1)
for i in range(self._steps-1):
end = start + n
tw2 = F.softmax(self.betas_reduce[start:end], dim=-1)
tn2 = F.softmax(self.betas_normal[start:end], dim=-1)
start = end
n += 1
weightsr2 = torch.cat([weightsr2,tw2],dim=0)
weightsn2 = torch.cat([weightsn2,tn2],dim=0)
gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy(),weightsn2.data.cpu().numpy())
gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy(),weightsr2.data.cpu().numpy())
concat = range(2+self._steps-self._multiplier, self._steps+2)
genotype = Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat
)
return genotype
示例11: genotype
# 需要导入模块: import genotypes [as 别名]
# 或者: from genotypes import Genotype [as 别名]
def genotype(self):
def _parse(weights,weights2):
gene = []
n = 2
start = 0
for i in range(self._steps):
end = start + n
W = weights[start:end].copy()
W2 = weights2[start:end].copy()
for j in range(n):
W[j,:]=W[j,:]*W2[j]
edges = sorted(range(i + 2), key=lambda x: -max(W[x][k] for k in range(len(W[x])) if k != PRIMITIVES.index('none')))[:2]
#edges = sorted(range(i + 2), key=lambda x: -W2[x])[:2]
for j in edges:
k_best = None
for k in range(len(W[j])):
if k != PRIMITIVES.index('none'):
if k_best is None or W[j][k] > W[j][k_best]:
k_best = k
gene.append((PRIMITIVES[k_best], j))
start = end
n += 1
return gene
n = 3
start = 2
weightsr2 = F.softmax(self.betas_reduce[0:2], dim=-1)
weightsn2 = F.softmax(self.betas_normal[0:2], dim=-1)
for i in range(self._steps-1):
end = start + n
#print(self.betas_reduce[start:end])
tw2 = F.softmax(self.betas_reduce[start:end], dim=-1)
tn2 = F.softmax(self.betas_normal[start:end], dim=-1)
start = end
n += 1
weightsr2 = torch.cat([weightsr2,tw2],dim=0)
weightsn2 = torch.cat([weightsn2,tn2],dim=0)
gene_normal = _parse(F.softmax(self.alphas_normal, dim=-1).data.cpu().numpy(),weightsn2.data.cpu().numpy())
gene_reduce = _parse(F.softmax(self.alphas_reduce, dim=-1).data.cpu().numpy(),weightsr2.data.cpu().numpy())
concat = range(2+self._steps-self._multiplier, self._steps+2)
genotype = Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat
)
return genotype