Ejemplo n.º 1
0
    def setUp(self):

        self.tmp_dir = pyhrf.get_tmp_path()

        simu = simulate_sessions(output_dir=self.tmp_dir,
                                 snr_scenario='high_snr',
                                 spatial_size='random_small')
        self.data_simu = merge_fmri_sessions(simu)
Ejemplo n.º 2
0
    def test_multisession_simu(self):
        fd1 = FmriData.from_simu_ui()
        fd2 = FmriData.from_simu_ui()

        fd_msession = merge_fmri_sessions([fd1, fd2])
        self.assertEqual(fd_msession.nbSessions, 2)
    def setUp(self):

        #pyhrf.verbose.set_verbosity(2)

        np.random.seed(8652761)

        # tmpDir = tempfile.mkdtemp(prefix='pyhrf_tests',
        #     dir=pyhrf.cfg['global']['tmp_path'])

        self.tmp_outputs = True #save outputs in tmp dir
                                #if False then save in current dir

        if not self.tmp_outputs:
            self.tmp_dir_small = './JDE_MS_test_small_simu'
            if not op.exists(self.tmp_dir_small): os.makedirs(self.tmp_dir_small)
            self.tmp_dir_big = './JDE_MS_test_big_simu'
            if not op.exists(self.tmp_dir_big): os.makedirs(self.tmp_dir_big)
        else:
            self.tmp_dir_small = pyhrf.get_tmp_path()
            self.tmp_dir_big = pyhrf.get_tmp_path()

        simu = simulate_sessions(output_dir = self.tmp_dir_small,
                                 snr_scenario='high_snr', spatial_size='tiny')
        self.data_small_simu = merge_fmri_sessions(simu)

        simu = simulate_sessions(output_dir=self.tmp_dir_big,
                                 snr_scenario='low_snr', spatial_size='normal')
        self.data_simu = merge_fmri_sessions(simu)

        # Parameters for multi-sessions sampler
        dict_beta_single = {
                    BetaSampler.P_VAL_INI : np.array([0.5]),
                    BetaSampler.P_SAMPLE_FLAG : False,
                    BetaSampler.P_PARTITION_FUNCTION_METH : 'es',
                    BetaSampler.P_USE_TRUE_VALUE : False,
                    }

        dict_hrf_single = {
                    HRF_MultiSess_Sampler.P_SAMPLE_FLAG : False,
                    HRF_MultiSess_Sampler.P_NORMALISE : 1., # normalise samples
                    HRF_MultiSess_Sampler.P_USE_TRUE_VALUE :  True,
                    HRF_MultiSess_Sampler.P_ZERO_CONSTR :  True,
                    #HRF_MultiSess_Sampler.P_PRIOR_TYPE : 'singleHRF',
                    }

        dict_var_hrf_single = {
                        RHSampler.P_SAMPLE_FLAG : False,
                        RHSampler.P_VAL_INI : np.array([0.001]),
                    }

        dict_nrl_sess_single =   {
                        NRL_Multi_Sess_Sampler.P_SAMPLE_FLAG : False,
                        NRL_Multi_Sess_Sampler.P_USE_TRUE_VALUE :  True,
                        }

        dict_nrl_sess_var_single = {
                            Variance_GaussianNRL_Multi_Sess.P_SAMPLE_FLAG : False,
                            Variance_GaussianNRL_Multi_Sess.P_USE_TRUE_VALUE :  True,
                            }

        dict_nrl_bar_single =  {
                        NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG : False,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_NRLS : True,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_LABELS : False,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_LABELS : True,
                        }

        dict_drift_single = {
                    Drift_MultiSess_Sampler.P_SAMPLE_FLAG : False,
                    Drift_MultiSess_Sampler.P_USE_TRUE_VALUE : True,
                    }

        dict_drift_var_single = {
                        ETASampler_MultiSess.P_SAMPLE_FLAG : False,
                        ETASampler_MultiSess.P_USE_TRUE_VALUE : True,
                        }

        dict_noise_var_single = {
                        NoiseVariance_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG : False,
                        NoiseVariance_Drift_Multi_Sess_Sampler.P_USE_TRUE_VALUE :  True,
                        }

        dict_mixt_param_single =  {
                            BiGaussMixtureParamsSampler.P_SAMPLE_FLAG : False,
                            BiGaussMixtureParamsSampler.P_USE_TRUE_VALUE : True,
                            BiGaussMixtureParamsSampler.P_HYPER_PRIOR : 'Jeffrey',
                            }


        self.sampler_params_for_single_test = {
            BMSS.P_NB_ITERATIONS : 100,
            BMSS.P_SMPL_HIST_PACE : -1,
            BMSS.P_OBS_HIST_PACE : -1,
            # level of spatial correlation = beta
            BMSS.P_BETA : BetaSampler(dict_beta_single),
            # HRF
            BMSS.P_HRF : HRF_MultiSess_Sampler(dict_hrf_single),
            # HRF variance
            BMSS.P_RH : RHSampler(dict_var_hrf_single),
            # neural response levels (stimulus-induced effects) by session
            BMSS.P_NRLS_SESS : NRL_Multi_Sess_Sampler(dict_nrl_sess_single),
            # neural response levels by session --> variance
            BMSS.P_NRLS_SESS_VAR : Variance_GaussianNRL_Multi_Sess(dict_nrl_sess_var_single),
            # neural response levels mean: over sessions
            BMSS.P_NRLS_BAR : NRLsBar_Drift_Multi_Sess_Sampler(dict_nrl_bar_single),
            # drift
            BMSS.P_DRIFT : Drift_MultiSess_Sampler(dict_drift_single),
            #drift variance
            BMSS.P_ETA : ETASampler_MultiSess(dict_drift_var_single),
            #noise variance
            BMSS.P_NOISE_VAR_SESS : NoiseVariance_Drift_Multi_Sess_Sampler(dict_noise_var_single),
            #weights o fthe mixture
            #parameters of the mixture
            BMSS.P_MIXT_PARAM_NRLS_BAR : BiGaussMixtureParamsSampler(dict_mixt_param_single),
            BMSS.P_CHECK_FINAL_VALUE : 'raise', #print or raise
        }


        # Parameters for multi-sessions sampler - full test
        dict_beta_full = {
                    BetaSampler.P_VAL_INI : np.array([0.5]),
                    BetaSampler.P_SAMPLE_FLAG : True,
                    BetaSampler.P_PARTITION_FUNCTION_METH : 'es',
                    }

        dict_hrf_full = {
                    HRF_MultiSess_Sampler.P_SAMPLE_FLAG : True,
                    HRF_MultiSess_Sampler.P_NORMALISE : 1., # normalise samples
                    HRF_MultiSess_Sampler.P_USE_TRUE_VALUE :  False,
                    HRF_MultiSess_Sampler.P_ZERO_CONSTR : True,
                    #HRF_MultiSess_Sampler.P_PRIOR_TYPE : 'singleHRF',
                    }

        dict_var_hrf_full = {
                        RHSampler.P_SAMPLE_FLAG : False,
                        RHSampler.P_VAL_INI : np.array([0.001]),
                    }

        dict_nrl_sess_full =   {
                        NRL_Multi_Sess_Sampler.P_SAMPLE_FLAG : True,
                        NRL_Multi_Sess_Sampler.P_USE_TRUE_VALUE :  False,
                        }

        dict_nrl_sess_var_full = {
                            Variance_GaussianNRL_Multi_Sess.P_SAMPLE_FLAG : True,
                            Variance_GaussianNRL_Multi_Sess.P_USE_TRUE_VALUE : False,
                            }

        dict_nrl_bar_full =  {
                        NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG : True,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_NRLS : False,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_LABELS : True,
                        NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_LABELS : False,
                        }

        dict_drift_full = {
                    Drift_MultiSess_Sampler.P_SAMPLE_FLAG : True,
                    Drift_MultiSess_Sampler.P_USE_TRUE_VALUE : False,
                    }

        dict_drift_var_full = {
                        ETASampler_MultiSess.P_SAMPLE_FLAG : True,
                        ETASampler_MultiSess.P_USE_TRUE_VALUE : False,
                        }

        dict_noise_var_full = {
                        NoiseVariance_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG : True,
                        NoiseVariance_Drift_Multi_Sess_Sampler.P_USE_TRUE_VALUE :  False,
                        }

        dict_mixt_param_full =  {
                            BiGaussMixtureParamsSampler.P_SAMPLE_FLAG : True,
                            BiGaussMixtureParamsSampler.P_USE_TRUE_VALUE : False,
                            BiGaussMixtureParamsSampler.P_HYPER_PRIOR : 'Jeffrey',
                            }


        self.sampler_params_for_full_test = {

            BMSS.P_NB_ITERATIONS : 400,
            BMSS.P_SMPL_HIST_PACE : -1,
            BMSS.P_OBS_HIST_PACE : -1,
            # level of spatial correlation = beta
            BMSS.P_BETA : BetaSampler(dict_beta_full),
            # HRF
            BMSS.P_HRF : HRF_MultiSess_Sampler(dict_hrf_full),
            # HRF variance
            BMSS.P_RH : RHSampler(dict_var_hrf_full),
            # neural response levels (stimulus-induced effects) by session
            BMSS.P_NRLS_SESS : NRL_Multi_Sess_Sampler(dict_nrl_sess_full),
            # neural response levels by session --> variance
            BMSS.P_NRLS_SESS_VAR : Variance_GaussianNRL_Multi_Sess(dict_nrl_sess_var_full),
            # neural response levels mean: over sessions
            BMSS.P_NRLS_BAR : NRLsBar_Drift_Multi_Sess_Sampler(dict_nrl_bar_full),
            # drift
            BMSS.P_DRIFT : Drift_MultiSess_Sampler(dict_drift_full),
            #drift variance
            BMSS.P_ETA : ETASampler_MultiSess(dict_drift_var_full),
            #noise variance
            BMSS.P_NOISE_VAR_SESS : NoiseVariance_Drift_Multi_Sess_Sampler(dict_noise_var_full),
            #weights o fthe mixture
            #parameters of the mixture
            BMSS.P_MIXT_PARAM_NRLS_BAR : BiGaussMixtureParamsSampler(dict_mixt_param_full),
            BMSS.P_CHECK_FINAL_VALUE : 'raise', #print or raise
        }
