<s> """<STR_LIT>""" <EOL> from pebl import prior , config , evaluator , result , network <EOL> from pebl . learner . base import Learner <EOL> from pebl . taskcontroller . base import Task <EOL> class ListLearner ( Learner ) : <EOL> _params = ( <EOL> config . StringParameter ( <EOL> '<STR_LIT>' , <EOL> """<STR_LIT>""" , <EOL> default = '<STR_LIT>' <EOL> ) <EOL> ) <EOL> def __init__ ( self , data_ = None , prior_ = None , networks = None ) : <EOL> """<STR_LIT>""" <EOL> super ( ListLearner , self ) . __init__ ( data_ , prior_ ) <EOL> self . networks = networks <EOL> if not networks : <EOL> variables = self . data . variables <EOL> _net = lambda netstr : network . Network ( variables , netstr ) <EOL> netstrings = config . get ( '<STR_LIT>' ) . splitlines ( ) <EOL> self . networks = ( _net ( s ) for s in netstrings if s ) <EOL> def run ( self ) : <EOL> self . result = result . LearnerResult ( self ) <EOL> self . evaluator = evaluator . fromconfig ( self . data , prior_ = self . prior ) <EOL> self . result . start_run ( ) <EOL> for net in self . networks : <EOL> self . result . add_network ( net , self . evaluator . score_network ( net ) ) <EOL> self . result . stop_run ( ) <EOL> return self . result <EOL> def split ( self , count ) : <EOL> """<STR_LIT>""" <EOL> nets = list ( self . networks ) <EOL> numnets = len ( nets ) <EOL> netspertask = numnets / count <EOL> indices = [ [ i , i + netspertask ] for i in xrange ( <NUM_LIT:0> , numnets , netspertask ) ] <EOL> if len ( indices ) > count : <EOL> indices . pop ( - <NUM_LIT:1> ) <EOL> indices [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] = numnets - <NUM_LIT:1> <EOL> return [ ListLearner ( self . data , self . prior , nets [ i : j ] ) for i , j in indices ] <EOL> def __getstate__ ( self ) : <EOL> d = self . __dict__ <EOL> d [ '<STR_LIT>' ] = list ( d [ '<STR_LIT>' ] ) <EOL> return d </s>
