コード例 #1
0
        print 'SNR = ', snr, ' dB'


        # Estimation with 1 hrf. Uses glover as mean GP
        hrf_model = 'glover'
        hrf_0 = _get_hrf_model(hrf_model, hrf_length=hrf_length + dt,
                               dt=dt, normalize=True)
        f_hrf = interp1d(x_0, hrf_0)
        gp = SuperDuperGP(hrf_length=hrf_length, t_r=t_r, oversampling=1./dt, gamma=gamma,
                    modulation=modulation, fmin_max_iter=fmin_max_iter, sigma_noise=1.,
                    time_offset=time_offset, n_iter=n_iter, normalize_y=normalize_y, verbose=True,
                    optimize=optimize, n_restarts_optimizer=n_restarts_optimizer,
                    zeros_extremes=zeros_extremes, f_mean=f_hrf)
        (hx, hy, hrf_var,
         resid_norm_sq,
         sigma_sq_resid) = gp.fit(ys_acquired, paradigm)
        print 'residual norm square = ', resid_norm_sq

        hy *= np.sign(hy[np.argmax(np.abs(hy))]) / np.abs(hy).max()
        hrf_0 /= hrf_0.max()
        hrf_sim /= hrf_sim.max()

        # Plotting each HRF simulated vs estimated
        if len(range_peak)==5 or len(range_peak)==6:
            plt.subplot(2, 3, i + 1)
            plt.tight_layout()
        elif len(range_peak)==3 or len(range_peak)==4:
            plt.subplot(2, 2, i + 1)
            plt.tight_layout()
        elif len(range_peak)==2:
            ax = plt.subplot(1, 2, i + 1)
コード例 #2
0
        n_iter = 3
        normalize_y = False
        optimize = True
        zeros_extremes = True

        # Estimation
        gp = SuperDuperGP(hrf_length=hrf_length, t_r=t_r, oversampling=1./dt,
                          gamma=gamma, modulation=modulation,
                          fmin_max_iter=fmin_max_iter, sigma_noise=1.0,
                          time_offset=time_offset, n_iter=n_iter,
                          normalize_y=normalize_y, verbose=True,
                          optimize=optimize,
                          n_restarts_optimizer=n_restarts_optimizer,
                          zeros_extremes=zeros_extremes, f_mean=f_hrf)

        (hx, hy, hrf_var, resid_norm_sq, sigma_sq_resid) = gp.fit(ys, paradigm)

        print 'residual norm square = ', resid_norm_sq

        # Testing with a GLM
        mask_img = nb.Nifti1Image(np.ones((2, 2, 2)), affine=np.eye(4))
        masker = NiftiMasker(mask_img=mask_img)
        masker.fit()
        ys2 = np.ones((2, 2, 2, ys.shape[0])) * ys[np.newaxis, np.newaxis, np.newaxis, :]
        niimgs = nb.Nifti1Image(ys2, affine=np.eye(4))
        glm = FirstLevelGLM(mask=mask_img, t_r=t_r, standardize=True, noise_model='ols')
        glm.fit(niimgs, dm)
        norm_resid = (np.linalg.norm(glm.results_[0][0].resid, axis=0)**2).mean()
        ys_pred_glm = glm.results_[0][0].predicted[:, 0]

        # Predict GP