Functions for working with the discrete-continuous EGM (DCEGM) algorithm as described in “The endogenous grid method for discrete-continuous dynamic choice models with (or without) taste shocks” by Iskhakov et al. (2016) [https://doi.org/10.3982/QE643 and ijrsDCEGM2017 in our Zotero]
Example can be found in https://github.com/econ-ark/DemARK/blob/master/notebooks/DCEGM-Upper-Envelope.ipynb
calc_cross_points(mGrid, condVs, optIdx)¶
Given a grid of m values, a matrix of the conditional values of different actions at every grid point, and a vector indicating the optimal action at each grid point, this function computes the coordinates of the crossing points that happen when the optimal action changes
- mGrid (np.array) – Market resources grid.
- condVs (np.array must have as many rows as possible discrete actions, and) – as many columns as m gridpoints there are. Conditional value functions
- optIdx (np.array of indices) – Optimal decision at each grid point
- xing_points ([tuple]) – List of crossing points, each as an (m,v) tuple.
- segments (np.array with two columns and as many rows as xing points.) – Each row represents a crossing point. The first column is the index of the optimal action to the left, and the second, to the right.
calc_linear_crossing(m, left_v, right_v)¶
Computes the intersection between two line segments, defined by two common x points, and the values of both segments at both x points
- (m_int, v_int) (a tuple with the corrdinates of the intercept.)
- if there is no intercept in the interval [m,m], (None,None)
calc_multiline_envelope(M, C, V_T, commonM, find_crossings=False)¶
Do the envelope step of the DCEGM algorithm. Takes in market ressources, consumption levels, and inverse values from the EGM step. These represent (m, c) pairs that solve the necessary first order conditions. This function calculates the optimal (m, c, v_t) pairs on the commonM grid.
- M (np.array) – market ressources from EGM step
- C (np.array) – consumption from EGM step
- V_T (np.array) – transformed values at the EGM grid
- commonM (np.array) – common grid to do upper envelope calculations on
- find_crossings (boolean) – should the exact crossing points of segments be computed and added to the grids?
calc_prim_kink(mGrid, vTGrids, choices)¶
- mGrid (np.array) – Common m grid
- vTGrids ([np.array], length = # choices, each element has length = len(mGrid)) – value functions evaluated on the common m grid.
- choices ([np.array], length = # choices, each element has length = len(mGrid)) – Optimal choices. In the form of choice probability vectors that must be degenerate
- kinks ([(mCoord, vTCoor)]) – list of kink points
- segments ([(left, right)]) – List of the same length as kinks, where each element is a tuple indicating which segments are optimal on each side of the kink.
Find index vectors rise and fall such that rise holds the indeces i such that x[i+1]>x[i] and fall holds indeces j such that either - x[j+1] < x[j] or, - x[j]>x[j-1] and v[j]<v[j-1].
The vectors are essential to the DCEGM algorithm, as they definite the relevant intervals to be used to construct the upper envelope of potential solutions to the (necessary) first order conditions.
- x (np.ndarray) – array of points where v is evaluated
- v (np.ndarray) – array of values of some function of x
- rise (np.ndarray) – see description above
- fall (np.ndarray) – see description above