Example #1
0
def test_fextractor_indices_with_channel_number():
    ex = pipeline.FeatureExtractor(
        [('rand', _RandomMultipleFeature(features_per_channel=2)),
         ('0', _NthSampleFeature(0))],
        n_channels=2)
    assert ex.channel_indices == {'0': (0, 2, 4), '1': (1, 3, 5)}
    assert ex.feature_indices == {'rand': (0, 1, 2, 3), '0': (4, 5)}
Example #2
0
def test_fextractor_indices_no_arguments_inferred():
    ex = pipeline.FeatureExtractor(
        [('rand', _RandomMultipleFeature(features_per_channel=2)),
         ('0', _NthSampleFeature(0))])
    data = np.array([[0, 1, 2, 3, 4],
                     [5, 6, 7, 8, 9]])
    ex.process(data)
    assert ex.channel_indices == {'0': (0, 2, 4), '1': (1, 3, 5)}
    assert ex.feature_indices == {'rand': (0, 1, 2, 3), '0': (4, 5)}
Example #3
0
def test_fextractor_indices_with_names():
    ex = pipeline.FeatureExtractor(
        [('rand', _RandomMultipleFeature(features_per_channel=2)),
         ('0', _NthSampleFeature(0))],
        channel_names=['channel_1', 'channel_2'])
    assert ex.channel_indices == {
        'channel_1': (0, 2, 4),
        'channel_2': (1, 3, 5)}
    assert ex.feature_indices == {'rand': (0, 1, 2, 3), '0': (4, 5)}
Example #4
0
def test_fextractor_clear():
    ex = pipeline.FeatureExtractor([('0', _NthSampleFeature(0)),
                                    ('1', _NthSampleFeature(2))])
    data_2ch = np.array([[0, 1, 2, 3, 4],
                         [5, 6, 7, 8, 9]])
    data_1ch = np.array([[0, 1, 2, 3, 4]])

    assert_array_equal(np.array([0, 5, 2, 7]), ex.process(data_2ch))
    ex.clear()
    assert_array_equal(np.array([0, 2]), ex.process(data_1ch))
Example #5
0
def test_fextractor_simple():
    f0 = _NthSampleFeature(0)
    ex = pipeline.FeatureExtractor([('0', f0),
                                    ('1', _NthSampleFeature(1))])
    data = np.array([[0, 1, 2, 3, 4],
                     [5, 6, 7, 8, 9]])

    assert_array_equal(np.array([0, 5, 1, 6]), ex.process(data))
    assert_array_equal(np.array([0, 5, 1, 6]), ex.process(data))

    assert ex.feature_indices['0'] == (0, 2)
    assert ex.feature_indices['1'] == (2, 4)

    assert ex.named_features['0'] is f0
Example #6
0
def test_feature_selector():
    fe = pipeline.FeatureExtractor(
        [('N0', _NthSampleFeature(0)),
         ('N2', _NthSampleFeature(2))],
        n_channels=3)
    fs = pipeline.FeatureSelector(
        features=['N2'],
        feature_indices=fe.feature_indices)
    pipe = pipeline.Pipeline([fe, fs])
    data = np.array([[0, 1, 2, 3, 4],
                     [5, 6, 7, 8, 9],
                     [10, 11, 12, 13, 14]])
    truth = np.array([2, 7, 12])
    assert_array_equal(truth, pipe.process(data))
Example #7
0
def test_channel_selector():
    fe = pipeline.FeatureExtractor(
        [('0', _NthSampleFeature(0)),
         ('2', _NthSampleFeature(2))],
        channel_names=['channel_1', 'channel_2', 'channel_3'])
    cs = pipeline.ChannelSelector(
        channels=['channel_1', 'channel_3'],
        channel_indices=fe.channel_indices)
    pipe = pipeline.Pipeline([fe, cs])
    data = np.array([[0, 1, 2, 3, 4],
                     [5, 6, 7, 8, 9],
                     [10, 11, 12, 13, 14]])
    truth = np.array([0, 10, 2, 12])
    assert_array_equal(truth, pipe.process(data))
Example #8
0
def test_fextractor_unequal_feature_sizes():
    ex = pipeline.FeatureExtractor([('0', _NthSampleFeature(0)),
                                    ('1', _NthSampleFeature(2, channel=1))])
    data = np.array([[0, 1, 2, 3, 4],
                     [5, 6, 7, 8, 9]])
    assert_array_equal(np.array([0, 5, 7]), ex.process(data))
Example #9
0
def test_fextractor_indices_no_arguments():
    ex = pipeline.FeatureExtractor(
        [('rand', _RandomMultipleFeature(features_per_channel=2)),
         ('0', _NthSampleFeature(0))])
    assert ex.channel_indices == {}
    assert ex.feature_indices == {}