(self, strategy="QueryInstanceUncertainty", **kwargs)
Set the query strategy of the experiment.

        Parameters
        ----------
        strategy: {str, callable}, optional (default='QueryInstanceUncertainty')
            The query strategy function.
            Giving str to use a pre-defined strategy.
            Giving callable to use a user-defined strategy.

        kwargs: dict, optional
            The args used in strategy.
            If kwargs is None,the pre-defined query strategy will init in default way.
            (See the default way of pre-defined query strategy in the alipy/query_strategy/'query_strategy' and 'sota_strategy').
            If strategy is a user-define strategy,the parameters accord with definition of function parameter.

            Note that, each parameters should be static.
            The parameters will be fed to the callable object automatically.
Set the query strategy of the experiment.
Set the query strategy of the experiment .
def set_query_strategy(self, strategy="QueryInstanceUncertainty", **kwargs):
        """
            Set the query strategy of the experiment.

        Parameters
        ----------
        strategy: {str, callable}, optional (default='QueryInstanceUncertainty')
            The query strategy function.
            Giving str to use a pre-defined strategy.
            Giving callable to use a user-defined strategy.

        kwargs: dict, optional
            The args used in strategy.
            If kwargs is None,the pre-defined query strategy will init in default way.
            (See the default way of pre-defined query strategy in the alipy/query_strategy/'query_strategy' and 'sota_strategy').
            If strategy is a user-define strategy,the parameters accord with definition of function parameter.

            Note that, each parameters should be static.
            The parameters will be fed to the callable object automatically.
        """
        # check 
        if self._existed_query_strategy:
            raise Exception("You already has set the query strategy,don`t has to set it again.")
        # user-defined strategy
        if callable(strategy):
            self.__custom_strategy_flag = True
            strategyname = kwargs.pop('strategyname', None)
            if strategyname is not None:
                self._query_function_name = strategyname
            else:
                self._query_function_name = 'user-defined strategy'
            self.__custom_func_arg = kwargs
            self._query_function = strategy(self._X, self._y, **kwargs)
        else:
            # a pre-defined strategy in ALiPy
            if strategy not in ['QueryInstanceQBC', 'QueryInstanceUncertainty', 'QueryRandom', 'QueryInstanceRandom',
                                'QueryInstanceGraphDensity', 'QueryInstanceQUIRE',
                                'QueryInstanceBMDR', 'QueryInstanceSPAL', 'QueryInstanceLAL',
                                'QueryExpectedErrorReduction']:
                raise NotImplementedError('Strategy {} is not implemented. Specify a valid '
                                          'method name or privide a callable object.'.format(str(strategy)))
            else:
                self._query_function_name = strategy
                if strategy == 'QueryInstanceQBC':
                    method = kwargs.pop('method', 'query_by_bagging')
                    disagreement = kwargs.pop('disagreement', 'vote_entropy')
                    self._query_function = QueryInstanceQBC(self._X, self._y, method, disagreement)
                elif strategy == 'QueryInstanceUncertainty':
                    measure = kwargs.pop('measure', 'entropy')
                    self._query_function = QueryInstanceUncertainty(self._X, self._y, measure)
                elif strategy == 'QueryInstanceRandom' or strategy == 'QueryRandom':
                    self._query_function = QueryInstanceRandom(self._X, self._y)
                elif strategy == 'QueryExpectedErrorReduction':
                    self._query_function = QueryExpectedErrorReduction(self._X, self._y)
                elif strategy == 'QueryInstanceGraphDensity' or strategy == 'QueryInstanceQUIRE':
                    if self._train_idx is None:
                        raise ValueError(
                            'train_idx is None.Please split data firstly.You can call set_data_split or split_AL to split data.')
                    self._query_function_need_train_ind = True
                    self._query_function_metric = kwargs.pop('metric', 'manhattan')
                    self._query_function_kwargs = kwargs
                elif strategy == 'QueryInstanceBMDR':
                    beta = kwargs.pop('beta', 1000)
                    gamma = kwargs.pop('gamma', 0.1)
                    rho = kwargs.pop('rho', 1)
                    self._query_function = QueryInstanceBMDR(self._X, self._y, beta, gamma, rho, **kwargs)
                    self.qp_solver = kwargs.pop('qp_sover', 'ECOS')
                elif strategy == 'QueryInstanceSPAL':
                    mu = kwargs.pop('mu', 0.1)
                    gamma = kwargs.pop('gamma', 0.1)
                    rho = kwargs.pop('rho', 1)
                    lambda_init = kwargs.pop('lambda_init', 0.1)
                    lambda_pace = kwargs.pop('lambda_pace', 0.01)
                    self._query_function = QueryInstanceSPAL(self._X, self._y, mu, gamma, rho, lambda_init, lambda_pace,
                                                             **kwargs)
                    self.qp_solver = kwargs.pop('qp_sover', 'ECOS')
                elif strategy == 'QueryInstanceLAL':
                    mode = kwargs.pop('mode', 'LAL_iterative')
                    data_path = kwargs.pop('data_path', '.')
                    cls_est = kwargs.pop('cls_est', 50)
                    train_slt = kwargs.pop('train_slt', True)
                    self._query_function = QueryInstanceLAL(self._X, self._y, mode, data_path, cls_est, train_slt,
                                                            **kwargs)
