Beispiel #1
0
class NoPermutationPipeline(RegressionAnalysisPipeline):
    
    
    def run(self):
        
        self.loader = ConnectivityDataLoader()
        self.X, self.y = self.loader.setup_analysis(self.path, 
                              self.roi_list, 
                              self.directory, 
                              self.condition_list, 
                              self.subjects).filter(self.filter_).get_data()
        
        X = self.X
        y = self.y
                             
        X = zscore(X, axis=1) # Sample-wise
        y = zscore(np.float_(y))       
        
        self.fs = FeatureSelectionIterator()
        self.fs.setup_analysis(self.fs_algorithm, 
                          self.fs_ranking_fx).run(X, y).select_first(80)
        
        
        
        self.reg = RegressionAnalysis().setup_analysis(self.cv_schema, 
                                                  self.learner, 
                                                  self.error_fx)
        self.results = []
        for set_ in self.fs:
            X_ = X[:,set_]
            y_ = y
                        
            reg_res = self.reg.run(X_, y_) # To be selected
                       
            self.results.append([reg_res])
        
        self.save()
        
        return self.results
Beispiel #2
0
    def run(self):
        
        self.results = []
        self.loader = ConnectivityDataLoader()
        self.X, self.y = self.loader.setup_analysis(self.path, 
                              self.roi_list, 
                              self.directory, 
                              self.condition_list, 
                              self.subjects).filter(self.filter_).get_data()

        
        X = self.X
        y = self.y
        
        X = zscore(X, axis=1) # Sample-wise
        y = zscore(np.float_(y))
        
        self.fs = FeatureSelectionIterator()
        self.fs.setup_analysis(self.fs_algorithm, self.fs_ranking_fx).run(X, y).select_first(80)
        
        self.reg = RegressionAnalysis().setup_analysis(self.cv_schema, 
                                                  self.learner, 
                                                  self.error_fx)
        #Speedup stuff
        schema = ShuffleSplit(12, n_iter=1, test_size=0.25)
        self.perm_reg = RegressionAnalysis().setup_analysis(schema, 
                                                  self.learner, 
                                                  self.error_fx)
        
        self.perm = PermutationAnalysis().setup_analysis(self.reg, 
                                                    n_permutation=self.n_permutations,
                                                    dimension='features')
        

        
        for i,set_ in enumerate(self.fs):
            
            if i > 78:
                X_ = X[:,set_]
                y_ = y
                            
                reg_res = self.reg.run(X_, y_) # To be selected
                n_dist = self.perm.run(X_, y_)
                
                p_res = self.perm.pvalues(reg_res)
                
                self.results.append([reg_res, n_dist, p_res])

        #self.save()
        return self.results
Beispiel #3
0
class RegressionAnalysisPipeline(Pipeline):
    
    _default_fields = {'path':'/media/robbis/DATA/fmri/monks/', 
               'roi_list':None, 
               'directory':None, 
               'condition_list':None,
               'subjects':None,
               'filter_':None,
               'fs_algorithm':Correlation,
               'fs_ranking_fx':ranking_correlation,
               'cv_schema':ShuffleSplit(12, 
                                        n_iter=250, 
                                        test_size=0.25),
               'learner':SVR(kernel='linear', C=1),
               'error_fx':[mean_squared_error, correlation],
               'y_field':None,
               'n_permutations':2000
               }
    
    
    def setup_analysis(self, **kwargs):
        """
        Fields needed:
        
        path: (e.g. '/media/robbis/DATA/fmri/monks/')
        roi_list: (e.g. load '/media/robbis/DATA/fmri/templates_fcmri/findlab_rois.txt')
        directory (e.g. '20151030_141350_connectivity_filtered_first_no_gsr_findlab_fmri')
        condition_list (e.g. ['Samatha', 'Vipassana'])
        subjects  (e.g. '/media/robbis/DATA/fmri/monks/attributes_struct.txt')
        filter  (e.g. {'meditation':'Samatha', 'groups':'E'})
            -- filter_keywords were used to build the filter
                e.g. meditation: Vipassana will overwrite the filter
        fs_algorithm  (e.g. mvpa_itab.stats.base.Correlation)
        fs_ranking_fx (e.g. mvpa_itab.measures.ranking_correlation)
        cv_schema (e.g. ShuffleSplit(num_exp_subjects, n_iter=cv_repetitions, test_size=cv_fraction)
        learner (e.g. SVR(kernel='linear', C=1))
        error_fx (e.g. [mean_squared_error, correlation])
        y_field (e.g. expertise)
        n_permutations (e.g. 1000)
        """
        self._configuration = dict()
        for arg in self._default_fields:
            setattr(self, arg, self._default_fields[arg])
            self._configuration[arg] = self._default_fields[arg]
        for arg in kwargs:
            setattr(self, arg, kwargs[arg])
            self._configuration[arg] = kwargs[arg]
            
        
        return self


    def update_configuration(self, **kwargs):
        
        for arg in kwargs:
            setattr(self, arg, kwargs[arg])
            self._configuration[arg] = kwargs[arg]
            
            if arg in self.filter_.keys():
                self.filter_[arg] = kwargs[arg]
                self._configuration['filter_'][arg] = kwargs[arg]
                
        return self
    

            
    def run(self):
        
        self.results = []
        self.loader = ConnectivityDataLoader()
        self.X, self.y = self.loader.setup_analysis(self.path, 
                              self.roi_list, 
                              self.directory, 
                              self.condition_list, 
                              self.subjects).filter(self.filter_).get_data()

        
        X = self.X
        y = self.y
        
        X = zscore(X, axis=1) # Sample-wise
        y = zscore(np.float_(y))
        
        self.fs = FeatureSelectionIterator()
        self.fs.setup_analysis(self.fs_algorithm, self.fs_ranking_fx).run(X, y).select_first(80)
        
        self.reg = RegressionAnalysis().setup_analysis(self.cv_schema, 
                                                  self.learner, 
                                                  self.error_fx)
        #Speedup stuff
        schema = ShuffleSplit(12, n_iter=1, test_size=0.25)
        self.perm_reg = RegressionAnalysis().setup_analysis(schema, 
                                                  self.learner, 
                                                  self.error_fx)
        
        self.perm = PermutationAnalysis().setup_analysis(self.reg, 
                                                    n_permutation=self.n_permutations,
                                                    dimension='features')
        

        
        for i,set_ in enumerate(self.fs):
            
            if i > 78:
                X_ = X[:,set_]
                y_ = y
                            
                reg_res = self.reg.run(X_, y_) # To be selected
                n_dist = self.perm.run(X_, y_)
                
                p_res = self.perm.pvalues(reg_res)
                
                self.results.append([reg_res, n_dist, p_res])

        #self.save()
        return self.results