matching_utils
module¶
matching-related utilities
Matching
dataclass
¶
stores the numbers of couples and singles of every type;
muxy
is an (X,Y)-matrix
n
is an X-vector
m
is an Y-vector
no_singles
: if True
, this is a model w/o singles
mux0
and mu0y
are generated as the corresponding numbers of singles
as well as the total number of households n_households
and the total number of individuals n_individuals
Source code in cupid_matching/matching_utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
VarianceMatching
dataclass
¶
initialized with the six matrix components of the variance of a `Matching; computes five more components.
var_xyzt
is the (XY, XY) var-cov matrix of muxy
var_xyz0
is the (XY, X) covariance matrix of muxy
and mux0
var_xy0t
is the (XY, Y) covariance matrix of muxy
and mu0y
var_x0z0
is the (X, X) var-cov matrix of mux0
var_x00t
is the (X, Y) covariance matrix of mux0
and mu0y
var_0y0t
is the (Y, Y) var-cov matrix of mu0y
var_xyn
is the (XY, X) covariance matrix of muxy
and nx
var_xym
is the (XY, Y) covariance matrix of muxy
and my
var_nn
is the (X, X) var-cov matrix of nx
var_nm
is the (X, Y) covariance matrix of nx
and my
var_mm
is the (Y, Y) var-cov matrix of my
var_allmus
is the (XY+X+Y, XY+X+Y) var-cov matrix of (muxy, mux0, mu0y)
var_munm
is the (XY+X+Y, XY+X+Y) var-cov matrix of (muxy, n, m)
no_singles
: if True
, this is a model w/o singles;
then var_allmus
and var_munm
are (XY, XY)
and (XY, XY+X+Y)
matrices
Source code in cupid_matching/matching_utils.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
make_var_allmus()
¶
create the variance-covariance of (muxy, mux0, mu0y)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Any
|
the |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
an |
Source code in cupid_matching/matching_utils.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
make_var_munm()
¶
create the variance-covariance of (muxy, n, m)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Any
|
this |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
an |
Source code in cupid_matching/matching_utils.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
unpack()
¶
return a tuple of all members of this VarianceMatching
Source code in cupid_matching/matching_utils.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
compute_margins(muxy, mux0, mu0y)
¶
Computes the margins from the matches and the singles.
Source code in cupid_matching/matching_utils.py
20 21 22 23 24 |
|
get_evals(fun, mus, additional_parameters=None)
¶
evaluates fun(mus, additional_parameters)
Source code in cupid_matching/matching_utils.py
108 109 110 111 112 113 |
|
get_margins(mus)
¶
computes the numbers of each type from the matching patterns
Source code in cupid_matching/matching_utils.py
116 117 118 119 |
|
get_singles(muxy, n, m)
¶
Computes the numbers of singles from the matches and the margins.
Source code in cupid_matching/matching_utils.py
13 14 15 16 17 |
|
simulate_sample_from_mus(mus, n_households, no_singles=False, seed=None)
¶
Draw a sample of n_households
from the matching patterns in mus
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mus |
Matching
|
the matching patterns |
required |
n_households |
int
|
the number of households requested |
required |
no_singles |
bool
|
if |
False
|
seed |
int | None
|
an integer seed for the random number generator |
None
|
Returns:
Type | Description |
---|---|
Matching
|
the sample matching patterns |
Source code in cupid_matching/matching_utils.py
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 |
|
var_divide(varmus, d)
¶
divide all members by the same number
Source code in cupid_matching/matching_utils.py
393 394 395 396 397 398 399 400 401 402 403 |
|
variance_muhat(muhat)
¶
Computes the unweighted variance-covariance matrix of the observed matching patterns
Parameters:
Name | Type | Description | Default |
---|---|---|---|
muhat |
Matching
|
a |
required |
Returns:
Type | Description |
---|---|
VarianceMatching
|
the corresponding |
Source code in cupid_matching/matching_utils.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|