#NEWLINE# @ classmethod #NEWLINE# def predict_from_cfg( cls , choosers , alternatives , cfgname , alternative_ratio = 2.0 , debug = False ) : #NEWLINE# #INDENT# '\n        Simulate the discrete choices for the specified choosers\n\n        Parameters\n        ----------\n        choosers : DataFrame\n            A dataframe of agents doing the choosing.\n        alternatives : DataFrame\n            A dataframe of alternatives which the choosers are locating in and\n            which have a supply.\n        cfgname : string\n            The name of the yaml config file from which to read the discrete\n            choice model.\n        alternative_ratio : float\n            Above the ratio of alternatives to choosers (default of 2.0),\n            the alternatives will be sampled to meet this ratio\n            (for performance reasons).\n\n        Returns\n        -------\n        choices : pandas.Series\n            Mapping of chooser ID to alternative ID. Some choosers\n            will map to a nan value when there are not enough alternatives\n            for all the choosers.\n        lcm : SegmentedMNLDiscreteChoiceModel which was used to predict\n        ' #NEWLINE# logger . debug ( 'start: predict from configuration {}' . format ( cfgname ) ) #NEWLINE# lcm = cls . from_yaml ( str_or_buffer = cfgname ) #NEWLINE# if ( len ( alternatives ) > ( len ( choosers ) * alternative_ratio ) ) : #NEWLINE# #INDENT# logger . info ( ( 'Alternative ratio exceeded: %d alternatives and only %d choosers' % ( len ( alternatives ) , len ( choosers ) ) ) ) #NEWLINE# idxes = np . random . choice ( alternatives . index , size = np . floor ( ( len ( choosers ) * alternative_ratio ) ) , replace = False ) #NEWLINE# alternatives = alternatives . loc [ idxes ] #NEWLINE# logger . info ( ( '  after sampling %d alternatives are available\n' % len ( alternatives ) ) ) #NEWLINE# #UNINDENT# new_units = lcm . predict ( choosers , alternatives , debug = debug ) #NEWLINE# print ( ( 'Assigned %d choosers to new units' % len ( new_units . dropna ( ) ) ) ) #NEWLINE# logger . debug ( 'finish: predict from configuration {}' . format ( cfgname ) ) #NEWLINE# return ( new_units , lcm )