From a0c0cf0aacac20266a91f0bf22785ae3991ed863 Mon Sep 17 00:00:00 2001 From: hermosillajelmy Date: Wed, 29 Jan 2025 16:57:18 -0300 Subject: [PATCH 1/3] add cutoff for conditions with different RCA in relative relatedness --- economic_complexity/product_space.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/economic_complexity/product_space.py b/economic_complexity/product_space.py index d1b6b5b..520b93d 100644 --- a/economic_complexity/product_space.py +++ b/economic_complexity/product_space.py @@ -405,13 +405,16 @@ def relative_relatedness( opp = rcas.copy() - if cutoff == 0: - opp = 1 - else: - opp[opp >= cutoff] = pd.NA - opp[opp < cutoff] = 1 - - wcp = relatedness(rcas, cutoff=cutoff, proximities=proximities) + if cutoff == 0: #all activities + opp[:] = 1 + elif cutoff > 0: #cuttoff = 1 activities with comparative advantages + opp[opp >= cutoff] = 1 + opp[opp < cutoff] = pd.NA + else: #<0 cutoff = -1 activities without comparative advantages, + opp[opp >= cutoff * -1] = pd.NA + opp[opp < cutoff * -1] = 1 + + wcp = relatedness(rcas, proximities=proximities) wcp_opp = opp * wcp wcp_mean = wcp_opp.mean(axis=1) From 0d339c692049d1f45bd73cd056bd3bc3605af202 Mon Sep 17 00:00:00 2001 From: hermosillajelmy Date: Thu, 30 Jan 2025 15:28:54 -0300 Subject: [PATCH 2/3] clear cutoff conditions --- economic_complexity/product_space.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/economic_complexity/product_space.py b/economic_complexity/product_space.py index 520b93d..a1a7a5a 100644 --- a/economic_complexity/product_space.py +++ b/economic_complexity/product_space.py @@ -405,14 +405,8 @@ def relative_relatedness( opp = rcas.copy() - if cutoff == 0: #all activities - opp[:] = 1 - elif cutoff > 0: #cuttoff = 1 activities with comparative advantages - opp[opp >= cutoff] = 1 - opp[opp < cutoff] = pd.NA - else: #<0 cutoff = -1 activities without comparative advantages, - opp[opp >= cutoff * -1] = pd.NA - opp[opp < cutoff * -1] = 1 + opp[opp >= cutoff] = pd.NA + opp[opp < cutoff] = 1 wcp = relatedness(rcas, proximities=proximities) From 312158e42fcbb82322c6f1223b0893407b8b24a6 Mon Sep 17 00:00:00 2001 From: hermosillajelmy Date: Thu, 30 Jan 2025 15:30:16 -0300 Subject: [PATCH 3/3] minor change --- economic_complexity/product_space.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/economic_complexity/product_space.py b/economic_complexity/product_space.py index a1a7a5a..42cb9a9 100644 --- a/economic_complexity/product_space.py +++ b/economic_complexity/product_space.py @@ -408,7 +408,7 @@ def relative_relatedness( opp[opp >= cutoff] = pd.NA opp[opp < cutoff] = 1 - wcp = relatedness(rcas, proximities=proximities) + wcp = relatedness(rcas, cutoff=cutoff, proximities=proximities) wcp_opp = opp * wcp wcp_mean = wcp_opp.mean(axis=1)