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.
mnl_estimate
(data, chosen, numalts, GPU=False, coeffrange=(-3, 3), weights=None, lcgrad=False, beta=None)[source]¶ Calculate coefficients of the MNL model.
Parameters: data : 2D 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.
chosen : 2D 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.
numalts : int
The number of alternatives.
GPU : bool, optional
coeffrange : tuple of floats, optional
Limits of (min, max) to which coefficients are clipped.
weights : ndarray, optional
lcgrad : bool, optional
beta : 1D array, optional
Any initial guess for the coefficients.
Returns: log_likelihood : dict
Dictionary of log-likelihood values describing the quality of the model fit.
fit_parameters : pandas.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_simulate
(data, coeff, numalts, GPU=False, returnprobs=True)[source]¶ Get the probabilities for each chooser choosing between numalts alternatives.
Parameters: data : 2D 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.
coeff : 1D array
The model coefficients corresponding to each column in data.
numalts : int
The number of alternatives available to each chooser.
GPU : bool, optional
returnprobs : bool, 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.