Skip to main content

A package to solve, simulate and estimate separable matching models

Project description

cupid_matching

image image image image

A Python package to solve, simulate and estimate separable matching models

Installation

pip install -U cupid_matching

Accessing the code

For instance:

from cupid_matching.min_distance import estimate_semilinear_mde

An example

We create a Choo-Siow market; we solve for the stable matching in an infinite ppulation using IPFP; we simulate a sample drawn from the stable matching and we estimate the coefficients of the basis functions using both minimum distance and Poisson GLM estimators.

import numpy as np
from cupid_matching.model_classes import ChooSiowPrimitives
from cupid_matching.choo_siow import entropy_choo_siow
from cupid_matching.min_distance import estimate_semilinear_mde
from cupid_matching.poisson_glm import choo_siow_poisson_glm

X, Y, K = 10, 20, 2
# we simulate a Choo and Siow population
#  with 10 types of men and 20 types of women
#  with equal numbers of men and women of each type
#  and two random basis functions
lambda_true = np.random.randn(K)
phi_bases = np.random.randn(X, Y, K)
n = np.ones(X)
m = np.ones(Y)
Phi = phi_bases @ lambda_true
choo_siow_instance = ChooSiowPrimitives(Phi, n, m)
matching_popu = choo_siow_instance.ipfp_solve()
muxy_popu, mux0_popu, mu0y_popu, n_popu, m_popu \
    = matching_popu.unpack()

# we simulate the market on a finite population
n_households = int(1e6)
mus_sim = choo_siow_instance.simulate(n_households)
choo_siow_instance.describe()

# We estimate the parameters using minimum distance
mde_results = estimate_semilinear_mde(
            mus_sim, phi_bases, entropy_choo_siow, 
            more_params=None
        )

# we print and check the results
mde_discrepancy = mde_results.print_results(
            true_coeffs=lambda_true, n_alpha=0
        )

# we also estimate using Poisson GLM 
poisson_results = choo_siow_poisson_glm(mus_sim, phi_bases)

muxy_sim, mux0_sim, mu0y_sim, n_sim, m_sim \
    = mus_sim.unpack()

poisson_discrepancy = poisson_results.print_results(
        lambda_true, 
        u_true=-np.log(mux0_sim/ n_sim), 
        v_true=-np.log(mu0y_sim / m_sim)
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cupid_matching-0.2.2.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cupid_matching-0.2.2-py2.py3-none-any.whl (40.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cupid_matching-0.2.2.tar.gz.

File metadata

  • Download URL: cupid_matching-0.2.2.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for cupid_matching-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9614268a13331e8435019301e387874f9e774de47c796200ddd9a5e7dd8bb5b3
MD5 487b2d87f8627aa2b31d1ddc1628d260
BLAKE2b-256 52c4ee7c5f3b0bce6f492a60b35052fa9c96199c61713e5c20fdb1907bfdd0d1

See more details on using hashes here.

File details

Details for the file cupid_matching-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: cupid_matching-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for cupid_matching-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0c02a9d125fcb5721e303cac8245b7cfb630759c5a000f2e6a1d62b1c7b51ba3
MD5 4f52ccd35cba23fe0aee58d992ac9c93
BLAKE2b-256 38d11c2d7982268c6a53d10e2828e6e30aa8b1dadd0c351b18e0bc66a2681c10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page