(self, round, train_id, test_id, Lcollection, Ucollection,
                       saver, examples=None, labels=None, global_parameters=None)
The active-learning main loop.
The active-learning main loop.
The active - learning main loop .
def __al_main_loop(self, round, train_id, test_id, Lcollection, Ucollection,
                       saver, examples=None, labels=None, global_parameters=None):
        """
            The active-learning main loop.
        """
        Lcollection = IndexCollection(Lcollection)
        Ucollection = IndexCollection(Ucollection)
        self._model.fit(X=self._X[Lcollection.index, :], y=self._y[Lcollection.index])
        pred = self._model.predict(self._X[test_id, :])

        # some query strategy,such as QueryInstanceGraphDensity,QueryInstanceQUIRE, need train_ind
        if self._query_function_need_train_ind:
            if self._query_function_name == 'QueryInstanceGraphDensity':
                if self._query_function_metric is not None:
                    querfunction = QueryInstanceGraphDensity(self._X, self._y, train_id, self._query_function_metric)
                else:
                    raise Exception(
                        "The QueryInstanceGraphDensity need metric.Please input metric in set_query_strategy().")
            elif self._query_function_name == 'QueryInstanceQUIRE':
                querfunction = QueryInstanceQUIRE(self._X, self._y, train_id, **self._query_function_kwargs)

        # performance calc
        perf_result = self._performance_metric(pred, self._y[test_id])

        # stopping-criterion 
        stopping_criterion = copy.deepcopy(self._stopping_criterion)
        saver.set_initial_point(perf_result)

        while not stopping_criterion.is_stop():
            if not self.__custom_strategy_flag:
                if self._query_function_name == 'QueryInstanceGraphDensity':
                    select_ind = querfunction.select(Lcollection, Ucollection, batch_size=self._batch_size,
                                                     **self._query_function_kwargs)
                elif self._query_function_name == 'QueryInstanceQUIRE':
                    select_ind = querfunction.select(Lcollection, Ucollection, batch_size=self._batch_size)
                elif 'model' in inspect.getfullargspec(self._query_function.select)[0]:
                    select_ind = self._query_function.select(Lcollection, Ucollection, batch_size=self._batch_size,
                                                             model=self._model)
                elif self._query_function_name == 'QueryInstanceBMDR' or self._query_function_name == 'QueryInstanceSPAL':
                    select_ind = self._query_function.select(Lcollection, Ucollection, batch_size=self._batch_size,
                                                             qp_solver=self.qp_solver)
                else:
                    select_ind = self._query_function.select(Lcollection, Ucollection, batch_size=self._batch_size)
            else:
                select_ind = self._query_function.select(Lcollection, Ucollection, batch_size=self._batch_size,
                                                         **self.__custom_func_arg)
            Lcollection.update(select_ind)
            Ucollection.difference_update(select_ind)
            # update model
            self._model.fit(X=self._X[Lcollection.index, :], y=self._y[Lcollection.index])
            pred = self._model.predict(self._X[test_id, :])

            # performance calc
            perf_result = self._performance_metric(pred, self._y[test_id])

            # save intermediate results
            st = State(select_index=select_ind, performance=perf_result)
            saver.add_state(st)
            saver.save()
            # update stopping_criteria
            stopping_criterion.update_information(saver)
def __al_main_loop ( self , round , train_id , test_id , Lcollection , Ucollection , saver , examples = None , labels = None , global_parameters = None ) : Lcollection = IndexCollection ( Lcollection ) Ucollection = IndexCollection ( Ucollection ) self . _model . fit ( X = self . _X [ Lcollection . index , : ] , y = self . _y [ Lcollection . index ] ) pred = self . _model . predict ( self . _X [ test_id , : ] ) # some query strategy,such as QueryInstanceGraphDensity,QueryInstanceQUIRE, need train_ind if self . _query_function_need_train_ind : if self . _query_function_name == 'QueryInstanceGraphDensity' : if self . _query_function_metric is not None : querfunction = QueryInstanceGraphDensity ( self . _X , self . _y , train_id , self . _query_function_metric ) else : raise Exception ( "The QueryInstanceGraphDensity need metric.Please input metric in set_query_strategy()." ) elif self . _query_function_name == 'QueryInstanceQUIRE' : querfunction = QueryInstanceQUIRE ( self . _X , self . _y , train_id , * * self . _query_function_kwargs ) # performance calc perf_result = self . _performance_metric ( pred , self . _y [ test_id ] ) # stopping-criterion  stopping_criterion = copy . deepcopy ( self . _stopping_criterion ) saver . set_initial_point ( perf_result ) while not stopping_criterion . is_stop ( ) : if not self . __custom_strategy_flag : if self . _query_function_name == 'QueryInstanceGraphDensity' : select_ind = querfunction . select ( Lcollection , Ucollection , batch_size = self . _batch_size , * * self . _query_function_kwargs ) elif self . _query_function_name == 'QueryInstanceQUIRE' : select_ind = querfunction . select ( Lcollection , Ucollection , batch_size = self . _batch_size ) elif 'model' in inspect . getfullargspec ( self . _query_function . select ) [ 0 ] : select_ind = self . _query_function . select ( Lcollection , Ucollection , batch_size = self . _batch_size , model = self . _model ) elif self . _query_function_name == 'QueryInstanceBMDR' or self . _query_function_name == 'QueryInstanceSPAL' : select_ind = self . _query_function . select ( Lcollection , Ucollection , batch_size = self . _batch_size , qp_solver = self . qp_solver ) else : select_ind = self . _query_function . select ( Lcollection , Ucollection , batch_size = self . _batch_size ) else : select_ind = self . _query_function . select ( Lcollection , Ucollection , batch_size = self . _batch_size , * * self . __custom_func_arg ) Lcollection . update ( select_ind ) Ucollection . difference_update ( select_ind ) # update model self . _model . fit ( X = self . _X [ Lcollection . index , : ] , y = self . _y [ Lcollection . index ] ) pred = self . _model . predict ( self . _X [ test_id , : ] ) # performance calc perf_result = self . _performance_metric ( pred , self . _y [ test_id ] ) # save intermediate results st = State ( select_index = select_ind , performance = perf_result ) saver . add_state ( st ) saver . save ( ) # update stopping_criteria stopping_criterion . update_information ( saver )