Ejemplo n.º 4
0
 def setUp(self):
     self.tmp_dir = pyhrf.get_tmp_path()
     simu = simulate_sessions(output_dir=self.tmp_dir,
                              snr_scenario='high_snr',
                              spatial_size='random_small')
     self.data_simu = merge_fmri_sessions(simu)
Ejemplo n.º 5
0
 def test_multisession_simu(self):
     fd1 = FmriData.from_simu_ui()
     fd2 = FmriData.from_simu_ui()
     
     fd_msession = merge_fmri_sessions([fd1, fd2])
     self.assertEqual(fd_msession.nbSessions, 2)
Ejemplo n.º 6
0
    def setUp(self):

        np.random.seed(8652761)
        self.tmp_outputs = True  #save outputs in tmp dir
        #if False then save in current dir

        if not self.tmp_outputs:
            self.tmp_dir_small = './JDE_MS_test_small_simu'
            if not op.exists(self.tmp_dir_small):
                os.makedirs(self.tmp_dir_small)
            self.tmp_dir_big = './JDE_MS_test_big_simu'
            if not op.exists(self.tmp_dir_big): os.makedirs(self.tmp_dir_big)
        else:
            self.tmp_dir_small = pyhrf.get_tmp_path()
            self.tmp_dir_big = pyhrf.get_tmp_path()

        simu = simulate_sessions(output_dir=self.tmp_dir_small,
                                 snr_scenario='high_snr',
                                 spatial_size='tiny')
        self.data_small_simu = merge_fmri_sessions(simu)

        simu = simulate_sessions(output_dir=self.tmp_dir_big,
                                 snr_scenario='low_snr',
                                 spatial_size='normal')
        self.data_simu = merge_fmri_sessions(simu)

        # Parameters for multi-sessions sampler
        dict_beta_single = {
            BetaSampler.P_VAL_INI: np.array([0.5]),
            BetaSampler.P_SAMPLE_FLAG: False,
            BetaSampler.P_PARTITION_FUNCTION_METH: 'es',
            BetaSampler.P_USE_TRUE_VALUE: False,
        }

        dict_hrf_single = {
            HRF_MultiSess_Sampler.P_SAMPLE_FLAG: False,
            HRF_MultiSess_Sampler.P_NORMALISE: 1.,  # normalise samples
            HRF_MultiSess_Sampler.P_USE_TRUE_VALUE: True,
            HRF_MultiSess_Sampler.P_ZERO_CONSTR: True,
            #HRF_MultiSess_Sampler.P_PRIOR_TYPE : 'singleHRF',
        }

        dict_var_hrf_single = {
            RHSampler.P_SAMPLE_FLAG: False,
            RHSampler.P_VAL_INI: np.array([0.001]),
        }

        dict_nrl_sess_single = {
            NRL_Multi_Sess_Sampler.P_SAMPLE_FLAG: False,
            NRL_Multi_Sess_Sampler.P_USE_TRUE_VALUE: True,
        }

        dict_nrl_sess_var_single = {
            Variance_GaussianNRL_Multi_Sess.P_SAMPLE_FLAG: False,
            Variance_GaussianNRL_Multi_Sess.P_USE_TRUE_VALUE: True,
        }

        dict_nrl_bar_single = {
            NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG: False,
            NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_NRLS: True,
            NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_LABELS: False,
            NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_LABELS: True,
        }

        dict_drift_single = {
            Drift_MultiSess_Sampler.P_SAMPLE_FLAG: False,
            Drift_MultiSess_Sampler.P_USE_TRUE_VALUE: True,
        }

        dict_drift_var_single = {
            ETASampler_MultiSess.P_SAMPLE_FLAG: False,
            ETASampler_MultiSess.P_USE_TRUE_VALUE: True,
        }

        dict_noise_var_single = {
            NoiseVariance_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG: False,
            NoiseVariance_Drift_Multi_Sess_Sampler.P_USE_TRUE_VALUE: True,
        }

        dict_mixt_param_single = {
            BiGaussMixtureParamsSampler.P_SAMPLE_FLAG: False,
            BiGaussMixtureParamsSampler.P_USE_TRUE_VALUE: True,
            BiGaussMixtureParamsSampler.P_HYPER_PRIOR: 'Jeffrey',
        }

        self.sampler_params_for_single_test = {
            BMSS.P_NB_ITERATIONS:
            100,
            BMSS.P_SMPL_HIST_PACE:
            -1,
            BMSS.P_OBS_HIST_PACE:
            -1,
            # level of spatial correlation = beta
            BMSS.P_BETA:
            BetaSampler(dict_beta_single),
            # HRF
            BMSS.P_HRF:
            HRF_MultiSess_Sampler(dict_hrf_single),
            # HRF variance
            BMSS.P_RH:
            RHSampler(dict_var_hrf_single),
            # neural response levels (stimulus-induced effects) by session
            BMSS.P_NRLS_SESS:
            NRL_Multi_Sess_Sampler(dict_nrl_sess_single),
            # neural response levels by session --> variance
            BMSS.P_NRLS_SESS_VAR:
            Variance_GaussianNRL_Multi_Sess(dict_nrl_sess_var_single),
            # neural response levels mean: over sessions
            BMSS.P_NRLS_BAR:
            NRLsBar_Drift_Multi_Sess_Sampler(dict_nrl_bar_single),
            # drift
            BMSS.P_DRIFT:
            Drift_MultiSess_Sampler(dict_drift_single),
            #drift variance
            BMSS.P_ETA:
            ETASampler_MultiSess(dict_drift_var_single),
            #noise variance
            BMSS.P_NOISE_VAR_SESS:
            NoiseVariance_Drift_Multi_Sess_Sampler(dict_noise_var_single),
            #weights o fthe mixture
            #parameters of the mixture
            BMSS.P_MIXT_PARAM_NRLS_BAR:
            BiGaussMixtureParamsSampler(dict_mixt_param_single),
            BMSS.P_CHECK_FINAL_VALUE:
            'raise',  #print or raise
        }

        # Parameters for multi-sessions sampler - full test
        dict_beta_full = {
            BetaSampler.P_VAL_INI: np.array([0.5]),
            BetaSampler.P_SAMPLE_FLAG: True,
            BetaSampler.P_PARTITION_FUNCTION_METH: 'es',
        }

        dict_hrf_full = {
            HRF_MultiSess_Sampler.P_SAMPLE_FLAG: True,
            HRF_MultiSess_Sampler.P_NORMALISE: 1.,  # normalise samples
            HRF_MultiSess_Sampler.P_USE_TRUE_VALUE: False,
            HRF_MultiSess_Sampler.P_ZERO_CONSTR: True,
            #HRF_MultiSess_Sampler.P_PRIOR_TYPE : 'singleHRF',
        }

        dict_var_hrf_full = {
            RHSampler.P_SAMPLE_FLAG: False,
            RHSampler.P_VAL_INI: np.array([0.001]),
        }

        dict_nrl_sess_full = {
            NRL_Multi_Sess_Sampler.P_SAMPLE_FLAG: True,
            NRL_Multi_Sess_Sampler.P_USE_TRUE_VALUE: False,
        }

        dict_nrl_sess_var_full = {
            Variance_GaussianNRL_Multi_Sess.P_SAMPLE_FLAG: True,
            Variance_GaussianNRL_Multi_Sess.P_USE_TRUE_VALUE: False,
        }

        dict_nrl_bar_full = {
            NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG: True,
            NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_NRLS: False,
            NRLsBar_Drift_Multi_Sess_Sampler.P_SAMPLE_LABELS: True,
            NRLsBar_Drift_Multi_Sess_Sampler.P_USE_TRUE_LABELS: False,
        }

        dict_drift_full = {
            Drift_MultiSess_Sampler.P_SAMPLE_FLAG: True,
            Drift_MultiSess_Sampler.P_USE_TRUE_VALUE: False,
        }

        dict_drift_var_full = {
            ETASampler_MultiSess.P_SAMPLE_FLAG: True,
            ETASampler_MultiSess.P_USE_TRUE_VALUE: False,
        }

        dict_noise_var_full = {
            NoiseVariance_Drift_Multi_Sess_Sampler.P_SAMPLE_FLAG: True,
            NoiseVariance_Drift_Multi_Sess_Sampler.P_USE_TRUE_VALUE: False,
        }

        dict_mixt_param_full = {
            BiGaussMixtureParamsSampler.P_SAMPLE_FLAG: True,
            BiGaussMixtureParamsSampler.P_USE_TRUE_VALUE: False,
            BiGaussMixtureParamsSampler.P_HYPER_PRIOR: 'Jeffrey',
        }

        self.sampler_params_for_full_test = {
            BMSS.P_NB_ITERATIONS:
            400,
            BMSS.P_SMPL_HIST_PACE:
            -1,
            BMSS.P_OBS_HIST_PACE:
            -1,
            # level of spatial correlation = beta
            BMSS.P_BETA:
            BetaSampler(dict_beta_full),
            # HRF
            BMSS.P_HRF:
            HRF_MultiSess_Sampler(dict_hrf_full),
            # HRF variance
            BMSS.P_RH:
            RHSampler(dict_var_hrf_full),
            # neural response levels (stimulus-induced effects) by session
            BMSS.P_NRLS_SESS:
            NRL_Multi_Sess_Sampler(dict_nrl_sess_full),
            # neural response levels by session --> variance
            BMSS.P_NRLS_SESS_VAR:
            Variance_GaussianNRL_Multi_Sess(dict_nrl_sess_var_full),
            # neural response levels mean: over sessions
            BMSS.P_NRLS_BAR:
            NRLsBar_Drift_Multi_Sess_Sampler(dict_nrl_bar_full),
            # drift
            BMSS.P_DRIFT:
            Drift_MultiSess_Sampler(dict_drift_full),
            #drift variance
            BMSS.P_ETA:
            ETASampler_MultiSess(dict_drift_var_full),
            #noise variance
            BMSS.P_NOISE_VAR_SESS:
            NoiseVariance_Drift_Multi_Sess_Sampler(dict_noise_var_full),
            #weights o fthe mixture
            #parameters of the mixture
            BMSS.P_MIXT_PARAM_NRLS_BAR:
            BiGaussMixtureParamsSampler(dict_mixt_param_full),
            BMSS.P_CHECK_FINAL_VALUE:
            'raise',  #print or raise
        }