Skip to content

Commit 7a2f747

Browse files
committed
update match_transport for numpy2
1 parent 5bed173 commit 7a2f747

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
_build/
2-
.DS_Store
2+
.DS_Store
3+
.ipynb_checkpoints/
4+
.virtual_documents/

lectures/match_transport.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.16.4
7+
jupytext_version: 1.17.2
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -13,13 +13,11 @@ kernelspec:
1313

1414
# Composite Sorting
1515

16-
+++
17-
1816
## Overview
1917

2018
Optimal transport theory studies how a marginal probabilty measure can be related to another marginal probability measure in an ideal way.
2119

22-
* here ideal means to minimize some cost criterion.
20+
* here ideal means to minimize some cost criterion.
2321

2422
The output of such a theory is a **coupling** of the two probability measures, i.e., a joint probabilty
2523
measure having those two marginal probability measures.
@@ -575,9 +573,9 @@ def plot_H_z(self, figsize=(15, 8), range_x_axis=None, scatter=True):
575573
plt.axhline(0, color='black', linewidth=1)
576574
577575
# determine the step points for horizontal lines
578-
step = np.concatenate(([self.support_z.min() - .05 * self.support_z.ptp()],
576+
step = np.concatenate(([self.support_z.min() - .05 * np.ptp(self.support_z)],
579577
self.support_z,
580-
[self.support_z.max() + .05 * self.support_z.ptp()]))
578+
[self.support_z.max() + .05 * np.ptp(self.support_z)]))
581579
height = np.concatenate(([0], H_z, [0]))
582580
583581
# plot the horizontal lines of the step function
@@ -699,9 +697,9 @@ def plot_layers(self, figsize=(15, 8)):
699697
plt.figure(figsize=figsize)
700698
701699
# Plot H(z)
702-
step = np.concatenate(([self.support_z.min() - .05 * self.support_z.ptp()],
700+
step = np.concatenate(([self.support_z.min() - .05 * np.ptp(self.support_z)],
703701
self.support_z,
704-
[self.support_z.max() + .05 * self.support_z.ptp()]))
702+
[self.support_z.max() + .05 * np.ptp(self.support_z)]))
705703
height = np.concatenate((H_z, [0]))
706704
plt.step(step, height, where='post', color='black', label='CDF', zorder=1)
707705
@@ -984,7 +982,7 @@ def plot_layer_matching(self, layer, matching_layer):
984982
ax.spines['top'].set_color('none')
985983
ax.spines['right'].set_color('none')
986984
ax.yaxis.set_ticks([])
987-
ax.set_ylim(bottom= -self.support_z.ptp() / 100)
985+
ax.set_ylim(bottom= -np.ptp(self.support_z) / 100)
988986
989987
plt.show()
990988
@@ -1319,29 +1317,29 @@ def plot_matching(self, matching_off_diag, title, figsize=(15, 15),
13191317
ax.spines['top'].set_color('none')
13201318
ax.spines['right'].set_color('none')
13211319
ax.yaxis.set_ticks([])
1322-
ax.set_ylim(- self.X_types.ptp() / 10,
1323-
(max_height / 2) + self.X_types.ptp()*.01)
1320+
ax.set_ylim(- np.ptp(self.X_types) / 10,
1321+
(max_height / 2) + np.ptp(self.X_types)*.01)
13241322
13251323
# Plot H_z on the main axis if enabled
13261324
if plot_H_z:
13271325
H_z = np.cumsum(self.q_z)
13281326
13291327
step = np.concatenate(([self.support_z.min()
1330-
- .02 * self.support_z.ptp()],
1328+
- .02 * np.ptp(self.support_z)],
13311329
self.support_z,
13321330
[self.support_z.max()
1333-
+ .02 * self.support_z.ptp()]))
1331+
+ .02 * np.ptp(self.support_z)]))
13341332
1335-
H_z = H_z/H_z.ptp() * self.support_z.ptp() /2
1333+
H_z = H_z/np.ptp(H_z) * np.ptp(self.support_z) /2
13361334
height = np.concatenate(([0], H_z, [0]))
13371335
13381336
# Plot the compressed H_z on the same main x-axis
13391337
ax.step(step, height, color='green', lw=2,
13401338
label='$H_z$', where='post')
13411339
13421340
# Set the y-limit to keep H_z and maximum circle size in the plot
1343-
ax.set_ylim(np.min(H_z) - H_z.ptp() *.01,
1344-
np.maximum(np.max(H_z), max_height / 2) + H_z.ptp() *.01)
1341+
ax.set_ylim(np.min(H_z) - np.ptp(H_z) *.01,
1342+
np.maximum(np.max(H_z), max_height / 2) + np.ptp(H_z) *.01)
13451343
13461344
# Add label and legend for H_z
13471345
ax.legend(loc="upper right")
@@ -1614,7 +1612,7 @@ example_2.plot_matching(matching_NAM, title = 'NAM',
16141612
16151613
+++ {"user_expressions": []}
16161614
1617-
### Example 3
1615+
### Example 3
16181616
16191617
+++ {"user_expressions": []}
16201618
@@ -1907,7 +1905,7 @@ def plot_hierarchies(self, subpairs, scatter=True, range_x_axis=None):
19071905
19081906
if range_x_axis is not None:
19091907
ax.set_xlim(range_x_axis)
1910-
ax.set_ylim(- self.X_types.ptp() / 10,
1908+
ax.set_ylim(- np.ptp(self.X_types) / 10,
19111909
(range_x_axis[1] - range_x_axis[0]) / 2 )
19121910
19131911
# Title and layout settings for the main plot
@@ -2230,12 +2228,11 @@ We plot the wage standard deviation for the sorted occupations.
22302228
---
22312229
mystnb:
22322230
figure:
2233-
caption: "Average wage for each Standard Occupational Classification (SOC) code.
2234-
The codes are sorted by average wage on the horizontal axis. In red,
2235-
a polynomial of degree 5 is fitted to the data. The size of the marker is
2236-
proportional to the number of individuals in the occupation."
2231+
caption: Average wage for each Standard Occupational Classification (SOC) code.
2232+
The codes are sorted by average wage on the horizontal axis. In red, a polynomial
2233+
of degree 5 is fitted to the data. The size of the marker is proportional to
2234+
the number of individuals in the occupation.
22372235
---
2238-
22392236
# Scatter plot wage dispersion for each occupation
22402237
plt.figure(figsize=(10, 6))
22412238
@@ -2273,11 +2270,10 @@ We also plot the average wages for each occupation (SOC code). Again, occupation
22732270
---
22742271
mystnb:
22752272
figure:
2276-
caption: "Average wage for each Standard Occupational Classification (SOC) code.
2277-
The codes are sorted by average wage on the horizontal axis. In red,
2278-
a polynomial of degree 5 is fitted to the data."
2273+
caption: Average wage for each Standard Occupational Classification (SOC) code.
2274+
The codes are sorted by average wage on the horizontal axis. In red, a polynomial
2275+
of degree 5 is fitted to the data.
22792276
---
2280-
22812277
# Scatter plot average wage for each occupation
22822278
plt.figure(figsize=(10, 6))
22832279

0 commit comments

Comments
 (0)