-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
135 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# ChoiceModels | ||
# See full license in LICENSE | ||
|
||
from .distancematrix import * | ||
from .mergedchoicetable import * | ||
from .simulation import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Choice table utilities API | ||
========================== | ||
|
||
Working with discrete choice models can require a lot of data preparation. Each chooser has to be matched with hypothetical alternatives, either to simulate choice probabilities or to compare them with the chosen alternative for model estimation. | ||
|
||
ChoiceModels includes a class called ``MergedChoiceTable`` that automates this. To build a merged table, create an instance of the class and pass it one ``pd.DataFrame`` of choosers and another of alternatives, with whatever other arguments are needed (see below for full API). | ||
|
||
The merged data table can be output to a DataFrame, or passed directly to other ChoiceModels tools as a ``MergedChoiceTable`` object. (This retains metadata about indexes and other special columns.) | ||
|
||
.. code-block:: python | ||
mct = choicemodels.tools.MergedChoiceTable(obs, alts, ..) | ||
df = mct.to_frame() | ||
This tool is designed especially for models that need to sample from large numbers of alternatives. It supports: | ||
|
||
- uniform random sampling of alternatives, with or without replacement | ||
- weighted random sampling based either on characteristics of the alternatives or on combinations of chooser and alternative | ||
- interaction terms to be merged onto the final data table | ||
- cartesian merging of all the choosers with all the alternatives, without sampling | ||
|
||
All of the sampling procedures work for both estimation (where the chosen alternative is known) and simulation (where it is not). | ||
|
||
|
||
MergedChoiceTable | ||
----------------- | ||
|
||
.. autoclass:: choicemodels.tools.MergedChoiceTable | ||
:members: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Distance utilities API | ||
====================== | ||
|
||
ChoiceModels also includes tools for constructing pairwise distance matrices and calculating which geographies are within various distance bands of some reference geography. | ||
|
||
|
||
Distance matrices | ||
----------------- | ||
|
||
.. autofunction:: choicemodels.tools.great_circle_distance_matrix | ||
|
||
.. autofunction:: choicemodels.tools.euclidean_distance_matrix | ||
|
||
.. autofunction:: choicemodels.tools.distance_matrix | ||
|
||
|
||
Distance bands | ||
-------------- | ||
|
||
.. autofunction:: choicemodels.tools.distance_bands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Getting started | ||
=============== | ||
|
||
Intro | ||
----- | ||
|
||
ChoiceModels is a Python library for discrete choice model estimation, with utilities for sampling, simulation, and other ancillary tasks. It's part of the `Urban Data Science Toolkit <https://github.com/udst>`__ (UDST). | ||
|
||
MORE TK | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
TK | ||
|
||
|
||
Basic usage | ||
----------- | ||
|
||
TK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Multinomial Logit API | ||
===================== | ||
|
||
ChoiceModels has built-in functionality for Multinomial Logit estimation and simulation. This can use either the `PyLogit <https://github.com/timothyb0912/pylogit>`__ MNL estimation engine or a custom engine optimized for fast performance with large numbers of alternatives. The custom engine is originally from ``urbansim.urbanchoice``. | ||
|
||
Fitting a model yields a results object that can generate choice probabilities for out-of-sample scenarios. | ||
|
||
|
||
MultinomialLogit | ||
---------------- | ||
|
||
.. autoclass:: choicemodels.MultinomialLogit | ||
:members: | ||
|
||
|
||
MultinomialLogitResults | ||
----------------------- | ||
|
||
.. autoclass:: choicemodels.MultinomialLogitResults | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Simulation utilities API | ||
======================== | ||
|
||
ChoiceModels provides general-purpose tools for Monte Carlo simulation of choices among alternatives, given probability distributions generated from fitted models. | ||
|
||
``monte_carlo_choices()`` is equivalent to applying ``np.random.choice()`` in parallel for many independent choice scenarios, but it's implemented as a single-pass matrix calculation that is much faster. | ||
|
||
``iterative_lottery_choices()`` is for cases where the alternatives have limited capacity, requiring multiple passes to match choosers and alternatives. Effectively, choices are simulated sequentially, each time removing the chosen alternative or reducing its available capacity. (It's actually done in batches for better performance.) | ||
|
||
|
||
Independent choices | ||
------------------- | ||
|
||
.. autofunction:: choicemodels.tools.monte_carlo_choices | ||
|
||
|
||
Capacity-constrained choices | ||
---------------------------- | ||
|
||
.. autofunction:: choicemodels.tools.iterative_lottery_choices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
coverage >= 4.5 | ||
coveralls >= 1.3 | ||
pytest >= 3.4 | ||
urbansim >= 3.1 | ||
urbansim >= 3.1 | ||
sphinx | ||
numpydoc | ||
sphinx_rtd_theme |