コード例 #1
0
def test_select_sample_size_none(seed_random):
    # Default to size smaller than number of samples

    input_matrix, target_matrix = datasets.get_random_classification(
        1000, 1, 2)

    new_inp_matrix, new_tar_matrix = base.select_sample(
        input_matrix, target_matrix)

    assert len(new_inp_matrix) < len(input_matrix)
    assert len(new_inp_matrix) == base._selection_size_heuristic(
        len(input_matrix))

    assert len(new_tar_matrix) < len(input_matrix)
    assert len(new_tar_matrix) == base._selection_size_heuristic(
        len(input_matrix))
コード例 #2
0
def _check_obj_and_obj_jac_match(make_model_func, classification=False):
    """obj and obj_jac functions should return the same obj value."""
    attrs = random.randint(1, 10)
    outs = random.randint(1, 10)
    model = make_model_func(attrs, random.randint(1, 10), outs)

    if classification:
        dataset = datasets.get_random_classification(10, attrs, outs)
    else:
        dataset = datasets.get_random_regression(10, attrs, outs)

    # Don't use exactly the same parameters, to ensure obj functions are actually
    # using the given parameters
    parameters = random.uniform(-1.0,
                                1.0) * mlp._flatten(model._weight_matrices)
    assert helpers.approx_equal(
        mlp._mlp_obj(model, dataset[0], dataset[1], parameters),
        mlp._mlp_obj_jac(model, dataset[0], dataset[1], parameters)[0])