Пример #1
0
def _set_layer_random_parameters(layer, experiment_parameters):
    param_space = deepcopy(experiment_parameters.get_layer_parameters(layer.layer_type))
    if param_space is None:
        raise Exception('No parameters defined for layer %s' % layer.layer_type)
    param_space.update(layer.parameters)
    layer.parameters = {
        name: random_initial_param_value(param)
        for name, param in param_space.items()}
    layer.apply_constraints()
Пример #2
0
def _random_layout_row(layout, row_idx,
                       experiment_parameters, init_layer_parameters=False):
    blocks = random_initial_param_value(param=experiment_parameters.get_layout_parameter('blocks'))
    return Row([
        _random_layout_block(
            layout,
            row_idx,
            experiment_parameters,
            init_layer_parameters=init_layer_parameters)
        for _ in range(blocks)])
Пример #3
0
def _random_optimizer(optimizer, experiment_parameters):
    ref_parameters = experiment_parameters.get_optimizers_parameters()
    optimizer_id = optimizer.optimizer if optimizer else None
    if not optimizer_id:
        optimizers = list(ref_parameters.keys())
        optimizer_id = optimizers[rand.randint(0, len(optimizers) - 1)]
    if not optimizer_id in ref_parameters:
        raise Exception('Unknown optimizer id: "%s"' % optimizer_id)
    param_space = deepcopy(ref_parameters[optimizer_id])
    if optimizer:
        param_space.update(optimizer.parameters)
    parameters = {
        name: random_initial_param_value(param)
        for name, param in param_space.items()}
    return Optimizer(optimizer_id, parameters)
Пример #4
0
def _random_layout_block(layout, row_idx,
                         experiment_parameters, init_layer_parameters=False):
    if layout.block:
        return _instantiate_layout_block(
            layout,
            row_idx,
            experiment_parameters,
            init_layer_parameters=init_layer_parameters)
    layers = random_initial_param_value(experiment_parameters.get_layout_parameter('layers'))
    template = []
    for _ in range(layers):
        allowed_layers = get_allowed_new_block_layers(template, experiment_parameters)
        if len(allowed_layers) == 0:
            break
        new_layer = random_list_element(allowed_layers)
        template.append(new_layer)
    block = Block()
    _setup_block_input(layout, row_idx, block, experiment_parameters)
    block.layers += _create_template_layers(
        template,
        experiment_parameters,
        init_layer_parameters)
    return block
Пример #5
0
def _random_layout(layout, experiment_parameters):
    layout = Layout(
        layout.input_size,
        layout.output_size,
        layout.output_activation,
        layout.block)
    if experiment_parameters.is_layout_search():
        rows = random_initial_param_value(experiment_parameters.get_layout_parameter('rows'))
        for row_idx in range(rows):
            layout.rows.append(
                _random_layout_row(
                    layout,
                    row_idx,
                    experiment_parameters))
    else:
        layout.rows = [
            Row(blocks=[
                _instantiate_layout_block(
                    layout,
                    0,
                    experiment_parameters)])]
    if experiment_parameters.is_parameters_search():
        _set_layout_random_parameters(layout, experiment_parameters)
    return layout