MCPcopy Index your code
hub / github.com/geekcomputers/Python / mutate

Method mutate

ML/src/python/neuralforge/nas/search_space.py:127–143  ·  view source on GitHub ↗
(self, architecture: Architecture, mutation_rate: float = 0.1)

Source from the content-addressed store, hash-verified

125 return nn.ReLU(inplace=True)
126
127 def mutate(self, architecture: Architecture, mutation_rate: float = 0.1) -> Architecture:
128 new_genome = []
129
130 for gene in architecture.genome:
131 if random.random() < mutation_rate:
132 if gene.get('type') == 'pooling':
133 gene = gene.copy()
134 gene['pooling_type'] = random.choice(self.pooling_types)
135 else:
136 gene = gene.copy()
137 gene['type'] = random.choice(self.layer_types)
138 gene['channels'] = random.choice(self.channels)
139 gene['activation'] = random.choice(self.activation_types)
140
141 new_genome.append(gene)
142
143 return Architecture(new_genome)
144
145 def crossover(self, parent1: Architecture, parent2: Architecture) -> Architecture:
146 min_len = min(len(parent1.genome), len(parent2.genome))

Callers 1

create_offspringMethod · 0.80

Calls 4

ArchitectureClass · 0.85
getMethod · 0.45
copyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected