Exemple #1
0
    def test_large_output_iter(self):
        scml = SCML(max_iter=1, output_iter=2)
        triplets = np.array([[[0, 1], [2, 1], [0, 0]]])
        msg = ("The value of output_iter must be equal or smaller than"
               " max_iter.")

        with pytest.raises(ValueError) as raised_error:
            scml.fit(triplets)
        assert msg == raised_error.value.args[0]
Exemple #2
0
    def test_int_inputs(self, name):
        value = 1.0
        d = {name: value}
        scml = SCML(**d)
        triplets = np.array([[[0, 1], [2, 1], [0, 0]]])

        msg = ("%s should be an integer, instead it is of type"
               " %s" % (name, type(value)))
        with pytest.raises(ValueError) as raised_error:
            scml.fit(triplets)
        assert msg == raised_error.value.args[0]
Exemple #3
0
def test_raise_big_number_of_features():
    triplets, _, _, X = build_triplets(with_preprocessor=False)
    triplets = triplets[:3, :, :]
    estimator = SCML(n_basis=320)
    set_random_state(estimator)
    with pytest.raises(ValueError) as exc_info:
        estimator.fit(triplets)
    assert exc_info.value.args[0] == \
           "Number of features (4) is greater than the number of triplets(3)." \
           "\nConsider using dimensionality reduction or using another basis " \
           "generation scheme."
Exemple #4
0
 def test_dimension_reduction_msg(self):
     scml = SCML(n_basis=2)
     triplets = np.array([[[0, 1], [2, 1], [0, 0]], [[2, 1], [0, 1], [2,
                                                                      0]],
                          [[0, 0], [2, 0], [0, 1]], [[2, 0], [0, 0], [2,
                                                                      1]]])
     msg = ("The number of bases with nonzero weight is less than the "
            "number of features of the input, in consequence the "
            "learned transformation reduces the dimension to 1.")
     with pytest.warns(UserWarning) as raised_warning:
         scml.fit(triplets)
     assert msg == raised_warning[0].message.args[0]
Exemple #5
0
    # anyways
    c, target = shuffle(c, target, random_state=SEED)
    if with_preprocessor:
        # if preprocessor, we build a 2D array of quadruplets of indices
        return Dataset(c, target, X, c[:, 0])
    else:
        # if not, we build a 3D array of quadruplets of samples
        return Dataset(X[c], target, None, X[c[:, 0]])


quadruplets_learners = [(LSML(), build_quadruplets)]
ids_quadruplets_learners = list(
    map(lambda x: x.__class__.__name__,
        [learner for (learner, _) in quadruplets_learners]))

triplets_learners = [(SCML(), build_triplets)]
ids_triplets_learners = list(
    map(lambda x: x.__class__.__name__,
        [learner for (learner, _) in triplets_learners]))

pairs_learners = [
    (ITML(max_iter=2), build_pairs),  # max_iter=2 to be faster
    (MMC(max_iter=2), build_pairs),  # max_iter=2 to be faster
    (SDML(prior='identity', balance_param=1e-5), build_pairs)
]
ids_pairs_learners = list(
    map(lambda x: x.__class__.__name__,
        [learner for (learner, _) in pairs_learners]))

classifiers = [(Covariance(), build_classification),
               (LFDA(), build_classification), (LMNN(), build_classification),