Location Choice Utilities

Multinomial Logit API

Number crunching code for multinomial logit. mnl_estimate and mnl_simulate especially are used by urbansim.models.lcm.

urbansim.urbanchoice.mnl.get_hessian(derivative)[source]
urbansim.urbanchoice.mnl.get_standard_error(hessian)[source]
urbansim.urbanchoice.mnl.mnl_estimate(data, chosen, numalts, GPU=False, coeffrange=- 3, 3, weights=None, lcgrad=False, beta=None)[source]

Calculate coefficients of the MNL model.

Parameters
data2D array

The data are expected to be in “long” form where each row is for one alternative. Alternatives are in groups of numalts rows per choosers. Alternatives must be in the same order for each chooser.

chosen2D array

This boolean array has a row for each chooser and a column for each alternative. The column ordering for alternatives is expected to be the same as their row ordering in the data array. A one (True) indicates which alternative each chooser has chosen.

numaltsint

The number of alternatives.

GPUbool, optional
coeffrangetuple of floats, optional

Limits of (min, max) to which coefficients are clipped.

weightsndarray, optional
lcgradbool, optional
beta1D array, optional

Any initial guess for the coefficients.

Returns
log_likelihooddict

Dictionary of log-likelihood values describing the quality of the model fit.

fit_parameterspandas.DataFrame

Table of fit parameters with columns ‘Coefficient’, ‘Std. Error’, ‘T-Score’. Each row corresponds to a column in data and are given in the same order as in data.

See also

scipy.optimize.fmin_l_bfgs_b

The optimization routine used.

urbansim.urbanchoice.mnl.mnl_loglik(beta, data, chosen, numalts, weights=None, lcgrad=False, stderr=0)[source]
urbansim.urbanchoice.mnl.mnl_probs(data, beta, numalts)[source]
urbansim.urbanchoice.mnl.mnl_simulate(data, coeff, numalts, GPU=False, returnprobs=True)[source]

Get the probabilities for each chooser choosing between numalts alternatives.

Parameters
data2D array

The data are expected to be in “long” form where each row is for one alternative. Alternatives are in groups of numalts rows per choosers. Alternatives must be in the same order for each chooser.

coeff1D array

The model coefficients corresponding to each column in data.

numaltsint

The number of alternatives available to each chooser.

GPUbool, optional
returnprobsbool, optional

If True, return the probabilities for each chooser/alternative instead of actual choices.

Returns
probs or choices: 2D array

If returnprobs is True the probabilities are a 2D array with a row for each chooser and columns for each alternative.

Interaction Datasets API

Utilities for making merged interaction tables of choosers and the alternatives from which they are choosing. Used for location choice models.

urbansim.urbanchoice.interaction.enable_gpu()[source]
urbansim.urbanchoice.interaction.mnl_interaction_dataset(choosers, alternatives, SAMPLE_SIZE, chosenalts=None)[source]