econcomplex 1.0.0__py3-none-any.whl

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 (43) hide show
  1. econcomplex/__init__.py +220 -0
  2. econcomplex/complexity/__init__.py +23 -0
  3. econcomplex/complexity/eci_pci.py +131 -0
  4. econcomplex/complexity/eigenvector.py +115 -0
  5. econcomplex/complexity/fitness.py +130 -0
  6. econcomplex/complexity/reflections.py +173 -0
  7. econcomplex/complexity/subnational.py +82 -0
  8. econcomplex/core/__init__.py +23 -0
  9. econcomplex/core/diversity.py +125 -0
  10. econcomplex/core/preprocess.py +83 -0
  11. econcomplex/core/rca.py +161 -0
  12. econcomplex/core/utils.py +137 -0
  13. econcomplex/dynamics/__init__.py +10 -0
  14. econcomplex/dynamics/entry_exit.py +248 -0
  15. econcomplex/dynamics/growth.py +146 -0
  16. econcomplex/inequality/__init__.py +11 -0
  17. econcomplex/inequality/concentration.py +148 -0
  18. econcomplex/inequality/gini.py +164 -0
  19. econcomplex/optimization/__init__.py +46 -0
  20. econcomplex/optimization/diffusion.py +379 -0
  21. econcomplex/optimization/growth_target.py +170 -0
  22. econcomplex/optimization/portfolio.py +178 -0
  23. econcomplex/optimization/steppingstone.py +267 -0
  24. econcomplex/outlook/__init__.py +6 -0
  25. econcomplex/outlook/coi_cog.py +168 -0
  26. econcomplex/patents/__init__.py +7 -0
  27. econcomplex/patents/recombination.py +135 -0
  28. econcomplex/pipeline.py +255 -0
  29. econcomplex/productivity/__init__.py +8 -0
  30. econcomplex/productivity/prody.py +218 -0
  31. econcomplex/relatedness/__init__.py +25 -0
  32. econcomplex/relatedness/cooccurrence.py +173 -0
  33. econcomplex/relatedness/cross_space.py +142 -0
  34. econcomplex/relatedness/density.py +232 -0
  35. econcomplex/relatedness/proximity.py +214 -0
  36. econcomplex/specialization/__init__.py +17 -0
  37. econcomplex/specialization/location_quotient.py +163 -0
  38. econcomplex/specialization/similarity.py +68 -0
  39. econcomplex-1.0.0.dist-info/METADATA +223 -0
  40. econcomplex-1.0.0.dist-info/RECORD +43 -0
  41. econcomplex-1.0.0.dist-info/WHEEL +5 -0
  42. econcomplex-1.0.0.dist-info/licenses/LICENSE +22 -0
  43. econcomplex-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.4