def set_query_strategy ( self , strategy = "QueryInstanceUncertainty" , * * kwargs ) : # check  if self . _existed_query_strategy : raise Exception ( "You already has set the query strategy,don`t has to set it again." ) # user-defined strategy if callable ( strategy ) : self . __custom_strategy_flag = True strategyname = kwargs . pop ( 'strategyname' , None ) if strategyname is not None : self . _query_function_name = strategyname else : self . _query_function_name = 'user-defined strategy' self . __custom_func_arg = kwargs self . _query_function = strategy ( self . _X , self . _y , * * kwargs ) else : # a pre-defined strategy in ALiPy if strategy not in [ 'QueryInstanceQBC' , 'QueryInstanceUncertainty' , 'QueryRandom' , 'QueryInstanceRandom' , 'QueryInstanceGraphDensity' , 'QueryInstanceQUIRE' , 'QueryInstanceBMDR' , 'QueryInstanceSPAL' , 'QueryInstanceLAL' , 'QueryExpectedErrorReduction' ] : raise NotImplementedError ( 'Strategy {} is not implemented. Specify a valid ' 'method name or privide a callable object.' . format ( str ( strategy ) ) ) else : self . _query_function_name = strategy if strategy == 'QueryInstanceQBC' : method = kwargs . pop ( 'method' , 'query_by_bagging' ) disagreement = kwargs . pop ( 'disagreement' , 'vote_entropy' ) self . _query_function = QueryInstanceQBC ( self . _X , self . _y , method , disagreement ) elif strategy == 'QueryInstanceUncertainty' : measure = kwargs . pop ( 'measure' , 'entropy' ) self . _query_function = QueryInstanceUncertainty ( self . _X , self . _y , measure ) elif strategy == 'QueryInstanceRandom' or strategy == 'QueryRandom' : self . _query_function = QueryInstanceRandom ( self . _X , self . _y ) elif strategy == 'QueryExpectedErrorReduction' : self . _query_function = QueryExpectedErrorReduction ( self . _X , self . _y ) elif strategy == 'QueryInstanceGraphDensity' or strategy == 'QueryInstanceQUIRE' : if self . _train_idx is None : raise ValueError ( 'train_idx is None.Please split data firstly.You can call set_data_split or split_AL to split data.' ) self . _query_function_need_train_ind = True self . _query_function_metric = kwargs . pop ( 'metric' , 'manhattan' ) self . _query_function_kwargs = kwargs elif strategy == 'QueryInstanceBMDR' : beta = kwargs . pop ( 'beta' , 1000 ) gamma = kwargs . pop ( 'gamma' , 0.1 ) rho = kwargs . pop ( 'rho' , 1 ) self . _query_function = QueryInstanceBMDR ( self . _X , self . _y , beta , gamma , rho , * * kwargs ) self . qp_solver = kwargs . pop ( 'qp_sover' , 'ECOS' ) elif strategy == 'QueryInstanceSPAL' : mu = kwargs . pop ( 'mu' , 0.1 ) gamma = kwargs . pop ( 'gamma' , 0.1 ) rho = kwargs . pop ( 'rho' , 1 ) lambda_init = kwargs . pop ( 'lambda_init' , 0.1 ) lambda_pace = kwargs . pop ( 'lambda_pace' , 0.01 ) self . _query_function = QueryInstanceSPAL ( self . _X , self . _y , mu , gamma , rho , lambda_init , lambda_pace , * * kwargs ) self . qp_solver = kwargs . pop ( 'qp_sover' , 'ECOS' ) elif strategy == 'QueryInstanceLAL' : mode = kwargs . pop ( 'mode' , 'LAL_iterative' ) data_path = kwargs . pop ( 'data_path' , '.' ) cls_est = kwargs . pop ( 'cls_est' , 50 ) train_slt = kwargs . pop ( 'train_slt' , True ) self . _query_function = QueryInstanceLAL ( self . _X , self . _y , mode , data_path , cls_est , train_slt , * * kwargs )