{ "cells": [ { "cell_type": "markdown", "source": [ "# Numerical Integration\n", "\n", "One important component of the solution to the DCDP problem in **respy** models is numerical integration. A bottleneck in solving and estimating the model is the solution of the expected value function, the so-called $EMax(\\cdot)$. Solving the $EMax(\\cdot)$ requires us to solve a multi-dimensional integral at every point in the state space. The integrated value function does not have an analytical solution and thus requires the application of numerical methods.\n", "\n", "As the models become more complex, the computational burden increases as adding new features to the model increases the required number of function evaluations, which are the costly operation in numerical integration. Numerical integration usually uses monte carlo simulation. Results from applied mathematics, however, suggest methods that are more efficient and thus enable a performance increase. For the same number of function evaluations (and hence computational cost) quasi-Monte Carlo methods achieve a significantly higher accuracy. **respy** thus enables users to select between various methods for the numerical approximation of the $EMax(\\cdot)$. The numerical integration is controlled in the `options` of a specified model.\n" ], "metadata": {} }, { "cell_type": "code", "execution_count": 2, "source": [ "import respy as rp\r\n", "_, options = rp.get_example_model(\"kw_94_one\", with_data=False)" ], "outputs": [], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Numerical integration method\n", "\n", "The option `monte_carlo_sequence` controls how points are drawn.\n", "\n", "- `random`: Points are drawn randomly (crude Monte Carlo).\n", "- `sobol` or `halton`: Points are drawn from low-discrepancy sequences (superiority in coverage). This means a given approximation error can be achieved with less points." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "
\r\n", "**Note**: **respy** relies on [chaospy](https://chaospy.readthedocs.io/en/master) for the `sobol` and `halton` sequence. You need to install it in addition to **respy**.\r\n", "
" ], "metadata": {} }, { "cell_type": "code", "execution_count": 3, "source": [ "options[\"monte_carlo_sequence\"]" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'random'" ] }, "metadata": {}, "execution_count": 3 } ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Solution draws\r\n", "\r\n", "The number of solution draws controls how many points are used to evaluate an integral. You can specify them using the option `solution_draws`." ], "metadata": {} }, { "cell_type": "code", "execution_count": 4, "source": [ "options[\"solution_draws\"]" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "500" ] }, "metadata": {}, "execution_count": 4 } ], "metadata": {} }, { "cell_type": "markdown", "source": [ "Increasing the number of solution draws increases the accuracy of the solution at the cost of the computational burden." ], "metadata": {} }, { "cell_type": "raw", "source": [ "
\r\n", " Project\r\n", "\r\n", " Find an exploration of numerical integration methods in \r\n", " EKW models in Improving the Numerical Integration.\r\n", "
" ], "metadata": {} } ], "metadata": { "kernelspec": { "name": "python3", "display_name": "Python 3.9.5 64-bit ('respy': conda)" }, "language_info": { "name": "python", "version": "3.9.6", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" }, "interpreter": { "hash": "b549dadab0c2edb1c58f223f7584f57e60f2cc8e65ef8392efb9b23cb30dad20" } }, "nbformat": 4, "nbformat_minor": 4 }