bivariate_quantiles module¶
This takes in observations of a bivariate random variable y
and computes vector quantiles and vector ranks à la
Chernozhukov-Galichon-Hallin-Henry (Ann. Stats. 2017).
Note
if the math looks strange in the documentation, just reload the page.
The sequence of steps is as follows:
- choose a number of Chebyshev nodes for numerical integration and optimize
the weights:
v = solve_for_v(y, n_nodes) - to obtain the \((u_1,u_2)\) quantiles for \((u_1, u_2)\in [0,1]\), run
qtiles_y = bivariate_quantiles_v(y, v, u1, u2) - to compute the vector ranks for all points in the sample (the barycenters
of the cells in the power diagram):
ranks_y = bivariate_ranks_v(y, v, n_nodes)
Steps 1 and 2 can be combined: qtiles_y = bivariate_quantiles(y, v, u1, u2, n_nodes)
Steps 1 and 3 can be combined: ranks_y = bivariate_ranks(y, n_nodes)
bivariate_quantiles(y, u, n_nodes=32, verbose=False)
¶
Solve for the dual weights then evaluate bivariate quantiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observations, shape |
required |
u
|
ndarray
|
Query points in |
required |
n_nodes
|
int
|
Number of Chebyshev nodes for the quadrature. |
32
|
verbose
|
bool
|
Print optimisation diagnostics when |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Bivariate quantiles at |
Source code in bs_python_utils/bivariate_quantiles.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
bivariate_quantiles_v(y, u, v)
¶
Evaluate vector quantiles for a given set of dual weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observations with shape |
required |
u
|
ndarray
|
Evaluation points in |
required |
v
|
ndarray
|
Dual weights solving the optimal transport problem (length |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of quantile locations with shape |
Source code in bs_python_utils/bivariate_quantiles.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
bivariate_ranks(y, n_nodes=32, verbose=False)
¶
Compute ranks by first solving for the optimal weights v.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observations, shape |
required |
n_nodes
|
int
|
Number of Chebyshev nodes for the quadrature. |
32
|
verbose
|
bool
|
Print optimisation diagnostics when |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Average ranks with shape |
Source code in bs_python_utils/bivariate_quantiles.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
bivariate_ranks_v(y, v, n_nodes=32, presorted=False)
¶
Compute the barycentric ranks of each observation given optimal weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observations with shape |
required |
v
|
ndarray
|
Dual weights returned by |
required |
n_nodes
|
int
|
Number of Chebyshev nodes used in the quadrature. |
32
|
presorted
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of average ranks (shape |
Source code in bs_python_utils/bivariate_quantiles.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
solve_for_v_(y, n_nodes=32, verbose=False)
¶
Solve the dual optimisation to obtain the optimal weights v.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
Observations with shape |
required |
n_nodes
|
int
|
Number of Chebyshev nodes for the quadrature. |
32
|
verbose
|
bool
|
Print optimisation diagnostics when |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of length |
Source code in bs_python_utils/bivariate_quantiles.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |