def test_voxel_selection(): fake_raw_data = [create_epoch() for i in range(8)] labels = [0, 1, 0, 1, 0, 1, 0, 1] # 2 subjects, 4 epochs per subject vs = VoxelSelector(fake_raw_data, 4, labels, 2, voxel_unit=1) # test scipy normalization fake_corr = prng.rand(1, 4, 5).astype(np.float32) fake_corr = vs._correlationNormalization(fake_corr) if MPI.COMM_WORLD.Get_rank() == 0: expected_fake_corr = [[[1.19203866, 0.18862808, -0.54350245, -1.18334889, -0.16860008], [-1.06594729, -1.08742261, -1.19447124, 1.14114654, -0.67860204], [0.7839641, 1.53981364, 0.24948341, 0.82626557, 1.67902875], [-0.91005552, -0.64101928, 1.48848987, -0.78406328, -0.83182675]]] assert np.allclose(fake_corr, expected_fake_corr), \ 'within-subject normalization does not provide correct results' # for cross validation, use SVM with precomputed kernel # no shrinking, set C=1 clf = svm.SVC(kernel='precomputed', shrinking=False, C=1) results = vs.run(clf) if MPI.COMM_WORLD.Get_rank() == 0: output = [None] * len(results) for tuple in results: output[tuple[0]] = int(8*tuple[1]) expected_output = [7, 4, 6, 4, 4] assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via SVM does not provide correct results' # for cross validation, use logistic regression clf = LogisticRegression() results = vs.run(clf) if MPI.COMM_WORLD.Get_rank() == 0: output = [None] * len(results) for tuple in results: output[tuple[0]] = int(8*tuple[1]) expected_output = [6, 3, 6, 4, 4] assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via logistic regression does not provide correct results'
def test_voxel_selection(): fake_raw_data = [create_epoch() for i in range(8)] labels = [0, 1, 0, 1, 0, 1, 0, 1] # 2 subjects, 4 epochs per subject vs = VoxelSelector(fake_raw_data, 4, labels, 2, voxel_unit=1) # test scipy normalization fake_corr = prng.rand(1, 4, 5).astype(np.float32) fake_corr = vs._correlationNormalization(fake_corr) if MPI.COMM_WORLD.Get_rank() == 0: expected_fake_corr = [ [[1.19203866, 0.18862808, -0.54350245, -1.18334889, -0.16860008], [-1.06594729, -1.08742261, -1.19447124, 1.14114654, -0.67860204], [0.7839641, 1.53981364, 0.24948341, 0.82626557, 1.67902875], [-0.91005552, -0.64101928, 1.48848987, -0.78406328, -0.83182675]] ] assert np.allclose(fake_corr, expected_fake_corr), \ 'within-subject normalization does not provide correct results' # for cross validation, use SVM with precomputed kernel # no shrinking, set C=1 clf = svm.SVC(kernel='precomputed', shrinking=False, C=1) results = vs.run(clf) if MPI.COMM_WORLD.Get_rank() == 0: output = [None] * len(results) for tuple in results: output[tuple[0]] = int(8 * tuple[1]) expected_output = [7, 4, 6, 4, 4] assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via SVM does not provide correct results' # for cross validation, use logistic regression clf = LogisticRegression() results = vs.run(clf) if MPI.COMM_WORLD.Get_rank() == 0: output = [None] * len(results) for tuple in results: output[tuple[0]] = int(8 * tuple[1]) expected_output = [6, 3, 6, 4, 4] assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via logistic regression does not provide correct results'