(cls, choosers, alternatives, cfgname=None, cfg=None,
                         alternative_ratio=2.0, debug=False)
return new_units, lcm
Simulate choices for the specified choosers

        Parameters
        ----------
        choosers : DataFrame
            A dataframe of agents doing the choosing.
        alternatives : DataFrame
            A dataframe of locations which the choosers are locating in and
            which have a supply.
        cfgname : string
            The name of the yaml config file from which to read the discrete
            choice model.
        cfg: string
            an ordered yaml string of the model discrete choice model configuration.
            Used to read config from memory in lieu of loading cfgname from disk.
        alternative_ratio : float, optional
            Above the ratio of alternatives to choosers (default of 2.0),
            the alternatives will be sampled to meet this ratio
            (for performance reasons).
        debug : boolean, optional (default False)
            Whether to generate debug information on the model.

        Returns
        -------
        choices : pandas.Series
            Mapping of chooser ID to alternative ID. Some choosers
            will map to a nan value when there are not enough alternatives
            for all the choosers.
        lcm : MNLDiscreteChoiceModel which was used to predict
Simulate choices for the specified choosers
Simulate choices for the specified choosers
def predict_from_cfg(cls, choosers, alternatives, cfgname=None, cfg=None,
                         alternative_ratio=2.0, debug=False):
        """
        Simulate choices for the specified choosers

        Parameters
        ----------
        choosers : DataFrame
            A dataframe of agents doing the choosing.
        alternatives : DataFrame
            A dataframe of locations which the choosers are locating in and
            which have a supply.
        cfgname : string
            The name of the yaml config file from which to read the discrete
            choice model.
        cfg: string
            an ordered yaml string of the model discrete choice model configuration.
            Used to read config from memory in lieu of loading cfgname from disk.
        alternative_ratio : float, optional
            Above the ratio of alternatives to choosers (default of 2.0),
            the alternatives will be sampled to meet this ratio
            (for performance reasons).
        debug : boolean, optional (default False)
            Whether to generate debug information on the model.

        Returns
        -------
        choices : pandas.Series
            Mapping of chooser ID to alternative ID. Some choosers
            will map to a nan value when there are not enough alternatives
            for all the choosers.
        lcm : MNLDiscreteChoiceModel which was used to predict
        """
        logger.debug('start: predict from configuration {}'.format(cfgname))
        if cfgname:
            lcm = cls.from_yaml(str_or_buffer=cfgname)
        elif cfg:
            lcm = cls.from_yaml(yaml_str=cfg)
        else:
            msg = 'predict_from_cfg requires a configuration via the cfgname or cfg arguments'
            logger.error(msg)
            raise ValueError(msg)

        if len(alternatives) > len(choosers) * alternative_ratio:
            logger.info(
                ("Alternative ratio exceeded: %d alternatives "
                 "and only %d choosers") %
                (len(alternatives), len(choosers)))
            idxes = np.random.choice(
                alternatives.index, size=int(len(choosers) *
                                             alternative_ratio),
                replace=False)
            alternatives = alternatives.loc[idxes]
            logger.info(
                "  after sampling %d alternatives are available\n" %
                len(alternatives))

        new_units = lcm.predict(choosers, alternatives, debug=debug)
        print("Assigned %d choosers to new units" % len(new_units.dropna()))
        logger.debug('finish: predict from configuration {}'.format(cfgname))
        return new_units, lcm
def predict_from_cfg ( cls , choosers , alternatives , cfgname = None , cfg = None , alternative_ratio = 2.0 , debug = False ) : logger . debug ( 'start: predict from configuration {}' . format ( cfgname ) ) if cfgname : lcm = cls . from_yaml ( str_or_buffer = cfgname ) elif cfg : lcm = cls . from_yaml ( yaml_str = cfg ) else : msg = 'predict_from_cfg requires a configuration via the cfgname or cfg arguments' logger . error ( msg ) raise ValueError ( msg ) if len ( alternatives ) > len ( choosers ) * alternative_ratio : logger . info ( ( "Alternative ratio exceeded: %d alternatives " "and only %d choosers" ) % ( len ( alternatives ) , len ( choosers ) ) ) idxes = np . random . choice ( alternatives . index , size = int ( len ( choosers ) * alternative_ratio ) , replace = False ) alternatives = alternatives . loc [ idxes ] logger . info ( "  after sampling %d alternatives are available\n" % len ( alternatives ) ) new_units = lcm . predict ( choosers , alternatives , debug = debug ) print ( "Assigned %d choosers to new units" % len ( new_units . dropna ( ) ) ) logger . debug ( 'finish: predict from configuration {}' . format ( cfgname ) ) return new_units , lcm