You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/calvo.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -291,7 +291,7 @@ where $\beta \in (0,1)$ is a discount factor.
291
291
292
292
```{note}
293
293
We define $ r(x_t,\mu_t) := - s(\theta_t, \mu_t) $ as we do in order to represent the government's **maximum** problem in terms of our Python code for solving linear quadratic discounted dynamic programs.
294
-
In earlier quantecon lectures, we formulated these as **loss minimization** problems.
294
+
In [first LQ control lecture](https://python-intro.quantecon.org/lqcontrol.html) and some other quantecon lectures, we formulated these as **loss minimization** problems.
295
295
```
296
296
297
297
The government's time $t$ continuation value $v_t$ is
Copy file name to clipboardExpand all lines: lectures/match_transport.md
+71-39Lines changed: 71 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,30 +15,30 @@ kernelspec:
15
15
16
16
+++
17
17
18
-
## Introduction
18
+
## Overview
19
19
20
-
This lecture presents Python code for solving **composite sorting** problems of the kind
21
-
studied in *Composite Sorting* by Job Boerma, Aleh Tsyvinski, Ruodo Wang,
22
-
and Zhenyuan Zhang {cite}`boerma2023composite`.
20
+
This lecture describes how Job Boerma, Aleh Tsyvinski, Ruodo Wang,
21
+
and Zhenyuan Zhang {cite}`boerma2023composite` used optimal transport theory to formulate and solve an equilibrium of a model in which wages and allocations of workers across jobs adjust to match measures of different types with measures of different types of occupations.
23
22
24
-
In this lecture, we will use the following imports
23
+
Production technologies allow firms to affect shape costs of mismatch with the consequence
24
+
that costs of mismatch can be concave.
25
25
26
-
```{code-cell} ipython3
27
-
import numpy as np
28
-
from scipy.optimize import linprog
29
-
from itertools import chain
30
-
import pandas as pd
31
-
from collections import namedtuple
26
+
That means that it possible that equilibrium there is neither **positive assortive** nor **negative assorting** matching, an outcome that {cite}`boerma2023composite` call **composite assortive** matching.
27
+
28
+
In such an equilibrium with composite matching, for example, identical workers can sort into different occupations, some positively and some negatively.
29
+
30
+
{cite}`boerma2023composite`
31
+
show how this can generate distinct distributions of labor earnings within and across occupations.
32
+
33
+
34
+
This lecture describes the {cite}`boerma2023composite` model and presents Python code for computing equilibria.
35
+
36
+
It then applies the code to their model of labor markets.
37
+
38
+
As with our earlier lecture on optimal transport (https://python.quantecon.org/opt_transport.html), a key tool will be **linear programming**.
32
39
33
40
34
-
import matplotlib.pyplot as plt
35
-
import matplotlib.patches as patches
36
-
from matplotlib.ticker import MaxNLocator
37
-
from matplotlib import cm
38
-
from matplotlib.colors import Normalize
39
-
```
40
41
41
-
+++ {"user_expressions": []}
42
42
43
43
## Setup
44
44
@@ -49,7 +49,7 @@ For each $x \in X,$ let a positive integer $n_x$ be the number of agents of typ
49
49
50
50
Similarly, let a positive integer $m_y$ be the agents of agents of type $y \in Y$.
51
51
52
-
We will refer to these two measures as *marginals*.
52
+
We refer to these two measures as *marginals*.
53
53
54
54
We assume that
55
55
@@ -73,15 +73,15 @@ $$
73
73
Given our discreteness assumptions about $n$ and $m$, the problem admits an integer solution $\mu \in \mathbb{Z}_+^{X \times Y}$, i.e. $\mu_{xy}$ is a non-negative integer for each $x\in X, y\in Y$.
74
74
75
75
76
-
In this notebook, we will focus on integer solutions of the problem.
76
+
We will study integer solutions.
77
77
78
-
Two points on the integer assumption are worth mentioning:
78
+
Two points about restricting ourselves to integer solutions are worth mentioning:
79
79
80
80
* it is without loss of generality for computational purposes, since every problem with float marginals can be transformed into an equivalent problem with integer marginals;
81
-
*arguments below work for arbitrary real marginals from a mathematical standpoint, but some of the implementations will fail to work with float arithmetic.
81
+
*although the mathematical structure that we present actually wors for arbitrary real marginals, some of our Python implementations would fail to work with float arithmetic.
82
82
83
83
84
-
Our focus in this notebook is a specific instance of the optimal transport problem:
84
+
We focus on a specific instance of an optimal transport problem:
85
85
86
86
We assume that $X$ and $Y$ are finite subsets of $\mathbb{R}$ and that the cost function satisfies $c_{xy} = h(|x - y|)$ for all $x,y \in \mathbb{R},$ for an $h: \mathbb{R}_+ \rightarrow \mathbb{R}_+$ that is **strictly concave** and **strictly increasing** and **grounded** (i.e., $h(0)=0$).
87
87
@@ -112,7 +112,29 @@ $$
112
112
\end{aligned}
113
113
$$
114
114
115
-
The following class takes as inputs sets of types $X,Y \subset \mathbb{R},$ marginals $n, m $ with positive integer entries such that $\sum_{x \in X} n_x = \sum_{y \in Y} m_y $ and cost parameter $\zeta>1$.
115
+
116
+
Let's start setting up some Python code.
117
+
118
+
We use the following imports:
119
+
120
+
```{code-cell} ipython3
121
+
import numpy as np
122
+
from scipy.optimize import linprog
123
+
from itertools import chain
124
+
import pandas as pd
125
+
from collections import namedtuple
126
+
127
+
128
+
import matplotlib.pyplot as plt
129
+
import matplotlib.patches as patches
130
+
from matplotlib.ticker import MaxNLocator
131
+
from matplotlib import cm
132
+
from matplotlib.colors import Normalize
133
+
```
134
+
135
+
+++ {"user_expressions": []}
136
+
137
+
The following Python class takes as inputs sets of types $X,Y \subset \mathbb{R},$ marginals $n, m $ with positive integer entries such that $\sum_{x \in X} n_x = \sum_{y \in Y} m_y $ and cost parameter $\zeta>1$.
116
138
117
139
118
140
The cost function is stored as an $|X| \times |Y|$ matrix with $(x,y)$-entry equal to $|x-y|^{1/\zeta},$ i.e., the cost of matching an agent of type $x \in X$ with an agent of type $y \in Y.$
Having computed the value function, we can proceed to compute the optimal matching as the *policy* that attains the value function that solves the Bellman equation (*policy evaluation*).
845
867
846
-
Specifically, we start from agent $1$ and match it with the $k$ that achieves the minimum in the equation associated with $V_{1,2N_\ell};$
868
+
We start from agent $1$ and match it with the $k$ that achieves the minimum in the equation associated with $V_{1,2N_\ell}.$
847
869
848
870
Then we store segments $[2,k-1]$ and $[k+1,2N_\ell]$ (if not empty).
We will now present two key results in the context of OT with concave type costs.
985
+
We now present two key results in the context of OT with concave type costs.
964
986
965
987
We refer {cite}`boerma2023composite` and {cite}`delon2011minimum` for proofs.
966
988
@@ -1046,7 +1068,7 @@ print(f"Difference with previous Bellman equations: \
1046
1068
1047
1069
+++ {"user_expressions": []}
1048
1070
1049
-
Thanks to the results in this section, we can actually compute the optimal matching within the layer cuncurrently to the computation of the value function, rather than afterwards.
1071
+
We can actually compute the optimal matching within the layer simultaneously with computing the value function, rather than sequentially.
1050
1072
1051
1073
The key idea is that, if at some step of the computation of the values the left branch of the minimum above achieves the minimum, say $V_{ij}= c_{ij} + V_{i+1,j-1},$ then $(i,j)$ are optimally matched on $[i,j]$ and by the theorem above we get that a matching on $[i+1,j-1]$ which achieves $ V_{i+1,j-1}$ belongs to an optimal matching on the whole layer (since it is covered by the arc $(i,j)$ in $[i,j]$).
1052
1074
@@ -1147,7 +1169,7 @@ The following method assembles our components in order to solve the primal prob
1147
1169
1148
1170
First, if matches are perfect pairs, we store the on-diagonal matching and create an off-diagonal instance with the residual marginals.
1149
1171
1150
-
Then, we compute the set of layers of the residual distributions.
1172
+
Then we compute the set of layers of the residual distributions.
1151
1173
1152
1174
Finally, we solve each layer and put together matchings within each layer with the on-diagonal matchings.
In this notebook we study optimal transport problems on the real line with cost $c(x,y)= h(|x-y|)$ for a strictly concave and increasing function $h: \mathbb{R}_+ \rightarrow \mathbb{R}_+.$
1385
+
We study optimal transport problems on the real line with cost $c(x,y)= h(|x-y|)$ for a strictly concave and increasing function $h: \mathbb{R}_+ \rightarrow \mathbb{R}_+.$
1364
1386
1365
1387
The outcome is called *composite sorting*.
1366
1388
@@ -1477,7 +1499,7 @@ example_1.plot_matching(matching_NAM, title = 'NAM',
1477
1499
1478
1500
+++ {"user_expressions": []}
1479
1501
1480
-
Finally, notice that the the**Monge problem** cost function $|x-y|$ equals the limit of composite sorting cost $|x-y|^{1/\zeta}$ as $\zeta \downarrow 1$ and also the limit of $|x-y|^p$ as $p \downarrow 1.$
1502
+
Finally, notice that the **Monge problem** cost function $|x-y|$ equals the limit of the composite sorting cost $|x-y|^{1/\zeta}$ as $\zeta \downarrow 1$ and also the limit of $|x-y|^p$ as $p \downarrow 1.$
1481
1503
1482
1504
Evidently, the Monge problem is solved by both the PAM and the composite sorting assignment that arises for $\zeta \downarrow 1.$
1483
1505
@@ -1573,11 +1595,11 @@ example_2.plot_matching(matching_NAM, title = 'NAM',
1573
1595
1574
1596
+++ {"user_expressions": []}
1575
1597
1576
-
### Example 3 : from the paper
1598
+
### Example 3
1577
1599
1578
1600
+++ {"user_expressions": []}
1579
1601
1580
-
Boerma et al. provide the following example.
1602
+
{cite}`boerma2023composite` provide the following example.
1581
1603
1582
1604
There are four agents per side and three types per side (so the problem is not unitary, as opposed to the examples above).
1583
1605
@@ -1622,7 +1644,7 @@ example_3.plot_matching(matching_NAM, title = 'NAM',
1622
1644
1623
1645
+++ {"user_expressions": []}
1624
1646
1625
-
Let us recall our formulation
1647
+
Let's recall the formulation
1626
1648
1627
1649
$$
1628
1650
\begin{aligned}
@@ -1647,7 +1669,11 @@ where $(\phi , \psi) $ are dual variables, which can be interpreted as shadow co
1647
1669
Since the dual is feasible and bounded, $V_P = V_D$ (*strong duality* prevails).
1648
1670
1649
1671
1650
-
Assume now that $y_{xy} = \alpha_x + \gamma_y - c_{xy}$ is the output generated by matching $x$ and $y.$ It includes the sum of $x$ and $y$ specific amenities/outputs minus the cost $c_{xy}.$ Then, we have can formulate the following problem and its dual
1672
+
Assume now that $y_{xy} = \alpha_x + \gamma_y - c_{xy}$ is the output generated by matching $x$ and $y.$
1673
+
1674
+
It includes the sum of $x$ and $y$ specific amenities/outputs minus the cost $c_{xy}.$
1675
+
1676
+
Then we can formulate the following problem and its dual
1651
1677
1652
1678
$$
1653
1679
\begin{aligned}
@@ -1902,7 +1928,7 @@ As already mentioned, the algorithm starts from the matched pairs $(x_0,y_0)$ wi
1902
1928
1903
1929
1904
1930
1905
-
Then, the algorithm proceeds iterarively by processing any matched pair whose subpairs have already been processed.
1931
+
The algorithm then proceeds sequentially by processing any matched pair whose subpairs have already been processed.
1906
1932
1907
1933
After picking any such matched pair $(x_0,y_0)$, the dual variables already computed for the processed subpairs need to be made "comparable".
@@ -2164,7 +2190,11 @@ The occupation of each individual consists of a Standard Occupational Classifica
2164
2190
2165
2191
There are 497 codes in total.
2166
2192
2167
-
We consider only employed (civilian) individuals with ages between 25 and 60 from 2010 to 2017. To visualize log-wage dispersion, we group the individuals by occupation and compute the mean and standard deviation of the wages within each occupation. Then, we sort the occupations by average log-earnings within each occupation.
2193
+
We consider only employed (civilian) individuals with ages between 25 and 60 from 2010 to 2017.
2194
+
2195
+
To visualize log-wage dispersion, we group the individuals by occupation and compute the mean and standard deviation of the wages within each occupation.
2196
+
2197
+
Then we sort occupations by average log-earnings within each occupation.
2168
2198
2169
2199
The resulting dataset is included in the dataset `acs_data_summary.csv`
From the optimal matching we compute and visualize the hierarchies. Then, we find the dual solution $(\phi,\psi)$ and compute the wages as $w_x = g(x) - \phi_x,$ assuming that the type-specific productivity of type $x$ is $g(x) = x$.
2415
+
From the optimal matching we compute and visualize the hierarchies.
2416
+
2417
+
We then find the dual solution $(\phi,\psi)$ and compute the wages as $w_x = g(x) - \phi_x,$ assuming that the type-specific productivity of type $x$ is $g(x) = x$.
0 commit comments