<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from libact . base . interfaces import QueryStrategy , ContinuousModel <EOL> from libact . utils import inherit_docstring_from , zip <EOL> class UncertaintySampling ( QueryStrategy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UncertaintySampling , self ) . __init__ ( * args , ** kwargs ) <EOL> self . model = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if self . model is None : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if not isinstance ( self . model , ContinuousModel ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> self . model . train ( self . dataset ) <EOL> self . method = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . method not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise TypeError ( <EOL> "<STR_LIT>" + self . method <EOL> ) <EOL> @ inherit_docstring_from ( QueryStrategy ) <EOL> def make_query ( self ) : <EOL> dataset = self . dataset <EOL> self . model . train ( dataset ) <EOL> unlabeled_entry_ids , X_pool = zip ( * dataset . get_unlabeled_entries ( ) ) <EOL> if self . method == '<STR_LIT>' : <EOL> ask_id = np . argmin ( <EOL> np . max ( self . model . predict_real ( X_pool ) , axis = <NUM_LIT:1> ) <EOL> ) <EOL> elif self . method == '<STR_LIT>' : <EOL> dvalue = self . model . predict_real ( X_pool ) <EOL> if np . shape ( dvalue ) [ <NUM_LIT:1> ] > <NUM_LIT:2> : <EOL> dvalue = - ( np . partition ( - dvalue , <NUM_LIT:2> , axis = <NUM_LIT:1> ) [ : , : <NUM_LIT:2> ] ) <EOL> margin = np . abs ( dvalue [ : , <NUM_LIT:0> ] - dvalue [ : , <NUM_LIT:1> ] ) <EOL> ask_id = np . argmin ( margin ) <EOL> return unlabeled_entry_ids [ ask_id ] </s>