2
+ Name: econcomplex
3
+ Version: 1.0.0
4
+ Summary: Python library for economic complexity and regional science indicators
5
+ Author: Elton Freitas
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/eltonfreitas/econcomplex
8
+ Project-URL: Documentation, https://github.com/eltonfreitas/econcomplex/tree/main/docs
9
+ Project-URL: Changelog, https://github.com/eltonfreitas/econcomplex/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/eltonfreitas/econcomplex/issues
11
+ Keywords: economic complexity,regional science,economic geography,product space,relatedness
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: numpy>=1.21
25
+ Requires-Dist: pandas>=1.3
26
+ Requires-Dist: scipy>=1.9
27
+ Provides-Extra: dev
28
+ Requires-Dist: black; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: isort; extra == "dev"
31
+ Requires-Dist: pytest; extra == "dev"
32
+ Requires-Dist: pytest-cov; extra == "dev"
33
+ Requires-Dist: twine; extra == "dev"
34
+ Provides-Extra: network
35
+ Requires-Dist: networkx>=2.6; extra == "network"
36
+ Dynamic: license-file
37
+
38
+ # econcomplex
39
+
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)
42
+ [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
43
+ [![tests](https://img.shields.io/badge/tests-81%20passing-brightgreen)](tests/)
44
+
45
+ **econcomplex** is a Python library for **economic complexity and regional
46
+ science indicators**. It consolidates, in a single coherent API, the tools
47
+ scattered across the reference packages of the field — `EconGeo` (R),
48
+ `economiccomplexity` (R), `py-ecomplexity`, `py-economic-complexity` — and
49
+ adds a **target-oriented optimization layer** (ECI Optimization and strategic
50
+ diffusion) that, to our knowledge, is not available in any other package.
51
+
52
+ *Leia em português: [README.pt-BR.md](README.pt-BR.md).*
53
+
54
+ ---
55
+
56
+ ## What it computes
57
+
58
+ | Group | Indicators |
59
+ |---|---|
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 |
62
+ | **Specialization** | Location quotient, Hachman, Krugman, Hoover specialization coefficient, export similarity |
63
+ | **Inequality / Concentration** | Gini, locational Gini, Hoover-Gini, Hoover index, Herfindahl-Hirschman, Shannon entropy |
64
+ | **Productivity** | PRODY, EXPY, Product Gini Index, Product Emissions Intensity Index |
65
+ | **Patents** | Ease of recombination, modular complexity |
66
+ | **Dynamics** | Growth rates, entry/exit tracking — matrix-pair and long-panel APIs |
67
+ | **Outlook** | Complexity Outlook Index (COI) and Gain (COG) |
68
+ | **ECI Optimization** | Stepping-stone forecast model, entry-effort matrix, exact 0–1 program for minimal-effort diversification portfolios, growth targeting (Stojkoski & Hidalgo 2026) |
69
+ | **Strategic diffusion** | Complex-contagion calibration, five diversification strategies, optimal entry sequencing (Alshamsi, Pinheiro & Hidalgo 2018) |
70
+
71
+ 87 public functions in total — the PDF documentation carries a complete API
72
+ reference and an interpretation guide for every indicator family.
73
+
74
+ ## Installation
75
+
76
+ ```bash
77
+ pip install econcomplex
78
+ ```
79
+
80
+ Or, for the latest development version straight from GitHub:
81
+
82
+ ```bash
83
+ pip install git+https://github.com/eltonfreitas/econcomplex.git
84
+ ```
85
+
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:
88
+
89
+ ```bash
90
+ git clone https://github.com/eltonfreitas/econcomplex.git
91
+ cd econcomplex
92
+ pip install -e .[dev]
93
+ pytest # 81 tests
94
+ ```
95
+
96
+ ## Quick start
97
+
98
+ ### 1. One call, every indicator (long-format data)
99
+
100
+ ```python
101
+ import pandas as pd
102
+ import econcomplex as ec
103
+
104
+ df = pd.read_csv("my_data.csv") # columns: region, sector, employment[, year]
105
+
106
+ result = ec.compute_complexity(
107
+ df,
108
+ cols={"loc": "region", "act": "sector", "val": "employment", "time": "year"},
109
+ method="eigenvector", # or "reflections" / "fitness"
110
+ )
111
+ # adds columns: rca, mcp, diversity, ubiquity, eci, pci, density, distance, coi, cog
112
+ # with a "time" column the pipeline recomputes everything per period automatically
113
+ ```
114
+
115
+ ### 2. Working with matrices
116
+
117
+ ```python
118
+ mat = ec.pivot_to_matrix(df, "region", "sector", "employment")
119
+
120
+ eci, pci = ec.eci_pci(mat) # eigenvector method (default)
121
+ eci2, pci2 = ec.eci_pci(mat, method="fitness") # same call, other method
122
+
123
+ phi = ec.proximity(mat)["product"] # product space
124
+ density = ec.density(mat, phi=phi) # 0–100 % relatedness density
125
+ coi = ec.coi(mat, pci, phi=phi) # diversification potential
126
+ ```
127
+
128
+ Degenerate units (zero diversity or ubiquity) are **trimmed automatically**
129
+ and returned as `NaN`; for very sparse data (e.g. municipal trade) use the
130
+ well-connected core: `ec.eci_pci(mat, dmin=2, umin=2)` or `ec.trim_core(mat, 2, 2)`.
131
+
132
+ ### 3. Diversification targets (ECI Optimization)
133
+
134
+ Requires a panel with at least the periods *t*, *t+τ* and *t+Δt*:
135
+
136
+ ```python
137
+ model = ec.calibrate_steppingstone(panel, "region", "sector", "employment",
138
+ "year", horizon=10, steppingstone=5)
139
+
140
+ portfolio = ec.eci_optimization(mat, model, delta_eci=0.1)
141
+ # → minimal-effort set of new activities per region that raises its ECI by 0.1
142
+
143
+ # Growth targeting: convert a 3.5 %/yr target into an ECI target
144
+ gm = ec.calibrate_growth_model(macro, "region", "year", "gdppc", "eci")
145
+ eci_star = ec.eci_target_for_growth(gm, 0.035, gdppc_now)
146
+ portfolio = ec.eci_optimization(mat, model, target_eci=eci_star)
147
+
148
+ # When to make unrelated bets (strategic diffusion)
149
+ adj = ec.proximity_network(mat)
150
+ fit = ec.calibrate_contagion(panel, "region", "sector", "employment", "year",
151
+ adjacency=adj)
152
+ best = ec.optimize_sequence(adj, ec.mcp(mat).loc["my_region"],
153
+ B=fit["B"], alpha=fit["alpha"])
154
+ ```
155
+
156
+ ## Data format
157
+
158
+ The high-level API expects **long-format** (tidy) data — one row per
159
+ (location, activity[, period]):
160
+
161
+ | region | sector | employment | year |
162
+ |---|---|---:|---|
163
+ | SP | cnae_10 | 12345 | 2022 |
164
+ | SP | cnae_25 | 6789 | 2022 |
165
+ | RJ | cnae_10 | 9012 | 2022 |
166
+
167
+ Requirements: no duplicate (location, activity, period) rows, non-negative
168
+ values, no `NaN`, a single geographic level and a single activity
169
+ classification per analysis. Works with employment, exports, patents,
170
+ payroll — anything shaped location × activity × value. To experiment without
171
+ data: `df = ec.make_sample_data(n_locs=50, n_acts=30, seed=42)`.
172
+
173
+ ## Documentation and examples
174
+
175
+ - **Technical documentation (PDF)** — formulas, step-by-step usage,
176
+ interpretation guide, and the complete API reference:
177
+ [English](docs/econcomplex_documentation_en.pdf) ·
178
+ [Português](docs/econcomplex_documentation_pt.pdf)
179
+ (LaTeX sources in [docs/](docs/))
180
+ - **Runnable examples**: [examples/basic_usage.py](examples/basic_usage.py)
181
+ (guided tour of every indicator group) and
182
+ [examples/eci_optimization.py](examples/eci_optimization.py)
183
+ (optimization layer end to end)
184
+ - **In-code reference**: every function has a full NumPy-style docstring —
185
+ `help(ec.eci_pci)`
186
+ - **[CHANGELOG.md](CHANGELOG.md)** — release history
187
+
188
+ The API has three layers (detailed map in the PDF): *entry points* such as
189
+ `eci_pci` and `compute_complexity`; *advanced implementations* they delegate
190
+ to (`method_of_reflections`, `fitness_complexity`, …); and short *aliases*
191
+ bound to the same objects (`density`, `hhi`, `coi`, `pgi`, …).
192
+
193
+ ## Validation
194
+
195
+ The 81-test suite includes exact validations against the literature: the
196
+ eigenvector ECI/PCI uses the proper non-symmetric solver; the strategic
197
+ diffusion module reproduces the closed-form solution of Alshamsi et al.
198
+ (2018, eq. 2) on the wheel network; relative relatedness follows Pinheiro
199
+ et al. (2022, eq. 7) exactly; and the 0–1 portfolio program is solved
200
+ exactly with `scipy.optimize.milp`. On the 2022–2024 BACI trade data the
201
+ library recovers the canonical ECI country ranking.
202
+
203
+ ## Citation
204
+
205
+ ```bibtex
206
+ @software{freitas_econcomplex_2026,
207
+ author = {Freitas, Elton},
208
+ title = {econcomplex: economic complexity and regional science indicators in Python},
209
+ year = {2026},
210
+ version = {1.0.0},
211
+ url = {https://github.com/eltonfreitas/econcomplex}
212
+ }
213
+ ```
214
+
215
+ Please also cite the original papers of the indicators you use — full list
216
+ in the PDF documentation. Key references: Hidalgo & Hausmann (2009, *PNAS*);
217
+ Hidalgo et al. (2007, *Science*); Tacchella et al. (2012, *Sci. Rep.*);
218
+ Alshamsi, Pinheiro & Hidalgo (2018, *Nat. Commun.*); Pinheiro et al. (2022,
219
+ *Res. Policy*); Stojkoski & Hidalgo (2026, *Res. Policy*).
220
+
221
+ ## License
222
+
223
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,43 @@
1
+ econcomplex/__init__.py,sha256=t0QSU8xqH3iubzCJZMfZbZhv5wtbXatrl0r0VCLJMGI,9275
2
+ econcomplex/pipeline.py,sha256=SQ56vd75XWbwJtbpCvusF_oGxgDRZCaAFMzmcHthkp0,8369
3
+ econcomplex/complexity/__init__.py,sha256=pcJpIaK8G4w78MtFEZi7O4hiZgAhdYUEhXb5En_Kqy4,610
4
+ econcomplex/complexity/eci_pci.py,sha256=FPtNIkjUOEVLL42ccs5Yp_Gx4zVU9-WMVPdiZZRwxUE,5349
5
+ econcomplex/complexity/eigenvector.py,sha256=vwwoCawileCgMLttB3drkUhyO0IjVgQD_Nx9K1UxZl0,3848
6
+ econcomplex/complexity/fitness.py,sha256=-bNhGBOkNAPis6rs4mRI4Wdr2f-lC1zK0qPtaGnAOy4,4211
7
+ econcomplex/complexity/reflections.py,sha256=lsVKyCMfONDwM-_eXzKUE-W2yXfyS0cG6tImrMIUzkY,5558
8
+ econcomplex/complexity/subnational.py,sha256=9sappLz-00mvKIajwB6qVjdqOs7hPsqpPLFhpasgzJ8,2332
9
+ econcomplex/core/__init__.py,sha256=3_OfanXe7NNFI-14NgbAYHudsGQWDKNErzrSrLBkcrE,422
10
+ econcomplex/core/diversity.py,sha256=4zo6fLZt9MB-_Igyk89ETEAue_FKvavRJXE_YmrQEkU,2978
11
+ econcomplex/core/preprocess.py,sha256=RGrQBQHQzebLWCHizhYnnx-qr0QkF65ZeLyFuQPlM5g,2879
12
+ econcomplex/core/rca.py,sha256=iF0I9ScxHnSFKQZknd2O-It2fdDndeg-nuC7JNnrMjQ,4775
13
+ econcomplex/core/utils.py,sha256=78Oh7DLV99s8i8Erozwmk_kbwzlt19sEO86I_hiaNPM,4268
14
+ econcomplex/dynamics/__init__.py,sha256=G7GwV0Y_Moi_81RaJiLQ6LnthF2z0BzLODRQ07nWl4M,209
15
+ econcomplex/dynamics/entry_exit.py,sha256=o0fzxjZFaOiJwo3UpFlne3q-XTZCQNSkfxA2UGAM7hM,7213
16
+ econcomplex/dynamics/growth.py,sha256=oMVOUsPNbUjo8L8HN59kW3zw4laJVlt7T75rJ98WUto,3968
17
+ econcomplex/inequality/__init__.py,sha256=CuvMnETUIeJirBriZM087gE93hfgnSrzwfIdXTuZg3o,252
18
+ econcomplex/inequality/concentration.py,sha256=ebNGEI29C3SWgpG5LpKT-dSkYP_CvGvr5Y7H45Dt1c0,3626
19
+ econcomplex/inequality/gini.py,sha256=quROX_W_NC063b6L1UfjeJUjoHbuqrQV1HoPuCj82iM,4678
20
+ econcomplex/optimization/__init__.py,sha256=pJcKbhFtg_l_jg_JoqNpM6ME5xN4Y7ke13JESxTx9fI,1200
21
+ econcomplex/optimization/diffusion.py,sha256=IMVkBhGVvU47is4hWiElhCQmqTxSJUEvh9otCnyEUgs,12886
22
+ econcomplex/optimization/growth_target.py,sha256=iaShr-6vo-IjjSkIP2Sc5WWY3IMn9_KxEpcEUHWJOdw,5787
23
+ econcomplex/optimization/portfolio.py,sha256=79EqFgdGcDCENpUD4QT1JoTFLQ4Horidkq6A49uoFco,6141
24
+ econcomplex/optimization/steppingstone.py,sha256=N3CUBZD4PQUrrsFmmpYsU-XUr1mNTuHIlfQIX_1kV5s,9454
25
+ econcomplex/outlook/__init__.py,sha256=L_mFaPtCK3_f78M0aVEDtUiYkRs_rplDkiI2jNZC1w0,149
26
+ econcomplex/outlook/coi_cog.py,sha256=eEDqxz82koDhsJU1c1e8k8kldFgxyS7lZ-H8crjSFaU,5097
27
+ econcomplex/patents/__init__.py,sha256=lVJp1oQbvAP9gsBbZbBbDoVeWArViqHFO5gTE6X0Zfc,193
28
+ econcomplex/patents/recombination.py,sha256=qYTyrQJlb_d-16tcs37ovYRbGZLfenJyMB5y2akzJj8,3731
29
+ econcomplex/productivity/__init__.py,sha256=iXYPmGNcy4J4O49lfbqXpiBcTOM-i_qhWWvBwOIdPBA,173
30
+ econcomplex/productivity/prody.py,sha256=Ar3rDBFB_Wp-pB0GcfWuMUyvrKrBQ3U85SC-dF9VGPY,5887
31
+ econcomplex/relatedness/__init__.py,sha256=F1VydJg2bLzTgm-cfChqhW1fl4zEdboXyhP2p2fUWRU,669
32
+ econcomplex/relatedness/cooccurrence.py,sha256=2fWW0ghmtGdanYp5Cp_Q4wp37mGWIsT5jSwNt4B0xdM,4792
33
+ econcomplex/relatedness/cross_space.py,sha256=rXUbu5GExNbeCFFe7b_od1Bgej-tPv-_1Hwv9IkZqUU,4067
34
+ econcomplex/relatedness/density.py,sha256=IXj8kAqgkzPI73hULyWdhI11azNROg-A--bPlCzps-4,6983
35
+ econcomplex/relatedness/proximity.py,sha256=IfZKrZvQCnsHMi9DmBfj1DiJjh9GprRENqGAp56EEUk,6949
36
+ econcomplex/specialization/__init__.py,sha256=q4gO40Pz9qYoRDwTyT6JfxNyfMQIxjfykKsW8yOta6c,367
37
+ econcomplex/specialization/location_quotient.py,sha256=CwujkAYsAGVfnBou6boJG-Z1s99-nESn75njBojv61M,4088
38
+ econcomplex/specialization/similarity.py,sha256=0BNF4ll3wYHUR5SHlAp_W2r-6e25JUgGwlZTokht9BE,1648
39
+ econcomplex-1.0.0.dist-info/licenses/LICENSE,sha256=pqiYdbSldmazMVu8J1h4j7wQCu9FWoZ_IYAFUelk6Qo,1071
40
+ econcomplex-1.0.0.dist-info/METADATA,sha256=4w81FuZC5M7iolb-D6q7KQ3WtkdSMyNqqsatrPw_MBY,9509
41
+ econcomplex-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
42
+ econcomplex-1.0.0.dist-info/top_level.txt,sha256=9r2RW-_8WsUeKX4_oUTy45xc1YayZ-nZ-Zv3PXtZZrk,12
43
+ econcomplex-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elton Freitas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1 @@
1
+ econcomplex