Exemple #1
0
def test_mapper_vs_zscore():
    """Test by comparing to results of elderly z-score function
    """
    # data: 40 sample feature line in 20d space (40x20; samples x features)
    dss = [
        dataset_wizard(np.concatenate(
            [np.arange(40) for i in range(20)]).reshape(20,-1).T,
                targets=1, chunks=1),
        ] + datasets.values()

    for ds in dss:
        ds1 = deepcopy(ds)
        ds2 = deepcopy(ds)

        zsm = ZScoreMapper(chunks_attr=None)
        assert_raises(RuntimeError, zsm.forward, ds1.samples)
        zsm.train(ds1)
        ds1z = zsm.forward(ds1.samples)

        zscore(ds2, chunks_attr=None)
        assert_array_almost_equal(ds1z, ds2.samples)
        assert_array_equal(ds1.samples, ds.samples)
Exemple #2
0
def test_mapper_vs_zscore():
    """Test by comparing to results of elderly z-score function
    """
    # data: 40 sample feature line in 20d space (40x20; samples x features)
    dss = [
        dataset_wizard(np.concatenate(
            [np.arange(40) for i in range(20)]).reshape(20,-1).T,
                targets=1, chunks=1),
        ] + datasets.values()

    for ds in dss:
        ds1 = deepcopy(ds)
        ds2 = deepcopy(ds)

        zsm = ZScoreMapper(chunks_attr=None)
        assert_raises(RuntimeError, zsm.forward, ds1.samples)
        zsm.train(ds1)
        ds1z = zsm.forward(ds1.samples)

        zscore(ds2, chunks_attr=None)
        assert_array_almost_equal(ds1z, ds2.samples)
        assert_array_equal(ds1.samples, ds.samples)
Exemple #3
0
def test_dataset_summary():
    for ds in datasets.values() + [Dataset(np.array([None], dtype=object))]:
        s = ds.summary()
        ok_(s.startswith(str(ds)[1:-1])) # we strip surrounding '<...>'
        # TODO: actual test of what was returned; to do that properly
        #       RF the summary() so it is a dictionary

        summaries = []
        if 'targets' in ds.sa:
            summaries += ['Sequence statistics']
            if 'chunks' in ds.sa:
                summaries += ['Summary for targets', 'Summary for chunks']

        # By default we should get all kinds of summaries
        if not 'Number of unique targets >' in s:
            for summary in summaries:
                ok_(summary in s)

        # If we give "wrong" targets_attr we should see none of summaries
        s2 = ds.summary(targets_attr='bogus')
        for summary in summaries:
            ok_(not summary in s2)