Example #1
0
def bench_pymvpa():
#
#       .. PyMVPA ..
#
    from mvpa.mappers.mdp_adaptor import PCAMapper as MVPA_PCA
    from mvpa.datasets import dataset_wizard
    start = datetime.now()
    clf = MVPA_PCA(output_dim=n_components)
    data = dataset_wizard(samples=X)
    clf.train(data)
    return datetime.now() - start
Example #2
0
def bench_pymvpa(X, y, T, valid):
#
#       .. PyMVPA ..
#
    from mvpa.mappers.mdp_adaptor import PCAMapper
    from mvpa.datasets import dataset_wizard
    start = datetime.now()
    clf = PCAMapper(output_dim=n_components)
    data = dataset_wizard(samples=X)
    clf.train(data)
    delta = datetime.now() - start
    ev = explained_variance(X, clf.proj.T).sum()
    return ev, delta
Example #3
0
def test_pcamapper():
    # data: 40 sample feature line in 20d space (40x20; samples x features)
    ndlin = Dataset(np.concatenate([np.arange(40)
                               for i in range(20)]).reshape(20,-1).T)

    pm = PCAMapper()
    # train PCA
    assert_raises(mdp.NodeException, pm.train, ndlin)
    ndlin.samples = ndlin.samples.astype('float')
    ndlin_noise = ndlin.copy()
    ndlin_noise.samples += np.random.random(size=ndlin.samples.shape)
    # we have no variance for more than one PCA component, hence just one
    # actual non-zero eigenvalue
    assert_raises(mdp.NodeException, pm.train, ndlin)
    pm.train(ndlin_noise)
    assert_equal(pm.proj.shape, (20, 20))
    # now project data into PCA space
    p = pm.forward(ndlin.samples)
    assert_equal(p.shape, (40, 20))
    # check that the mapped data can be fully recovered by 'reverse()'
    assert_array_almost_equal(pm.reverse(p), ndlin)