(self, choosers, alternatives, debug=False)
return choices
Choose from among alternatives for a group of agents.

        Parameters
        ----------
        choosers : pandas.DataFrame
            Table describing the agents making choices, e.g. households.
        alternatives : pandas.DataFrame
            Table describing the things from which agents are choosing.
        debug : bool
            If debug is set to true, will set the variable "sim_pdf" on
            the object to store the probabilities for mapping of the
            outcome.

        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.
Choose from among alternatives for a group of agents.
Choose from among alternatives for a group of agents .
def predict(self, choosers, alternatives, debug=False):
        """
        Choose from among alternatives for a group of agents.

        Parameters
        ----------
        choosers : pandas.DataFrame
            Table describing the agents making choices, e.g. households.
        alternatives : pandas.DataFrame
            Table describing the things from which agents are choosing.
        debug : bool
            If debug is set to true, will set the variable "sim_pdf" on
            the object to store the probabilities for mapping of the
            outcome.

        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.

        """
        self.assert_fitted()
        logger.debug('start: predict LCM model {}'.format(self.name))

        choosers, alternatives = self.apply_predict_filters(
            choosers, alternatives)

        if len(choosers) == 0:
            return pd.Series()

        if len(alternatives) == 0:
            return pd.Series(index=choosers.index)

        probabilities = self.probabilities(
            choosers, alternatives, filter_tables=False)

        if debug:
            self.sim_pdf = probabilities

        if self.choice_mode == 'aggregate':
            choices = unit_choice(
                choosers.index.values,
                probabilities.index.get_level_values('alternative_id').values,
                probabilities.values)
        elif self.choice_mode == 'individual':
            def mkchoice(probs):
                probs.reset_index(0, drop=True, inplace=True)
                return np.random.choice(
                    probs.index.values, p=probs.values / probs.sum())
            choices = probabilities.groupby(level='chooser_id', sort=False)\
                .apply(mkchoice)
        else:
            raise ValueError(
                'Unrecognized choice_mode option: {}'.format(self.choice_mode))

        logger.debug('finish: predict LCM model {}'.format(self.name))
        return choices
def predict ( self , choosers , alternatives , debug = False ) : self . assert_fitted ( ) logger . debug ( 'start: predict LCM model {}' . format ( self . name ) ) choosers , alternatives = self . apply_predict_filters ( choosers , alternatives ) if len ( choosers ) == 0 : return pd . Series ( ) if len ( alternatives ) == 0 : return pd . Series ( index = choosers . index ) probabilities = self . probabilities ( choosers , alternatives , filter_tables = False ) if debug : self . sim_pdf = probabilities if self . choice_mode == 'aggregate' : choices = unit_choice ( choosers . index . values , probabilities . index . get_level_values ( 'alternative_id' ) . values , probabilities . values ) elif self . choice_mode == 'individual' : def mkchoice ( probs ) : probs . reset_index ( 0 , drop = True , inplace = True ) return np . random . choice ( probs . index . values , p = probs . values / probs . sum ( ) ) choices = probabilities . groupby ( level = 'chooser_id' , sort = False ) . apply ( mkchoice ) else : raise ValueError ( 'Unrecognized choice_mode option: {}' . format ( self . choice_mode ) ) logger . debug ( 'finish: predict LCM model {}' . format ( self . name ) ) return choices