econcomplex 1.0.1__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. econcomplex-1.2.0/CHANGELOG.md +191 -0
  2. {econcomplex-1.0.1/econcomplex.egg-info → econcomplex-1.2.0}/PKG-INFO +60 -19
  3. {econcomplex-1.0.1 → econcomplex-1.2.0}/README.md +54 -16
  4. {econcomplex-1.0.1 → econcomplex-1.2.0}/README.pt-BR.md +54 -16
  5. {econcomplex-1.0.1 → econcomplex-1.2.0}/docs/api_reference_en.tex +55 -6
  6. {econcomplex-1.0.1 → econcomplex-1.2.0}/docs/api_reference_pt.tex +55 -6
  7. econcomplex-1.2.0/docs/econcomplex_documentation_en.pdf +0 -0
  8. {econcomplex-1.0.1 → econcomplex-1.2.0}/docs/econcomplex_documentation_en.tex +594 -22
  9. econcomplex-1.2.0/docs/econcomplex_documentation_pt.pdf +0 -0
  10. {econcomplex-1.0.1 → econcomplex-1.2.0}/docs/econcomplex_documentation_pt.tex +605 -20
  11. {econcomplex-1.0.1 → econcomplex-1.2.0}/docs/generate_api_reference.py +31 -1
  12. econcomplex-1.2.0/docs/generate_tutorial.py +710 -0
  13. econcomplex-1.2.0/docs/tutorial_en.tex +476 -0
  14. econcomplex-1.2.0/docs/tutorial_pt.tex +481 -0
  15. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/__init__.py +62 -11
  16. econcomplex-1.2.0/econcomplex/complexity/diagnostics.py +129 -0
  17. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/eci_pci.py +23 -3
  18. econcomplex-1.2.0/econcomplex/complexity/genepy.py +102 -0
  19. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/subnational.py +28 -11
  20. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/core/diversity.py +9 -0
  21. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/core/preprocess.py +13 -1
  22. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/core/rca.py +11 -5
  23. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/core/utils.py +98 -3
  24. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/dynamics/entry_exit.py +4 -0
  25. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/inequality/concentration.py +3 -2
  26. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/inequality/gini.py +3 -2
  27. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/optimization/diffusion.py +6 -4
  28. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/optimization/portfolio.py +61 -25
  29. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/optimization/steppingstone.py +3 -2
  30. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/outlook/coi_cog.py +38 -27
  31. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/patents/recombination.py +5 -2
  32. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/pipeline.py +8 -0
  33. econcomplex-1.2.0/econcomplex/policy/__init__.py +6 -0
  34. econcomplex-1.2.0/econcomplex/policy/lists.py +364 -0
  35. econcomplex-1.2.0/econcomplex/prediction/__init__.py +7 -0
  36. econcomplex-1.2.0/econcomplex/prediction/entry.py +388 -0
  37. econcomplex-1.2.0/econcomplex/prediction/model.py +424 -0
  38. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/productivity/prody.py +7 -14
  39. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/relatedness/__init__.py +24 -1
  40. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/relatedness/cross_space.py +11 -1
  41. econcomplex-1.2.0/econcomplex/relatedness/density.py +401 -0
  42. econcomplex-1.2.0/econcomplex/relatedness/flows.py +109 -0
  43. econcomplex-1.2.0/econcomplex/relatedness/implied.py +123 -0
  44. econcomplex-1.2.0/econcomplex/relatedness/input_output.py +94 -0
  45. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/relatedness/proximity.py +49 -0
  46. econcomplex-1.2.0/econcomplex/relatedness/spatial.py +84 -0
  47. econcomplex-1.2.0/econcomplex/strategy/__init__.py +7 -0
  48. econcomplex-1.2.0/econcomplex/strategy/selection.py +341 -0
  49. {econcomplex-1.0.1 → econcomplex-1.2.0/econcomplex.egg-info}/PKG-INFO +60 -19
  50. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex.egg-info/SOURCES.txt +22 -1
  51. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex.egg-info/requires.txt +3 -0
  52. econcomplex-1.2.0/examples/diversification_strategy.py +169 -0
  53. econcomplex-1.2.0/examples/tutorial.py +145 -0
  54. {econcomplex-1.0.1 → econcomplex-1.2.0}/pyproject.toml +9 -4
  55. econcomplex-1.2.0/tests/test_quality.py +337 -0
  56. econcomplex-1.2.0/tests/test_stage2.py +345 -0
  57. econcomplex-1.2.0/tests/test_stage2b.py +345 -0
  58. econcomplex-1.0.1/CHANGELOG.md +0 -50
  59. econcomplex-1.0.1/docs/econcomplex_documentation_en.pdf +0 -0
  60. econcomplex-1.0.1/docs/econcomplex_documentation_pt.pdf +0 -0
  61. econcomplex-1.0.1/econcomplex/relatedness/density.py +0 -232
  62. {econcomplex-1.0.1 → econcomplex-1.2.0}/LICENSE +0 -0
  63. {econcomplex-1.0.1 → econcomplex-1.2.0}/MANIFEST.in +0 -0
  64. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/__init__.py +0 -0
  65. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/eigenvector.py +0 -0
  66. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/fitness.py +0 -0
  67. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/complexity/reflections.py +0 -0
  68. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/core/__init__.py +0 -0
  69. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/dynamics/__init__.py +0 -0
  70. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/dynamics/growth.py +0 -0
  71. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/inequality/__init__.py +0 -0
  72. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/optimization/__init__.py +0 -0
  73. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/optimization/growth_target.py +0 -0
  74. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/outlook/__init__.py +0 -0
  75. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/patents/__init__.py +0 -0
  76. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/productivity/__init__.py +0 -0
  77. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/relatedness/cooccurrence.py +0 -0
  78. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/specialization/__init__.py +0 -0
  79. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/specialization/location_quotient.py +0 -0
  80. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex/specialization/similarity.py +0 -0
  81. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex.egg-info/dependency_links.txt +0 -0
  82. {econcomplex-1.0.1 → econcomplex-1.2.0}/econcomplex.egg-info/top_level.txt +0 -0
  83. {econcomplex-1.0.1 → econcomplex-1.2.0}/examples/basic_usage.py +0 -0
  84. {econcomplex-1.0.1 → econcomplex-1.2.0}/examples/eci_optimization.py +0 -0
  85. {econcomplex-1.0.1 → econcomplex-1.2.0}/setup.cfg +0 -0
  86. {econcomplex-1.0.1 → econcomplex-1.2.0}/setup.py +0 -0
  87. {econcomplex-1.0.1 → econcomplex-1.2.0}/tests/test_core.py +0 -0
  88. {econcomplex-1.0.1 → econcomplex-1.2.0}/tests/test_diffusion.py +0 -0
  89. {econcomplex-1.0.1 → econcomplex-1.2.0}/tests/test_optimization.py +0 -0
