def _mutate_layout_rows(layout, parameters): current_rows = len(layout.get_rows()) new_rows = mutate_param( parameters.get_layout_parameter('rows'), current_rows) if new_rows > current_rows: for row_idx in range(current_rows, new_rows): layout.rows.append( _random_layout_row( layout, row_idx, parameters, init_layer_parameters=True)) else: while len(layout.get_rows()) > new_rows: idx = rand.randint(0, len(layout.rows) - 1) layout.rows = [ r for i, r in enumerate(layout.rows) if i != idx]
def _mutate_layout_layers(layout, parameters): row = random_list_element(layout.rows) block = random_list_element(row.blocks) current_layers = len(block.get_layers()) new_layers = mutate_param( parameters.get_layout_parameter('layers'), current_layers) if new_layers > current_layers: for _ in range(current_layers, new_layers): layers = get_allowed_new_block_layers(block.layers, parameters) block.layers += _create_template_layers( [random_list_element(layers)], parameters, init_layer_parameters=True) else: while len(block.layers) > new_layers: idx = rand.randint(0, len(block.layers) - 1) block.layers = [ l for i, l in enumerate(block.layers) if i != idx]
def _mutate_layout_blocks(layout, parameters): row = random_list_element(layout.rows) row_idx = layout.rows.index(row) current_blocks = len(row.get_blocks()) new_blocks = mutate_param( parameters.get_layout_parameter('blocks'), current_blocks) if new_blocks > current_blocks: for _ in range(current_blocks, new_blocks): row.blocks.append( _random_layout_block( layout, row_idx, parameters, init_layer_parameters=True)) else: while len(row.blocks) > new_blocks: idx = rand.randint(0, len(row.blocks) - 1) row.blocks = [ b for i, b in enumerate(row.blocks) if i != idx]
def _mutate_optimizer(optimizer, parameters, p_mutate_param=0.1): param_space = deepcopy(parameters.get_optimizer_parameters(optimizer.optimizer)) for name, value in optimizer.parameters.items(): if rand.random() < p_mutate_param: optimizer.parameters[name] = mutate_param(param_space[name], value)
def _mutate_layer(layer, parameters, p_mutate_param=0.1): param_space = deepcopy(parameters.get_layer_parameters(layer.layer_type)) for name, value in layer.parameters.items(): if rand.random() < p_mutate_param: layer.parameters[name] = mutate_param(param_space[name], value) layer.apply_constraints()