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
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
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)
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)
from mvpa.mappers.svd import SVDMapper from mvpa.mappers.mdp_adaptor import ICAMapper, PCAMapper from mvpa import cfg center = [10, 20] axis_range = 7 ##REF: Name was automagically refactored def plot_proj_dir(p): pl.plot([0, p[0, 0]], [0, p[0, 1]], linewidth=3, hold=True, color='y') pl.plot([0, p[1, 0]], [0, p[1, 1]], linewidth=3, hold=True, color='k') mappers = { 'PCA': PCAMapper(), 'SVD': SVDMapper(), 'ICA': ICAMapper(alg='CuBICA'), } datasets = [ noisy_2d_fx(100, lambda x: x, [lambda x: x], center, noise_std=0.5), noisy_2d_fx(50, lambda x: x, [lambda x: x, lambda x: -x], center, noise_std=0.5), noisy_2d_fx(50, lambda x: x, [lambda x: x, lambda x: 0], center, noise_std=0.5), ]