@@ -0,0 +1,191 @@
1
+ # Changelog
2
+
3
+ ## [1.2.0] — unreleased
4
+
5
+ General-purpose tools for the steps that come after the indicators:
6
+ explaining opportunities, ranking them, reading them through lists of
7
+ activities, and testing whether a score predicts entry. 112 public
8
+ functions (22 new). scikit-learn becomes an optional dependency
9
+ (`pip install "econcomplex[ml]"`), needed only by the prediction models.
10
+
11
+ ### Fixed
12
+ - **`complexity_outlook_gain` (`cog`) used the wrong normalization.** The
13
+ gain from entering activity c was divided by the total proximity of c,
14
+ instead of dividing each term by the total proximity of the activity c'
15
+ whose density rises. The two only coincide when every activity has the
16
+ same total proximity. The function now equals the actual change in the
17
+ Complexity Outlook Index when the activity is added (tested), and matches
18
+ the Growth Lab's `py-ecomplexity`. **Values change**: on the sample data
19
+ the correlation with the previous output is about 0.97, so rankings of
20
+ activities by COG can move. `compute_complexity` returns the corrected
21
+ `cog` column; `coi` is unchanged.
22
+
23
+ ### Added
24
+ - **Complexity**
25
+ - `genepy`, also `eci_pci(mat, method="genepy")`: the GENEPY index of
26
+ Sciarra et al. (2020), following the authors' released code.
27
+ - `eci_diagnostics`: spectral gap, relation with diversity and stability
28
+ of the ECI ranking under resampling of activities (Mealy, Farmer &
29
+ Teytelboym 2019). Flags matrices where the sign convention of the ECI
30
+ is fragile.
31
+ - **Relatedness**
32
+ - `implied_rca`: implied comparative advantage of Hausmann, Stock &
33
+ Yıldırım (2022) — RCA predicted from the k most similar activities or
34
+ regions.
35
+ - `io_relatedness`: proximity from an input-output table (Essletzbichler
36
+ 2015; Fan & Lang 2000).
37
+ - `skill_relatedness`: relatedness from a matrix of flows between
38
+ activities (job switches), observed over expected, mapped to [-1, 1)
39
+ (Neffke, Otto & Weyh 2017).
40
+ - `spatial_density`: share of a region's neighbours specialized in each
41
+ activity, with user-supplied spatial weights (Bahar, Hausmann & Hidalgo
42
+ 2014; Boschma, Martín & Minondo 2017).
43
+ - `density_contributions`: which of the region's activities make another
44
+ activity feasible; the contributions add up to the density.
45
+ - `decomposed_density`: density net of region and activity fixed effects
46
+ (handles NaN cells, e.g. only the activities a region lacks).
47
+ - **Strategy** (new `strategy` module)
48
+ - `desirability_index`: weighted combination of standardized indicators
49
+ per activity, with explicit (possibly negative) weights.
50
+ - `weight_sensitivity`: how far each activity's rank moves when the
51
+ weights are redrawn (Dirichlet).
52
+ - `strategy_quadrants`: short jump / long bet / low value / avoid, with
53
+ cuts computed inside each region.
54
+ - `opportunity_alignment`: correlation, per region, between the
55
+ feasibility and the desirability of its options.
56
+ - **Policy lists** (new `policy` module) — for any set of activities (green
57
+ lists, missions, value chains)
58
+ - `list_complexity_potential`: presence and potential of each region in
59
+ each list; generalizes the Green Complexity Index and Potential of
60
+ Mealy & Teytelboym (2022), reproduced with `average="missing"`.
61
+ - `list_density`: part of the relatedness density that rests on the
62
+ activities of a list (additive).
63
+ - `missing_links`: links of a chain that are present, feasible or missing
64
+ in each region.
65
+ - `transition_risk`: exposure to a list of activities at risk, Brown
66
+ Lock-in Index and Transition Outlook (Andres et al. 2023).
67
+ - **Entry prediction** (new `prediction` module)
68
+ - `entry_targets`: binary entry target and risk set between two periods
69
+ (RCA < 0.5 → RCA ≥ 1 by default, optional minimum size).
70
+ - `validate_entry`: scores any predictor of entry — AUC, within-region
71
+ AUC, average precision, precision/recall@k, Brier — with bootstrap
72
+ intervals by region and differences to a baseline. NumPy/SciPy only.
73
+ - `build_features`, `predict_entry`, `explain_entry` (need scikit-learn):
74
+ table of features per cell, out-of-sample probability of entry by
75
+ cross-validation over regions (gradient boosting, random forest, logit
76
+ or any classifier; one model on layers or one model per activity on the
77
+ RCA vector), and permutation importance on held-out regions.
78
+ - `potential_employment`: expected size of entries, probability × arrival
79
+ size (location quotient of 1, or quantiles of past entrants).
80
+ - `examples/diversification_strategy.py`: the new tools end to end.
81
+
82
+ ### Changed
83
+ - Documentation: a step-by-step tutorial opens the reference part of both
84
+ PDFs — nine steps from the raw table to a shortlist of targets and its
85
+ out-of-sample test, each with code, the output it prints and how to read
86
+ it. It is generated by `docs/generate_tutorial.py`, which runs the code,
87
+ so the numbers in the PDF are the ones the library produces; the same
88
+ code is in `examples/tutorial.py`.
89
+ - Documentation: new sections in the English and Portuguese PDFs (density
90
+ decompositions, skill relatedness, spatial density, strategy, policy
91
+ lists, entry validation), COG formula, interpretation table, references.
92
+ - `econcomplex.relatedness.__all__` lists every function of the subpackage.
93
+ - CI installs the `ml` extra so that the prediction tests run.
94
+
95
+ ## [1.1.0] — 2026-11-24
96
+
97
+ ### Fixed
98
+ - **Label alignment.** Auxiliary inputs given as labelled pandas objects are
99
+ now matched to the matrix by label instead of by position. Before, a
100
+ `Series` or `DataFrame` with the same labels in a different order silently
101
+ produced wrong results. Affects `prody`, `expy`, `pgi`, `peii`, `rpop`,
102
+ `hoover_index`, `hoover_gini`, `coi`, `cog`, every density function (`phi`),
103
+ `cross_relatedness` (`x_phi`), `subnational_eci`, `modular_complexity`
104
+ (`eor`) and the strategic-diffusion functions (`active`). Lists, arrays and
105
+ Series with a default integer index are still taken positionally; a missing
106
+ label raises a `ValueError` naming it.
107
+ - **Input validation.** Matrices with NaN/infinite or negative cells now raise
108
+ a clear `ValueError` at the entry point. NaN used to surface as a misleading
109
+ "trimming to the (1, 1)-core" error and negative values were accepted.
110
+ - **`eci_optimization` no longer stalls.** The exact solver could run
111
+ indefinitely on locations with many near-equivalent candidates. It is now
112
+ capped by `time_limit` (default 5 s per location); when the cap is hit the
113
+ best feasible portfolio found is returned, never worse than the greedy one.
114
+ - `subnational_eci` returns NaN (it returned 0) for regions with no
115
+ specialization, and accepts an external PCI in any order, with extra
116
+ activities, or missing some of the matrix's activities.
117
+ - Citations: Catalán, Navarrete & Figueroa (2022) for the cross-space, and
118
+ Pinheiro et al. (2022) for relative relatedness.
119
+
120
+ ### Added
121
+ - `product_proximity` and `location_proximity`: return the proximity matrix
122
+ directly instead of the `{"product": ..., "location": ...}` dictionary.
123
+ - `percent` option in `relatedness_density` and its internal/external
124
+ variants: `percent=False` returns shares (0-1), the scale of `distance`
125
+ and `cross_relatedness`. The default (0-100) is unchanged.
126
+ - `exits`, the preferred name for `exit` (which shadows the Python builtin).
127
+ - Runnable `Examples` in the docstrings of the main entry points, executed
128
+ by the test suite (`pytest --doctest-modules`).
129
+ - Continuous integration (GitHub Actions): Python 3.10 to 3.14 and NumPy 1.x.
130
+ - `eci_optimization` output has an `optimal` column (True when the solver
131
+ proved optimality) and warns once when locations reach the time limit.
132
+ - Known-answer tests for the 25 public functions that had no direct test,
133
+ plus a regression test that reproduces the 1.0.1 results to 1e-7.
134
+
135
+ ### Changed
136
+ - Minimum Python is now 3.10. Python 3.9 reached end of life in October 2025
137
+ and is no longer available on the CI runners; `pip` on 3.9 keeps
138
+ installing 1.0.1.
139
+
140
+ ### Note
141
+ - The 1.0.1 entry below says outputs were "byte-for-byte identical" to 1.0.0;
142
+ the check actually used a tolerance of 1e-9.
143
+
144
+ ## [1.0.1] — 2026-06-13
145
+
146
+ ### Changed
147
+ - `compute_complexity` is now a **pure orchestration layer**: it calls the
148
+ same public functions a user would call by hand (`diversity`, `ubiquity`,
149
+ and `distance` are now delegated instead of recomputed inline), so any
150
+ change to an indicator propagates automatically. Outputs are byte-for-byte
151
+ identical to 1.0.0 (verified against a saved baseline for all three methods).
152
+
153
+ ### Added
154
+ - `compute_complexity` now exposes `trim`, `dmin`, and `umin`, forwarded to
155
+ `eci_pci` — the well-connected `(2, 2)` core (recommended for sparse
156
+ subnational data) is finally reachable from the high-level pipeline, not
157
+ only from the matrix-level API.
158
+
159
+ ## [1.0.0] — 2026-06-12
160
+
161
+ First official release.
162
+
163
+ ### Added
164
+ - **Single entry point for complexity**: `eci_pci(mat, method="eigenvector" | "reflections" | "fitness")` in its own module (`complexity/eci_pci.py`), mirroring the interface of the R `economiccomplexity` package. Method-specific implementations remain public for advanced use (`eci_pci_eigenvector`, `method_of_reflections`, `fitness_complexity`).
165
+ - **Pre-processing for sparse data**: `trim_core(mat, dmin, umin)` iteratively prunes degenerate units (zero diversity/ubiquity) recomputing RCA each pass; applied automatically by `eci_pci` (`trim=True`, trimmed units returned as `NaN`). Use `dmin=2, umin=2` for the well-connected core recommended for subnational data.
166
+ - **ECI Optimization** (Stojkoski & Hidalgo 2026, *Research Policy* 55:105454): `calibrate_steppingstone`, `effort_matrix`, `forecast_specialization`, and `eci_optimization` (exact 0–1 program via `scipy.optimize.milp`), plus growth targeting (`calibrate_growth_model`, `eci_target_for_growth`, `expected_growth`).
167
+ - **Strategic diffusion** (Alshamsi, Pinheiro & Hidalgo 2018, *Nat. Commun.* 9:1328): `proximity_network`, `calibrate_contagion`, `activation_probabilities`, `diversification_strategy` (5 strategies), `expected_diversification_time` (validated against the paper's closed-form eq. 2), `compare_strategies`, and `optimize_sequence` (simulated annealing).
168
+ - **Documented short API**: aliases bound to the canonical functions (`density`, `relatedness`, `hhi`, `coi`, `cog`, `pgi`, `peii`, `spec_coefficient`, `cross_space_proximity`), new functions `make_sample_data`, `cosine_proximity`, `correlation_proximity`, and long-format panel wrappers `growth_rates`, `entry_tracking`, `exit_tracking`.
169
+ - `log_fitness` option (Cristelli et al. 2015 log scale) and convergence `tol` for the Method of Reflections; non-convergence warning for Fitness-Complexity.
170
+ - `continuous_method="correlation" | "cosine"` in `proximity()`/`continuous_proximity()`.
171
+ - Runnable examples in `examples/` (`basic_usage.py`, `eci_optimization.py`) and an API map section in the documentation.
172
+ - Expanded documentation: complete auto-generated API reference (87 functions, `docs/generate_api_reference.py`), indicator interpretation guide, and rewritten bilingual READMEs with quickstarts, data format, validation notes, and BibTeX citation.
173
+
174
+ ### Changed
175
+ - Default iterations unified at **20** for reflections and fitness (matching the R `economiccomplexity` package; for fitness it is a cap with early stopping at convergence).
176
+ - Method of Reflections output is now sign-oriented like the eigenvector method (ECI correlates positively with diversity, PCI negatively with ubiquity).
177
+ - `compute_complexity` routes all methods through the `eci_pci` dispatcher (validation and trimming included).
178
+ - Internal relative relatedness of the optimization module now follows Pinheiro et al. (2022, eq. 7) exactly (z-transform over the option set).
179
+ - SciPy minimum raised to 1.9 (`scipy.optimize.milp`).
180
+ - Documentation (EN/PT) fully revised: GitHub installation, real API signatures, new sections (pre-processing, ECI Optimization, strategic diffusion), corrected references (Tacchella et al. 2012).
181
+
182
+ ### Fixed
183
+ - NumPy 2.x compatibility: `np.trapz` removal broke `locational_gini`/`hoover_gini`.
184
+ - `cross_relatedness` returned the wrong column labels (crashed whenever the two spaces had different sizes).
185
+ - Missing standard-deviation guards in the eigenvector sign correction (silent NaN on degenerate matrices).
186
+ - Edge-case guards in the optimization layer (`b1 ≈ 0` effort, `a1 + a3·z ≈ 0` growth-target inversion).
187
+ - Documentation/API mismatches reported by external testing (`rpop`, `pgi`, `peii`, `expy` signatures; `coi`/`cog` argument order; `proximity` return type).
188
+
189
+ ## [0.1.0] — 2026 (initial public release)
190
+
191
+ - Core indicators: RCA, RPOP, Mcp, diversity/ubiquity; ECI/PCI (eigenvector, reflections, fitness); proximity, relatedness density, co-occurrence, cross-space; specialization, inequality, productivity, patents, dynamics, COI/COG; `compute_complexity` pipeline.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: econcomplex
3
- Version: 1.0.1
3
+ Version: 1.2.0
4
4
  Summary: Python library for economic complexity and regional science indicators
5
5
  Author: Elton Freitas
6
6
  License-Expression: MIT
@@ -13,12 +13,13 @@ Classifier: Development Status :: 5 - Production/Stable
13
13
  Classifier: Intended Audience :: Science/Research
14
14
  Classifier: Programming Language :: Python :: 3
15
15
  Classifier: Programming Language :: Python :: 3 :: Only
16
- Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
20
21
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
- Requires-Python: >=3.9
22
+ Requires-Python: >=3.10
22
23
  Description-Content-Type: text/markdown
23
24
  License-File: LICENSE
24
25
  Requires-Dist: numpy>=1.21
@@ -33,14 +34,16 @@ Requires-Dist: pytest-cov; extra == "dev"
33
34
  Requires-Dist: twine; extra == "dev"
34
35
  Provides-Extra: network
35
36
  Requires-Dist: networkx>=2.6; extra == "network"
37
+ Provides-Extra: ml
38
+ Requires-Dist: scikit-learn>=1.0; extra == "ml"
36
39
  Dynamic: license-file
37
40
 
38
41
  # econcomplex
39
42
 
40
- [![version](https://img.shields.io/badge/version-1.0.0-blue)](CHANGELOG.md)
41
- [![python](https://img.shields.io/badge/python-3.9%2B-blue)](pyproject.toml)
43
+ [![version](https://img.shields.io/badge/version-1.2.0-blue)](CHANGELOG.md)
44
+ [![python](https://img.shields.io/badge/python-3.10%2B-blue)](pyproject.toml)
42
45
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
43
- [![tests](https://img.shields.io/badge/tests-81%20passing-brightgreen)](tests/)
46
+ [![tests](https://github.com/eltonfreitas/econcomplex/actions/workflows/tests.yml/badge.svg)](https://github.com/eltonfreitas/econcomplex/actions/workflows/tests.yml)
44
47
 
45
48
  **econcomplex** is a Python library for **economic complexity and regional
46
49
  science indicators**. It consolidates, in a single coherent API, the tools
@@ -57,18 +60,21 @@ diffusion) that, to our knowledge, is not available in any other package.
57
60
 
58
61
  | Group | Indicators |
59
62
  |---|---|
60
- | **Complexity** | ECI / PCI through a single entry point — `eci_pci(mat, method="eigenvector" \| "reflections" \| "fitness")` — plus subnational ECI projected with an external PCI |
61
- | **Relatedness / Product Space** | Proximity (discrete, correlation, cosine), relatedness density, distance, relative relatedness (option-set z-score), co-occurrence indices, cross-space proximity between two activity spaces |
63
+ | **Complexity** | ECI / PCI through a single entry point — `eci_pci(mat, method="eigenvector" \| "reflections" \| "fitness")` — plus subnational ECI projected with an external PCI, the GENEPY index (`method="genepy"`) and diagnostics of how reliable the ECI ranking is |
64
+ | **Relatedness / Product Space** | Proximity (discrete, correlation, cosine), relatedness density, distance, relative relatedness (option-set z-score), co-occurrence indices, cross-space proximity between two activity spaces, skill relatedness from flows, spatial density, density contributions and fixed-effects decomposition, implied comparative advantage, input-output relatedness |
62
65
  | **Specialization** | Location quotient, Hachman, Krugman, Hoover specialization coefficient, export similarity |
63
66
  | **Inequality / Concentration** | Gini, locational Gini, Hoover-Gini, Hoover index, Herfindahl-Hirschman, Shannon entropy |
64
67
  | **Productivity** | PRODY, EXPY, Product Gini Index, Product Emissions Intensity Index |
65
68
  | **Patents** | Ease of recombination, modular complexity |
66
69
  | **Dynamics** | Growth rates, entry/exit tracking — matrix-pair and long-panel APIs |
67
70
  | **Outlook** | Complexity Outlook Index (COI) and Gain (COG) |
71
+ | **Strategy** | Desirability index with explicit weights, sensitivity of the ranking to the weights, feasibility × desirability quadrants, opportunity alignment |
72
+ | **Policy lists** | Presence and potential of a region in any list of activities (green lists, missions, value chains), density that rests on a list, missing links of a chain, transition risk (exposure, lock-in, outlook) |
73
+ | **Entry prediction** | Entry targets with a risk set, and out-of-sample validation of any predictor: AUC, within-region AUC, precision/recall@k, Brier, bootstrap by region; optional prediction models (gradient boosting, random forest, logit) with out-of-sample probabilities, feature importance and expected size of entries |
68
74
  | **ECI Optimization** | Stepping-stone forecast model, entry-effort matrix, exact 0–1 program for minimal-effort diversification portfolios, growth targeting (Stojkoski & Hidalgo 2026) |
69
75
  | **Strategic diffusion** | Complex-contagion calibration, five diversification strategies, optimal entry sequencing (Alshamsi, Pinheiro & Hidalgo 2018) |
70
76
 
71
- 87 public functions in total — the PDF documentation carries a complete API
77
+ 112 public functions in total — the PDF documentation carries a complete API
72
78
  reference and an interpretation guide for every indicator family.
73
79
 
74
80
  ## Installation
@@ -83,14 +89,15 @@ Or, for the latest development version straight from GitHub:
83
89
  pip install git+https://github.com/eltonfreitas/econcomplex.git
84
90
  ```
85
91
 
86
- Requires Python ≥ 3.9 with `numpy ≥ 1.21` (1.x **and** 2.x supported),
87
- `pandas ≥ 1.3`, `scipy ≥ 1.9`. For local development:
92
+ Requires Python ≥ 3.10 with `numpy ≥ 1.21` (1.x **and** 2.x supported),
93
+ `pandas ≥ 1.3`, `scipy ≥ 1.9`. The prediction models are optional and need
94
+ scikit-learn: `pip install "econcomplex[ml]"`. For local development:
88
95
 
89
96
  ```bash
90
97
  git clone https://github.com/eltonfreitas/econcomplex.git
91
98
  cd econcomplex
92
99
  pip install -e .[dev]
93
- pytest # 81 tests
100
+ pytest # tests + docstring examples
94
101
  ```
95
102
 
96
103
  ## Quick start
@@ -120,7 +127,7 @@ mat = ec.pivot_to_matrix(df, "region", "sector", "employment")
120
127
  eci, pci = ec.eci_pci(mat) # eigenvector method (default)
121
128
  eci2, pci2 = ec.eci_pci(mat, method="fitness") # same call, other method
122
129
 
123
- phi = ec.proximity(mat)["product"] # product space
130
+ phi = ec.product_proximity(mat) # product space
124
131
  density = ec.density(mat, phi=phi) # 0–100 % relatedness density
125
132
  coi = ec.coi(mat, pci, phi=phi) # diversification potential
126
133
  ```
@@ -153,6 +160,35 @@ best = ec.optimize_sequence(adj, ec.mcp(mat).loc["my_region"],
153
160
  B=fit["B"], alpha=fit["alpha"])
154
161
  ```
155
162
 
163
+ ### 4. From indicators to a strategy
164
+
165
+ ```python
166
+ # why is an activity within reach, and what is specific to the pair?
167
+ ec.density_contributions(mat, "my_region", "target_activity", phi=phi)
168
+ specific = ec.decomposed_density(density) # net of region/activity effects
169
+
170
+ # what is worth having, and how robust is that ranking to the weights?
171
+ indicators = pd.DataFrame({"pci": pci, "wage": wage})
172
+ desirability = ec.desirability_index(indicators, weights={"pci": 0.6, "wage": 0.4})
173
+ robust = ec.weight_sensitivity(indicators, seed=1)
174
+
175
+ # short jumps, long bets, low value, avoid — per region
176
+ options = ec.relatedness_density_external(mat, phi=phi)
177
+ quadrants = ec.strategy_quadrants(options, desirability)
178
+
179
+ # does a score computed at t0 predict the entries observed by t1?
180
+ target, at_risk = ec.entry_targets(ec.rca(mat_t0), ec.rca(mat_t1))
181
+ ec.validate_entry({"density": ec.density(mat_t0), "persistence": ec.rca(mat_t0)},
182
+ target, baseline="persistence", n_boot=200)
183
+
184
+ # optional (pip install "econcomplex[ml]"): a model on several layers,
185
+ # predicted out of sample, region by region
186
+ X = ec.build_features(mat_t0, {"density": ec.density(mat_t0),
187
+ "implied": ec.implied_rca(mat_t0)}, at_risk=at_risk)
188
+ prob = ec.predict_entry(X, target, model="gbm", seed=1)
189
+ ec.explain_entry(X, target, seed=1) # which layers carry the prediction
190
+ ```
191
+
156
192
  ## Data format
157
193
 
158
194
  The high-level API expects **long-format** (tidy) data — one row per
@@ -172,15 +208,20 @@ data: `df = ec.make_sample_data(n_locs=50, n_acts=30, seed=42)`.
172
208
 
173
209
  ## Documentation and examples
174
210
 
175
- - **Technical documentation (PDF)** — formulas, step-by-step usage,
211
+ - **Technical documentation (PDF)** — a step-by-step tutorial with code and
212
+ output, formulas,
176
213
  interpretation guide, and the complete API reference:
177
214
  [English](docs/econcomplex_documentation_en.pdf) ·
178
215
  [Português](docs/econcomplex_documentation_pt.pdf)
179
216
  (LaTeX sources in [docs/](docs/))
180
- - **Runnable examples**: [examples/basic_usage.py](examples/basic_usage.py)
181
- (guided tour of every indicator group) and
217
+ - **Runnable examples**: [examples/tutorial.py](examples/tutorial.py)
218
+ (the step-by-step tutorial of the PDF, from the data to a list of targets),
219
+ [examples/basic_usage.py](examples/basic_usage.py)
220
+ (guided tour of every indicator group),
182
221
  [examples/eci_optimization.py](examples/eci_optimization.py)
183
- (optimization layer end to end)
222
+ (optimization layer end to end) and
223
+ [examples/diversification_strategy.py](examples/diversification_strategy.py)
224
+ (validation of relatedness, desirability, quadrants and policy lists)
184
225
  - **In-code reference**: every function has a full NumPy-style docstring —
185
226
  `help(ec.eci_pci)`
186
227
  - **[CHANGELOG.md](CHANGELOG.md)** — release history
@@ -192,7 +233,7 @@ bound to the same objects (`density`, `hhi`, `coi`, `pgi`, …).
192
233
 
193
234
  ## Validation
194
235
 
195
- The 81-test suite includes exact validations against the literature: the
236
+ The test suite includes exact validations against the literature: the
196
237
  eigenvector ECI/PCI uses the proper non-symmetric solver; the strategic
197
238
  diffusion module reproduces the closed-form solution of Alshamsi et al.
198
239
  (2018, eq. 2) on the wheel network; relative relatedness follows Pinheiro
@@ -207,7 +248,7 @@ library recovers the canonical ECI country ranking.
207
248
  author = {Freitas, Elton},
208
249
  title = {econcomplex: economic complexity and regional science indicators in Python},
209
250
  year = {2026},
210
- version = {1.0.0},
251
+ version = {1.2.0},
211
252
  url = {https://github.com/eltonfreitas/econcomplex}
212
253
  }
213
254
  ```
@@ -1,9 +1,9 @@
1
1
  # econcomplex
2
2
 
3
- [![version](https://img.shields.io/badge/version-1.0.0-blue)](CHANGELOG.md)
4
- [![python](https://img.shields.io/badge/python-3.9%2B-blue)](pyproject.toml)
3
+ [![version](https://img.shields.io/badge/version-1.2.0-blue)](CHANGELOG.md)
4
+ [![python](https://img.shields.io/badge/python-3.10%2B-blue)](pyproject.toml)
5
5
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
6
- [![tests](https://img.shields.io/badge/tests-81%20passing-brightgreen)](tests/)
6
+ [![tests](https://github.com/eltonfreitas/econcomplex/actions/workflows/tests.yml/badge.svg)](https://github.com/eltonfreitas/econcomplex/actions/workflows/tests.yml)
7
7
 
8
8
  **econcomplex** is a Python library for **economic complexity and regional
9
9
  science indicators**. It consolidates, in a single coherent API, the tools
@@ -20,18 +20,21 @@ diffusion) that, to our knowledge, is not available in any other package.
20
20
 
21
21
  | Group | Indicators |
22
22
  |---|---|
23
- | **Complexity** | ECI / PCI through a single entry point — `eci_pci(mat, method="eigenvector" \| "reflections" \| "fitness")` — plus subnational ECI projected with an external PCI |
24
- | **Relatedness / Product Space** | Proximity (discrete, correlation, cosine), relatedness density, distance, relative relatedness (option-set z-score), co-occurrence indices, cross-space proximity between two activity spaces |
23
+ | **Complexity** | ECI / PCI through a single entry point — `eci_pci(mat, method="eigenvector" \| "reflections" \| "fitness")` — plus subnational ECI projected with an external PCI, the GENEPY index (`method="genepy"`) and diagnostics of how reliable the ECI ranking is |
24
+ | **Relatedness / Product Space** | Proximity (discrete, correlation, cosine), relatedness density, distance, relative relatedness (option-set z-score), co-occurrence indices, cross-space proximity between two activity spaces, skill relatedness from flows, spatial density, density contributions and fixed-effects decomposition, implied comparative advantage, input-output relatedness |
25
25
  | **Specialization** | Location quotient, Hachman, Krugman, Hoover specialization coefficient, export similarity |
26
26
  | **Inequality / Concentration** | Gini, locational Gini, Hoover-Gini, Hoover index, Herfindahl-Hirschman, Shannon entropy |
27
27
  | **Productivity** | PRODY, EXPY, Product Gini Index, Product Emissions Intensity Index |
28
28
  | **Patents** | Ease of recombination, modular complexity |
29
29
  | **Dynamics** | Growth rates, entry/exit tracking — matrix-pair and long-panel APIs |
30
30
  | **Outlook** | Complexity Outlook Index (COI) and Gain (COG) |
31
+ | **Strategy** | Desirability index with explicit weights, sensitivity of the ranking to the weights, feasibility × desirability quadrants, opportunity alignment |
32
+ | **Policy lists** | Presence and potential of a region in any list of activities (green lists, missions, value chains), density that rests on a list, missing links of a chain, transition risk (exposure, lock-in, outlook) |
33
+ | **Entry prediction** | Entry targets with a risk set, and out-of-sample validation of any predictor: AUC, within-region AUC, precision/recall@k, Brier, bootstrap by region; optional prediction models (gradient boosting, random forest, logit) with out-of-sample probabilities, feature importance and expected size of entries |
31
34
  | **ECI Optimization** | Stepping-stone forecast model, entry-effort matrix, exact 0–1 program for minimal-effort diversification portfolios, growth targeting (Stojkoski & Hidalgo 2026) |
32
35
  | **Strategic diffusion** | Complex-contagion calibration, five diversification strategies, optimal entry sequencing (Alshamsi, Pinheiro & Hidalgo 2018) |
33
36
 
34
- 87 public functions in total — the PDF documentation carries a complete API
37
+ 112 public functions in total — the PDF documentation carries a complete API
35
38
  reference and an interpretation guide for every indicator family.
36
39
 
37
40
  ## Installation
@@ -46,14 +49,15 @@ Or, for the latest development version straight from GitHub:
46
49
  pip install git+https://github.com/eltonfreitas/econcomplex.git
47
50
  ```
48
51
 
49
- Requires Python ≥ 3.9 with `numpy ≥ 1.21` (1.x **and** 2.x supported),
50
- `pandas ≥ 1.3`, `scipy ≥ 1.9`. For local development:
52
+ Requires Python ≥ 3.10 with `numpy ≥ 1.21` (1.x **and** 2.x supported),
53
+ `pandas ≥ 1.3`, `scipy ≥ 1.9`. The prediction models are optional and need
54
+ scikit-learn: `pip install "econcomplex[ml]"`. For local development:
51
55
 
52
56
  ```bash
53
57
  git clone https://github.com/eltonfreitas/econcomplex.git
54
58
  cd econcomplex
55
59
  pip install -e .[dev]
56
- pytest # 81 tests
60
+ pytest # tests + docstring examples
57
61
  ```
58
62
 
59
63
  ## Quick start
@@ -83,7 +87,7 @@ mat = ec.pivot_to_matrix(df, "region", "sector", "employment")
83
87
  eci, pci = ec.eci_pci(mat) # eigenvector method (default)
84
88
  eci2, pci2 = ec.eci_pci(mat, method="fitness") # same call, other method
85
89
 
86
- phi = ec.proximity(mat)["product"] # product space
90
+ phi = ec.product_proximity(mat) # product space
87
91
  density = ec.density(mat, phi=phi) # 0–100 % relatedness density
88
92
  coi = ec.coi(mat, pci, phi=phi) # diversification potential
89
93
  ```
@@ -116,6 +120,35 @@ best = ec.optimize_sequence(adj, ec.mcp(mat).loc["my_region"],
116
120
  B=fit["B"], alpha=fit["alpha"])
117
121
  ```
118
122
 
123
+ ### 4. From indicators to a strategy
124
+
125
+ ```python
126
+ # why is an activity within reach, and what is specific to the pair?
127
+ ec.density_contributions(mat, "my_region", "target_activity", phi=phi)
128
+ specific = ec.decomposed_density(density) # net of region/activity effects
129
+
130
+ # what is worth having, and how robust is that ranking to the weights?
131
+ indicators = pd.DataFrame({"pci": pci, "wage": wage})
132
+ desirability = ec.desirability_index(indicators, weights={"pci": 0.6, "wage": 0.4})
133
+ robust = ec.weight_sensitivity(indicators, seed=1)
134
+
135
+ # short jumps, long bets, low value, avoid — per region
136
+ options = ec.relatedness_density_external(mat, phi=phi)
137
+ quadrants = ec.strategy_quadrants(options, desirability)
138
+
139
+ # does a score computed at t0 predict the entries observed by t1?
140
+ target, at_risk = ec.entry_targets(ec.rca(mat_t0), ec.rca(mat_t1))
141
+ ec.validate_entry({"density": ec.density(mat_t0), "persistence": ec.rca(mat_t0)},
142
+ target, baseline="persistence", n_boot=200)
143
+
144
+ # optional (pip install "econcomplex[ml]"): a model on several layers,
145
+ # predicted out of sample, region by region
146
+ X = ec.build_features(mat_t0, {"density": ec.density(mat_t0),
147
+ "implied": ec.implied_rca(mat_t0)}, at_risk=at_risk)
148
+ prob = ec.predict_entry(X, target, model="gbm", seed=1)
149
+ ec.explain_entry(X, target, seed=1) # which layers carry the prediction
150
+ ```
151
+
119
152
  ## Data format
120
153
 
121
154
  The high-level API expects **long-format** (tidy) data — one row per
@@ -135,15 +168,20 @@ data: `df = ec.make_sample_data(n_locs=50, n_acts=30, seed=42)`.
135
168
 
136
169
  ## Documentation and examples
137
170
 
138
- - **Technical documentation (PDF)** — formulas, step-by-step usage,
171
+ - **Technical documentation (PDF)** — a step-by-step tutorial with code and
172
+ output, formulas,
139
173
  interpretation guide, and the complete API reference:
140
174
  [English](docs/econcomplex_documentation_en.pdf) ·
141
175
  [Português](docs/econcomplex_documentation_pt.pdf)
142
176
  (LaTeX sources in [docs/](docs/))
143
- - **Runnable examples**: [examples/basic_usage.py](examples/basic_usage.py)
144
- (guided tour of every indicator group) and
177
+ - **Runnable examples**: [examples/tutorial.py](examples/tutorial.py)
178
+ (the step-by-step tutorial of the PDF, from the data to a list of targets),
179
+ [examples/basic_usage.py](examples/basic_usage.py)
180
+ (guided tour of every indicator group),
145
181
  [examples/eci_optimization.py](examples/eci_optimization.py)
146
- (optimization layer end to end)
182
+ (optimization layer end to end) and
183
+ [examples/diversification_strategy.py](examples/diversification_strategy.py)
184
+ (validation of relatedness, desirability, quadrants and policy lists)
147
185
  - **In-code reference**: every function has a full NumPy-style docstring —
148
186
  `help(ec.eci_pci)`
149
187
  - **[CHANGELOG.md](CHANGELOG.md)** — release history
@@ -155,7 +193,7 @@ bound to the same objects (`density`, `hhi`, `coi`, `pgi`, …).
155
193
 
156
194
  ## Validation
157
195
 
158
- The 81-test suite includes exact validations against the literature: the
196
+ The test suite includes exact validations against the literature: the
159
197
  eigenvector ECI/PCI uses the proper non-symmetric solver; the strategic
160
198
  diffusion module reproduces the closed-form solution of Alshamsi et al.
161
199
  (2018, eq. 2) on the wheel network; relative relatedness follows Pinheiro
@@ -170,7 +208,7 @@ library recovers the canonical ECI country ranking.
170
208
  author = {Freitas, Elton},
171
209
  title = {econcomplex: economic complexity and regional science indicators in Python},
172
210
  year = {2026},
173
- version = {1.0.0},
211
+ version = {1.2.0},
174
212
  url = {https://github.com/eltonfreitas/econcomplex}
175
213
  }
176
214
  ```