dl4pi is a Python package built with torch. dl4pi is designed to extend traditional economic models using deep learning to capture heterogeneity in data. The package implements the framework proposed in Farrell, Liang and Misra (2021). It lets researchers use neural nets as parameters. These "parameter functions" retain the interpretability, economic meaning, and discipline of classical economic parameters while leveraging the power of machine learning. The package implements automatic inference for functions of these parameters.
The package was developed at the Center for Applied AI at the University of Chicago Booth School of Business.
Warning
While the code is structured as a Python package, this project is not actively maintained. It may contain bugs and there is no support available. Use at your own risk.
- Follow the installation instructions below to install the package.
- Review the example python notebooks on GitHub
- For synthetic examples, code to generate synthetic data is contained in the respective notebook.
- For real experimental examples, data is publicly available and can be obtained per the instructions in
readme.mdinside the data folder.
dl4pi is optimized for Python 3.12. To ensure compatibility, we recommend using a local version of Python and setting up a virtual environment. If you have pyenv, you can take the following steps:
# Clone the repo
git clone [email protected]:Center-for-Applied-AI/dl4pi.git
# Navigate to the directory
cd dl4pi
# Install Python 3.12 using pyenv
pyenv install 3.12
# Set the local Python version to 3.12
pyenv local 3.12
# Install virtualenv
pip install virtualenv
# Create a new virtual environment
virtualenv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install the package
pip install .This package is useful for researchers interested in estimating a population parameter
where
The mapping between individual characteristics and structural parameters
dl4pi implements the estimator proposed in Farrell, Liang and Misra (2021), which is a consistent estimator of
-
Identification: The parameter function
$\theta(x)$ must be identifiable; -
Regularity of the loss and statistic functions:
$l(y, t, \theta(x))$ and$H(\theta(x))$ must be thrice continously differenetiable with respect to$\theta(x)$ and possess$q>4$ finite absolute moments and positive variance. -
Well-behaved Hessian estimator: the conditional expectation of Hessian
$\Lambda(x)$ must have a bounded inverse. -
The model is conditionally unbiased:
$\mathbb{E}[l(Y,t,\theta(x))|X=x, T=t] = 0$
The estimator is calculated as:
where
Given some dataset and a three partition split, the procedure can be repeated three times to collect
| # | |||
|---|---|---|---|
| 1 | A | B | C |
| 2 | B | C | A |
| 3 | C | A | B |
To use the package, all objects from the table below should be defined.
| description | object | example |
|---|---|---|
| structural loss | dl4pi.examples.logit_loss |
|
| causal deep net | dl4pi.examples.cdnn_logit |
|
| statistic function | dl4pi.examples.statistic_function_alpha |
|
| covariates | torch.rand(1000,3) |
|
| outcome | torch.rand(1000,1) |
|
| treatment | torch.rand(1000,2) |
The following code perform cross-fitting:
# Inititalize AutoEstimator
ae = dl4pi.AutoEstimator(
structural_parameters_dimension=2,
statistic_function=statistic_function_alpha,
cdnn_model=cdnn_logit
)
# Perform cross-estimation
ae.cross_estimate(x=x, y=y, t=t)
# Retrieve the results
statistic_function_values = ae.statistic_function_values
psi_values = ae.psi_valuesstatistic_function_values is the tensor of observation level values of psi_values is the tensor of observation level values of
Detailed examples can be found in /examples.
If you found the framework useful, please cite Farrell, Liang and Misra (2021)
@article{dl4pi_paper,
title = {Deep Learning for Individual Heterogeneity: An Automatic Inference Framework},
author = {Max H. Farrell and Tengyuan Liang and Sanjog Misra},
year = {2021},
eprint = {2010.14694},
archivePrefix = {arXiv},
primaryClass = {econ.EM},
url = {https://arxiv.org/abs/2010.14694},
}If you used the dl4pi package in a publication, please also cite
@misc{dl4pi_package,
title = {Dl4pi: Deep Learning for Parameter Inference in Python},
author = {Max H. Farrell and Tengyuan Liang and Sanjog Misra and Janani Sekar and Kirill Skobelev and James Ross},
year = {2024},
url = {https://github.com/Center-for-Applied-AI/dl4pi},
note = {Python package version 1.0.0},
}Farrell, M. H., Liang, T., & Misra, S. (2021). Deep Learning for Individual Heterogeneity: An Automatic Inference Framework. arXiv:2010.14694.

