示例#1
0
def test_miyawaki2008():
    dataset = datasets.fetch_miyawaki2008(data_dir=tmpdir, verbose=0)
    assert_equal(len(dataset.func), 32)
    assert_equal(len(dataset.label), 32)
    assert_true(isinstance(dataset.mask, _basestring))
    assert_equal(len(dataset.mask_roi), 38)
    assert_equal(len(url_request.urls), 1)
示例#2
0
def test_miyawaki2008():
    dataset = datasets.fetch_miyawaki2008(data_dir=tmpdir, verbose=0)
    assert_equal(len(dataset.func), 32)
    assert_equal(len(dataset.label), 32)
    assert_true(isinstance(dataset.mask, _basestring))
    assert_equal(len(dataset.mask_roi), 38)
    assert_equal(len(url_request.urls), 1)
:ref:`sphx_glr_auto_examples_02_decoding_plot_miyawaki_encoding.py` for a
encoding approach for the same dataset.
"""

# Some basic imports
import time
import sys

############################################################################
# First we load the Miyawaki dataset
# -----------------------------------
from nilearn import datasets
sys.stderr.write("Fetching dataset...")
t0 = time.time()

miyawaki_dataset = datasets.fetch_miyawaki2008()

# print basic information on the dataset
print('First functional nifti image (4D) is located at: %s' %
      miyawaki_dataset.func[0])  # 4D data

X_random_filenames = miyawaki_dataset.func[12:]
X_figure_filenames = miyawaki_dataset.func[:12]
y_random_filenames = miyawaki_dataset.label[12:]
y_figure_filenames = miyawaki_dataset.label[:12]
y_shape = (10, 10)

sys.stderr.write(" Done (%.2fs).\n" % (time.time() - t0))

############################################################################
# Then we prepare and mask the data
It reconstructs 10x10 binary images from functional MRI data. Random images
are used as training set and structured images are used for reconstruction.
"""

### Imports ###################################################################

from matplotlib import pyplot as plt
import time
import sys

### Load Kamitani dataset #####################################################
from nilearn import datasets
sys.stderr.write("Fetching dataset...")
t0 = time.time()

miyawaki_dataset = datasets.fetch_miyawaki2008()
X_random_filenames = miyawaki_dataset.func[12:]
X_figure_filenames = miyawaki_dataset.func[:12]
y_random_filenames = miyawaki_dataset.label[12:]
y_figure_filenames = miyawaki_dataset.label[:12]
y_shape = (10, 10)

sys.stderr.write(" Done (%.2fs).\n" % (time.time() - t0))

### Preprocess and mask #######################################################
import numpy as np
from nilearn.input_data import MultiNiftiMasker

sys.stderr.write("Preprocessing data...")
t0 = time.time()
from the binary pixel-values of the presented images. Then we extract the
receptive fields for a set of voxels to see which pixel location a voxel
is most sensitive to.

See also :doc:`plot_miyawaki_reconstruction` for a decoding
approach for the same dataset.
"""

##############################################################################
# Loading the data
# ----------------
# Now we can load the data set:

from nilearn.datasets import fetch_miyawaki2008

dataset = fetch_miyawaki2008()

##############################################################################
# We only use the training data of this study,
# where random binary images were shown.

# training data starts after the first 12 files
fmri_random_runs_filenames = dataset.func[12:]
stimuli_random_runs_filenames = dataset.label[12:]

##############################################################################
# We can use :func:`nilearn.input_data.MultiNiftiMasker` to load the fMRI
# data, clean and mask it.

import numpy as np
from nilearn.input_data import MultiNiftiMasker
from core.util.utilities import compute_r2
from sklearn.decomposition import PCA
import core.gp.gp_sMTGPR as sMTGPR
import core.gp.gp_kronprod as gp_kronprod
from core.util.normod import extreme_value_prob, normative_prob_map, extreme_value_prob_fit
from sklearn.metrics import roc_auc_score
import time

###############################################################################

method = 'STGPR' # Select the method among MT_Kronprod, sMT_GPR, STGPR 
save_path = 'path for saving the results'
runs = 10 # Select the number of runs

############################ Loading Data #####################################
miyawaki_dataset = fetch_miyawaki2008()

Y_random_filenames = miyawaki_dataset.func[12:]
Y_figure_filenames = miyawaki_dataset.func[:12]
X_random_filenames = miyawaki_dataset.label[12:]
X_figure_filenames = miyawaki_dataset.label[:12]
X_shape = (10, 10)

masker = MultiNiftiMasker(mask_img=miyawaki_dataset.mask, detrend=True,
                          standardize=False)
masker.fit()
fmri_random = masker.transform(Y_random_filenames)
fmri_figure = masker.transform(Y_figure_filenames)

pattern_random = [] 
for x in X_random_filenames: