def mutateLayer(self, individual): """ Mutate the given layer by randomly chosen mutation. """ layers = individual.conv_layers + individual.dense_layers # select layer random l = random.randint(0, len(layers) - 1) layer = layers[l] if type(layer) is Layer: mutfunc = roulette([ self.mutateSize, self.mutateDropout, self.mutateActivation, self.randomInit ], [ PROB_CHANGE_LAYER_SIZE, PROB_CHANGE_DROPOUT, PROB_CHANGE_ACTIVATION, PROB_CHANGE_ALL ]) if mutfunc: mutfunc(layer) elif type(layer) is ConvLayer: mutfunc = roulette([ self.mutateFilters, self.mutateKernelSize, self.mutateActivation, self.randomInit ], [ PROB_CHANGE_NUM_FILTERS, PROB_MUTATE_KERNEL_SIZE, PROB_CHANGE_CONV_ACTIVATION, PROB_CHANGE_CONV_ALL ]) if mutfunc: mutfunc(layer) elif type(layer) is MaxPoolLayer: self.mutatePoolSize(layer) else: raise (TypeError("unknown type of layer")) return individual,
def mutateSize(self, layer): mutfunc = roulette( [self.changeSize, self.addNeuron, self.delNeuron], [PROB_RANDOM_LAYER_SIZE, PROB_ADD_NEURON, PROB_DEL_NEURON]) if mutfunc: mutfunc(layer)
def createRandomLayer(): create = roulette([lambda: ConvLayer(), lambda: MaxPoolLayer()], [Config.CONV_LAYER, Config.MAX_POOL_LAYER]) if create: return create() else: return ConvLayer()
def mutateSize(self, layer): """ Mutates size of the layer, chooses randomly from relevant mutations. """ mutfunc = roulette( [self.changeSize, self.addNeuron, self.delNeuron], [PROB_RANDOM_LAYER_SIZE, PROB_ADD_NEURON, PROB_DEL_NEURON]) if mutfunc: mutfunc(layer)
def mutate(self, individual): mutfunc = roulette([self.mutateLayer, self.addLayer, self.delLayer], [PROB_MUTATE_LAYER, PROB_ADD_LAYER, PROB_DEL_LAYER]) if mutfunc: return mutfunc(individual) return individual,
def mutate(self, individual): """ Mutate the network with one randomly selected mutation. """ mutfunc = roulette([self.mutateLayer, self.addLayer, self.delLayer], [PROB_MUTATE_LAYER, PROB_ADD_LAYER, PROB_DEL_LAYER]) if mutfunc: return mutfunc(individual) return individual,
def mutate(self, individual): """ Selects mutation type at random and applies it. """ mutfunc = roulette([self.mutateLayer, self.addLayer, self.delLayer], [PROB_MUTATE_LAYER, PROB_ADD_LAYER, PROB_DEL_LAYER]) if mutfunc: return mutfunc(individual) return individual,
def createRandomLayer(): create = roulette([lambda: ConvLayer(), lambda: MaxPoolLayer()], [Config.CONV_LAYER, Config.MAX_POOL_LAYER]) if create: return create() else: return ConvLayer()
def createRandomLayer(): create = roulette([lambda: ConvLayer(), lambda: MaxPoolLayer()], [ config.global_config["network"]["conv_layer"], config.global_config["network"]["max_pool_layer"] ]) if create: return create() else: return ConvLayer()
def mutate(self, individual): mutfunc = roulette([self.mutateLayer, self.addLayer, self.delLayer], [PROB_MUTATE_LAYER, PROB_ADD_LAYER, PROB_DEL_LAYER]) if mutfunc: return mutfunc(individual) assert len(individual.layers) == len(individual.strategy.blocks) return individual,
def mutate(self, individual): mutfunc = roulette([self.mutateLayer, self.addLayer, self.delLayer], [PROB_MUTATE_LAYER, PROB_ADD_LAYER, PROB_DEL_LAYER]) if mutfunc: return mutfunc(individual) assert len(individual.layers) == len(individual.strategy.blocks) return individual,
def mutateLayer(self, individual): # select layer random l = random.randint(0, len(individual.layers)-1) layer = individual.layers[l] strategy = individual.strategy.blocks[l] mutfunc = roulette([self.mutateSize, self.mutateDropout, self.mutateActivation], [PROB_CHANGE_LAYER_SIZE, PROB_CHANGE_DROPOUT, PROB_CHANGE_ACTIVATION]) if mutfunc: mutfunc(layer, strategy, len(individual.layers)) return individual,
def mutateLayer(self, individual): # select layer random l = random.randint(0, len(individual.layers) - 1) layer = individual.layers[l] strategy = individual.strategy.blocks[l] mutfunc = roulette( [self.mutateSize, self.mutateDropout, self.mutateActivation], [ PROB_CHANGE_LAYER_SIZE, PROB_CHANGE_DROPOUT, PROB_CHANGE_ACTIVATION ]) if mutfunc: mutfunc(layer, strategy, len(individual.layers)) return individual,
def mutateLayer(self, individual): """ Selects random layer and applies randomly selected mutation on it. """ # select layer random l = random.randint(0, len(individual.layers) - 1) layer = individual.layers[l] mutfunc = roulette([ self.mutateSize, self.mutateDropout, self.mutateActivation, self.randomInit ], [ PROB_CHANGE_LAYER_SIZE, PROB_CHANGE_DROPOUT, PROB_CHANGE_ACTIVATION, PROB_CHANGE_ALL ]) if mutfunc: mutfunc(layer) return individual,