Skip to main content

Implements transfer learning methods for low-rank matrix estimation.

Project description

learner_py

The learner_py package implements transfer learning methods for low-rank matrix estimation. These methods leverage similarity in the latent row and column spaces between the source and target populations to improve estimation in the target population. The methods include the LatEnt spAce-based tRaNsfer lEaRning (LEARNER) method and the direct projection LEARNER (D-LEARNER) method described by McGrath et al. (2024).

Installation

You can install the released version of learner from PyPi with:

pip install learner_py

LEARNER Method

We can apply the LEARNER method via the learner function.

This method allows for flexible patterns of heterogeneity across the source and target populations. It consequently requires specifying the tuning parameters lambda_1 and lambda_2 which control the degree of transfer learning between the populations. These values can be selected based on cross-validation via the cv.learner function. For example, we can specify candidate values of 1, 10, and 100 for lambda_1 and lambda_2 and select the optimal values based on cross-validation as follows:

res_cv = pylearner.cv_learner(
            Y_source=dat_highsim["Y_source"],
            Y_target=dat_highsim["Y_target"],
            lambda1_all=[1, 10, 100],
            lambda2_all=[1, 10, 100],
            step_size=0.003
        )

print(res_cv['lambda_1_min']) #100
print(res_cv["lambda_2_min"]) #1

Example

We illustrate an example of how learner can be used. We first load the package.

import learner_py as pylearner

In this illustration, we will use one of the toy data sets in the package (dat_highsim) that has a high degree of similarity between the latent spaces of the source and target populations. The object dat_highsim is a list which contains the observed source population data matrix Y_source and the target population data matrix Y_target. Since the data was simulated, the true values of the matrices are included in dat_highsim as Theta_source and Theta_target.

LEARNER Method

We can apply the LEARNER method via the learner function.

This method allows for flexible patterns of heterogeneity across the source and target populations. It consequently requires specifying the tuning parameters lambda_1 and lambda_2 which control the degree of transfer learning between the populations. These values can be selected based on cross-validation via the cv.learner function. For example, we can specify candidate values of 1, 10, and 100 for lambda_1 and lambda_2 and select the optimal values based on cross-validation as follows:

res_cv = pylearner.cv_learner(
            Y_source=dat_highsim["Y_source"],
            Y_target=dat_highsim["Y_target"],
            lambda1_all=[1, 10, 100],
            lambda2_all=[1, 10, 100],
            step_size=0.003
        )

print(res_cv['lambda_1_min']) #100
print(res_cv["lambda_2_min"]) #1

Next, we apply the learner function with these values of lambda1 and lambda2:

res_learner <- learner(Y_source = dat_highsim$Y_source, 
                       Y_target = dat_highsim$Y_target,
                       lambda1 = 100, lambda2 = 1, 
                       step_size = 0.003)

The LEARNER estimate is given by the learner_estimate component in the output of the learner function, e.g.,

print(res_learner['learner_estimate'][0:4, 0:4])
[[ 0.14688887 -1.63414688  1.18573076  0.00809396]
 [ 0.10877659 -0.2439277  -1.0061737  -0.05811972]
 [-0.62130277  1.04206753 -0.69077759  0.90570933]
 [ 1.58115883 -3.0000149   0.39780804 -2.12428512]]

D-LEARNER Method

We can apply the D-LEARNER method via the dlearner function. This method makes stronger assumptions on the heterogeneity across the source and target populations. It consequently does not rely on choosing tuning parameters. The dlearner function can be applied as follows:

res_dlearner = pylearner.dlearner(Y_source=dat_highsim["Y_source"],
                                  Y_target=dat_highsim["Y_target"])

print(res_dlearner['dlearner_estimate'][0:4, 0:4])

[[ 0.0959171  -1.72143637  1.15500149  0.00547827]
 [ 0.10771367 -0.3224348  -1.03557177 -0.10819564]
 [-0.72372751  0.86634922 -0.43528206  1.10580219]
 [ 1.63476957 -2.91985925  0.04876288 -2.35750409]]

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

learner_py-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

learner_py-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

learner_py-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

learner_py-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

learner_py-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (7.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

Details for the file learner_py-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for learner_py-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f6d78c5159f7ec3a1a948d7a7e8b1e6d0bbd0efd14e8c7ee47554da5b82e9f5c
MD5 b176d6130fb5efbb6594141660c56fe8
BLAKE2b-256 fa0ee3af13b2b98f45727ba27776e6f90978d16839dfea3b95103210051dd3b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for learner_py-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on ryan-odea/pylearner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file learner_py-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for learner_py-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f499ff973a33327825a2481d00b23ace3e8b0f1be631bb6ce143b3b26ff2522
MD5 8df1c8e3b09a6f6dbef69ab8e02c2ea0
BLAKE2b-256 0db41b5f5e685f33834d0b53898225670bcb89843822add0c3ca5f79dec2f2bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for learner_py-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on ryan-odea/pylearner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file learner_py-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for learner_py-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c17f86626f170f4c6aee709944bbe7692ff7634a9906f85b6e79a6cfc9650d5a
MD5 754caf780f8c212d929e133f0ff2aa8f
BLAKE2b-256 a2272cca2a1f8058965bfe13b37a4d0bbcd22f0914b8b7602d1bb0cb60d79004

See more details on using hashes here.

Provenance

The following attestation bundles were made for learner_py-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on ryan-odea/pylearner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file learner_py-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for learner_py-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 76d6dad18a96846864dc403d374c1291f8a27b6e8af45922dbb56b9dfdc623de
MD5 ab9ae3e09e40a4713826afa355bf1f4a
BLAKE2b-256 d973e61aadd25928b2e9090ee3f96b9c51254bc1189bc5f6ca96e724201728cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for learner_py-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on ryan-odea/pylearner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file learner_py-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for learner_py-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1dd7302d2b3149b08474c1bf04e5a807e55bdc0e34f12a21f055a31bb47eacba
MD5 016f3c8ba510453808dcdacdc73ac447
BLAKE2b-256 d65d8ed3ce85acaf28e66ed0879092bbbe1d74a868206451f4800dae889a47b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for learner_py-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on ryan-odea/pylearner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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