(self, architecture: Architecture, mutation_rate: float = 0.1)
| 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)) |
no test coverage detected