def probabilities(self, choosers, alternatives, filter_tables=True):
        logger.debug('start: calculate probabilities for LCM model {}'.format(
            self.name))
        self.assert_fitted()

        if filter_tables:
            choosers, alternatives = self.apply_predict_filters(
                choosers, alternatives)

        if self.prediction_sample_size is not None:
            sample_size = self.prediction_sample_size
        else:
            sample_size = len(alternatives)

        if self.probability_mode == 'single_chooser':
            _, merged, _ = interaction.mnl_interaction_dataset(
                choosers.head(1), alternatives, sample_size)
        elif self.probability_mode == 'full_product':
            _, merged, _ = interaction.mnl_interaction_dataset(
                choosers, alternatives, sample_size)
        else:
            raise ValueError(
                'Unrecognized probability_mode option: {}'.format(
                    self.probability_mode))

        merged = util.apply_filter_query(
            merged, self.interaction_predict_filters)
        model_design = dmatrix(
            self.str_model_expression, data=merged, return_type='dataframe')

        if len(merged) != model_design.as_matrix().shape[0]:
            raise ModelEvaluationError(
                'Simulated data does not have the same length as input.  '
                'This suggests there are null values in one or more of '
                'the input columns.')

        # get the order of the coefficients in the same order as the
        # columns in the design matrix
        coeffs = [self.fit_parameters['Coefficient'][x]
                  for x in model_design.columns]

        # probabilities are returned from mnl_simulate as a 2d array
        # with choosers along rows and alternatives along columns
        if self.probability_mode == 'single_chooser':
            numalts = len(merged)
        else:
            numalts = sample_size

        probabilities = mnl.mnl_simulate(
            model_design.as_matrix(),
            coeffs,
            numalts=numalts, returnprobs=True)

        # want to turn probabilities into a Series with a MultiIndex
        # of chooser IDs and alternative IDs.
        # indexing by chooser ID will get you the probabilities
        # across alternatives for that chooser
        mi = pd.MultiIndex.from_arrays(
            [merged['join_index'].values, merged.index.values],
            names=('chooser_id', 'alternative_id'))
        probabilities = pd.Series(probabilities.flatten(), index=mi)

        logger.debug('finish: calculate probabilities for LCM model {}'.format(
            self.name))
        return probabilities
Read lines, continuing if a blocking system call gets interrupted.
dataset/ETHPy150Open UDST/urbansim/urbansim/models/dcm.py/MNLDiscreteChoiceModel.probabilities--crossover with--dataset/ETHPy150Open larsyencken/anytop/anytop/common.py/robust_line_iter