Beispiel #1
0
def test_remapping_2():
    # here, we test a little more complex example, first obs is the
    # relvant one: it would get out-(0,2) but out-0 has not enough
    # obs., so it must get out-(1,3) instead.
    obs = np.array([[1, 1, 1, 1, 1],\
                    [1, 1, 1, 0, 1],\
                    [1, 1, 0, 1, 0],\
                    [1, 0, 0, 1, 0],\
                    [0, 0, 0, 0, 1],\
                    [1, 1, 1, 0, 0]], dtype=np.int8)
    mm = np.array([[0, 1, 0, 1, 1],\
                   [1, 0, 0, 0, 1],\
                   [1, 0, 1, 0, 0],\
                   [0, 1, 1, 0, 0],\
                   [0, 0, 0, 0, 1]])
    res1 = [[1, 0, 1, 0, 0],\
            [0, 1, 0, 1, 0],\
            [0, 0, 0, 0, 0],\
            [0, 0, 0, 0, 0],\
            [0, 0, 0, 0, 1],\
            [0, 0, 1, 0, 0]]

    assert map_features_smin(obs, mm, 1).toarray().tolist() == res1

    # here, we have enough obs for out-1 (withough looking at obs-0)
    # already:
    res2 = [[0, 1, 0, 1, 0],
            [0, 1, 0, 1, 0],\
            [0, 0, 0, 0, 0],\
            [0, 0, 0, 0, 0],\
            [0, 0, 0, 0, 0],\
            [0, 0, 0, 1, 0]]
    assert map_features_smin(obs, mm, 2).toarray().tolist() == res2
Beispiel #2
0
def test_map_features_smin(rand_spm):
    """
    test the remapping function of map_features_smin with random inputs
    """
    for rep in range(1):
        print("Rep", rep, "of random map_features_smin test.")
        indicator_matrix = rand_int8_spm(20, 5, 0.1)
        indicator_matrix = make_valid_indicator_matrix(indicator_matrix)
        mf0 = map_features(rand_spm, indicator_matrix)
        smin = int(np.median(mf0.sum(axis=0).tolist()))
        mf_rust = map_features_smin(rand_spm, indicator_matrix, smin)
        # mf_py = PureMapper(indicator_matrix) \
        #     .map_features_smin(rand_spm, smin).tocsr()
        # assert_eq_spm(mf_rust, mf_py)
        assert (np.vectorize(lambda x: x == 0 or x >= smin)(
            mf_rust.sum(axis=0))).all()
Beispiel #3
0
def test_remapping_1(indicator_matrix):
    """
    test the remapping function of map_features_smin with deterministic
    inputs
    """
    obs = np.array([[1, 1, 1, 1, 1], \
                    [1, 1, 1, 1, 0], \
                    [1, 1, 0, 1, 0], \
                    [1, 0, 0, 1, 0], \
                    [0, 0, 0, 0, 1]], dtype=np.int8)
    mf2 = map_features_smin(obs, indicator_matrix, 2)
    # the first observation shall now have the last output-feature
    # assigned instead of the first one
    assert mf2.toarray().tolist() == [[False, True, True, True], \
                                      [False, True, True, False], \
                                      [False, True, False, False], \
                                      [False, False, False, False], \
                                      [False, False, False, True]]
Beispiel #4
0
def test_map_features(rand_spm, indicator_matrix):
    mf0 = map_features_smin(rand_spm, indicator_matrix, 0)
    mf = map_features(rand_spm, indicator_matrix)
    assert_eq_spm(mf, mf0)
Beispiel #5
0
 def test_map_features_example1(example1):
     obs, mm = example1
     mf00 = map_features(obs, mm)
     mf0 = map_features_smin(obs, mm, 0)
     assert_eq_spm(mf00, mf0)
     map_features_smin(obs, mm, 10)