TorchDCM
PyTorch-first discrete choice model estimation and econometric inference.
Quick Start | Model Zoo | Installation | Benchmarks | Development
TorchDCM is the importable Python package for discrete choice model estimation.
This repository is intentionally package-first: it keeps the reusable
torchdcm implementation, unit tests, examples, and packaging metadata in one
small repo that users can install and import directly.
The software-paper repository is separate and contains public benchmark data, validation wrappers, plots, comparison tables, generated results, and LaTeX:
torchdcm-paper: validation, benchmarks, datasets, and manuscript
Why TorchDCM
| Goal | What TorchDCM Provides |
|---|---|
| PyTorch-native estimation | Vectorized likelihoods written around tensors and automatic differentiation. |
| Econometric outputs | Classic, robust, and cluster covariance; WTP and elasticity helpers. |
| Model coverage | MNL, NL, CNL, mixed logit, WTP-space, latent class, scaled, ordered, and hybrid choice. |
| Reusable package | Clean import surface with examples and package-level tests. |
| Benchmark companion | Full comparisons live in torchdcm-paper and import this package. |
Installation
python -m pip install torchdcm
For local development:
python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -e ".[dev]"
pytest
Quick Start
import torch
from torchdcm import Beta, ChoiceDataset, MultinomialLogit, UtilitySpec
from torchdcm.datasets import make_swissmetro_like
df = make_swissmetro_like(n_obs=300, seed=7)
data = ChoiceDataset.from_wide(
df,
alternatives=["TRAIN", "SM", "CAR"],
choice="choice",
variables={
"time": {"TRAIN": "time_train", "SM": "time_sm", "CAR": "time_car"},
"cost": {"TRAIN": "cost_train", "SM": "cost_sm", "CAR": "cost_car"},
},
availability={
"TRAIN": "avail_train",
"SM": "avail_sm",
"CAR": "avail_car",
},
individual_id="person_id",
)
spec = UtilitySpec()
spec.utility(
"TRAIN",
Beta("ASC_TRAIN")
+ Beta("B_TIME", init=-0.01) * "time"
+ Beta("B_COST", init=-0.1) * "cost",
)
spec.utility(
"SM",
Beta("B_TIME", init=-0.01) * "time"
+ Beta("B_COST", init=-0.1) * "cost",
)
spec.utility(
"CAR",
Beta("ASC_CAR")
+ Beta("B_TIME", init=-0.01) * "time"
+ Beta("B_COST", init=-0.1) * "cost",
)
device = "cuda" if torch.cuda.is_available() else "cpu"
result = MultinomialLogit(spec, device=device).fit(data, cov_type="cluster", groups="person_id")
print(result.summary())
summary() renders an organized console report covering the model and data,
convergence diagnostics, fit statistics, inference, alternative shares, and
parameter estimates. The same structured report can be inspected as tables or
saved as a reproducible artifact directory:
report = result.report(cov_type="cluster", confidence_level=0.95)
parameter_table = report.parameters
result.save_report(
"outputs/swissmetro_mnl",
formats=["html", "json", "csv", "latex", "text"],
)
The output directory contains a readable HTML report, a machine-readable JSON record, parameter/covariance/correlation CSV files, a LaTeX fragment, and a plain-text summary.
All estimators accept a standard PyTorch-style device argument. Passing
device="cuda" moves estimation, prediction, simulated likelihoods, and
covariance calculations for that model to CUDA when your PyTorch installation
has GPU support.
Model Zoo
The current package includes:
- multinomial logit / conditional logit;
- nested logit and cross-nested logit;
- mixed logit, WTP-space mixed logit, and error-components logit;
- latent-class logit;
- scaled and covariate-scaled multinomial logit;
- ordered logit and ordered probit;
- hybrid choice with latent variables and Gaussian measurement indicators;
- classic, robust, and cluster covariance estimates;
- WTP and elasticity helpers.
Repository Layout
| Path | Purpose |
|---|---|
torchdcm/ |
Importable package implementation. |
tests/ |
Package-level unit tests. |
examples/ |
Minimal runnable usage examples. |
docs/assets/ |
GitHub README logo and cover assets. |
pyproject.toml |
Packaging metadata and dependencies. |
Development
python -m pip install -e ".[dev]"
pytest
Benchmark and manuscript work should happen in the companion repository:
git clone https://github.com/mbc96325/torchdcm-paper.git
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchdcm-0.1.0.tar.gz.
File metadata
- Download URL: torchdcm-0.1.0.tar.gz
- Upload date:
- Size: 59.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0a54b11d04071c7c85ca82ac1c5ed1565b398c93f87ebb3e2cc02898dec66fd
|
|
| MD5 |
c7561c3129248f65fb654606d0bc6b87
|
|
| BLAKE2b-256 |
00845b859a636169888babc110bbc1ac59d8e348f5df7613255020c0e8cc54ea
|
Provenance
The following attestation bundles were made for torchdcm-0.1.0.tar.gz:
Publisher:
publish.yml on mbc96325/torchdcm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchdcm-0.1.0.tar.gz -
Subject digest:
b0a54b11d04071c7c85ca82ac1c5ed1565b398c93f87ebb3e2cc02898dec66fd - Sigstore transparency entry: 2204856261
- Sigstore integration time:
-
Permalink:
mbc96325/torchdcm@fc4eba60b9e69070d2f0732a28fc4c0d86b9f0af -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mbc96325
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc4eba60b9e69070d2f0732a28fc4c0d86b9f0af -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file torchdcm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torchdcm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 75.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d956aa21a245f471a33786660f2136c12425fc7f42d8b906f91b37c35d95d0c1
|
|
| MD5 |
976407bea64717ac4bc86961188d726a
|
|
| BLAKE2b-256 |
02208810ed53721af887efa2a5487d33944cc508a714dcf628ec065601cc5fbd
|
Provenance
The following attestation bundles were made for torchdcm-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mbc96325/torchdcm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchdcm-0.1.0-py3-none-any.whl -
Subject digest:
d956aa21a245f471a33786660f2136c12425fc7f42d8b906f91b37c35d95d0c1 - Sigstore transparency entry: 2204856274
- Sigstore integration time:
-
Permalink:
mbc96325/torchdcm@fc4eba60b9e69070d2f0732a28fc4c0d86b9f0af -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mbc96325
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc4eba60b9e69070d2f0732a28fc4c0d86b9f0af -
Trigger Event:
workflow_dispatch
-
Statement type: