econcomplex 1.0.0__tar.gz → 1.0.1__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.
- {econcomplex-1.0.0 → econcomplex-1.0.1}/CHANGELOG.md +15 -0
- {econcomplex-1.0.0/econcomplex.egg-info → econcomplex-1.0.1}/PKG-INFO +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/api_reference_en.tex +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/api_reference_pt.tex +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/econcomplex_documentation_en.pdf +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/econcomplex_documentation_en.tex +19 -4
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/econcomplex_documentation_pt.pdf +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/econcomplex_documentation_pt.tex +20 -4
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/__init__.py +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/pipeline.py +37 -9
- {econcomplex-1.0.0 → econcomplex-1.0.1/econcomplex.egg-info}/PKG-INFO +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/pyproject.toml +1 -1
- {econcomplex-1.0.0 → econcomplex-1.0.1}/tests/test_core.py +43 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/LICENSE +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/MANIFEST.in +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/README.md +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/README.pt-BR.md +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/docs/generate_api_reference.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/eci_pci.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/eigenvector.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/fitness.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/reflections.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/complexity/subnational.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/core/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/core/diversity.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/core/preprocess.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/core/rca.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/core/utils.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/dynamics/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/dynamics/entry_exit.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/dynamics/growth.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/inequality/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/inequality/concentration.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/inequality/gini.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/optimization/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/optimization/diffusion.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/optimization/growth_target.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/optimization/portfolio.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/optimization/steppingstone.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/outlook/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/outlook/coi_cog.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/patents/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/patents/recombination.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/productivity/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/productivity/prody.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/relatedness/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/relatedness/cooccurrence.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/relatedness/cross_space.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/relatedness/density.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/relatedness/proximity.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/specialization/__init__.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/specialization/location_quotient.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex/specialization/similarity.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex.egg-info/SOURCES.txt +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex.egg-info/dependency_links.txt +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex.egg-info/requires.txt +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/econcomplex.egg-info/top_level.txt +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/examples/basic_usage.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/examples/eci_optimization.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/setup.cfg +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/setup.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/tests/test_diffusion.py +0 -0
- {econcomplex-1.0.0 → econcomplex-1.0.1}/tests/test_optimization.py +0 -0
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.1] — 2026-06-13
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- `compute_complexity` is now a **pure orchestration layer**: it calls the
|
|
7
|
+
same public functions a user would call by hand (`diversity`, `ubiquity`,
|
|
8
|
+
and `distance` are now delegated instead of recomputed inline), so any
|
|
9
|
+
change to an indicator propagates automatically. Outputs are byte-for-byte
|
|
10
|
+
identical to 1.0.0 (verified against a saved baseline for all three methods).
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `compute_complexity` now exposes `trim`, `dmin`, and `umin`, forwarded to
|
|
14
|
+
`eci_pci` — the well-connected `(2, 2)` core (recommended for sparse
|
|
15
|
+
subnational data) is finally reachable from the high-level pipeline, not
|
|
16
|
+
only from the matrix-level API.
|
|
17
|
+
|
|
3
18
|
## [1.0.0] — 2026-06-12
|
|
4
19
|
|
|
5
20
|
First official release.
|
|
@@ -169,6 +169,6 @@
|
|
|
169
169
|
\toprule
|
|
170
170
|
\textbf{Function} & \textbf{Description} \\
|
|
171
171
|
\midrule\endhead
|
|
172
|
-
\texttt{\footnotesize compute\_complexity(data, cols, *, method='eigenvector', presence\_test='rca', threshold=1.0, iterations=20, proximity\_type='discrete', proximity\_method='max', pop=None, compute\_coi\_cog=True, time\_col=None)} & {\small Compute a full suite of economic complexity indicators.} \\[2pt]
|
|
172
|
+
\texttt{\footnotesize compute\_complexity(data, cols, *, method='eigenvector', presence\_test='rca', threshold=1.0, iterations=20, proximity\_type='discrete', proximity\_method='max', pop=None, compute\_coi\_cog=True, trim=True, dmin=1, umin=1, time\_col=None)} & {\small Compute a full suite of economic complexity indicators.} \\[2pt]
|
|
173
173
|
\bottomrule
|
|
174
174
|
\end{longtable}
|
|
@@ -169,6 +169,6 @@
|
|
|
169
169
|
\toprule
|
|
170
170
|
\textbf{Fun\c{c}\~{a}o} & \textbf{Descri\c{c}\~{a}o} \\
|
|
171
171
|
\midrule\endhead
|
|
172
|
-
\texttt{\footnotesize compute\_complexity(data, cols, *, method='eigenvector', presence\_test='rca', threshold=1.0, iterations=20, proximity\_type='discrete', proximity\_method='max', pop=None, compute\_coi\_cog=True, time\_col=None)} & {\small Pipeline completo: todos os indicadores a partir do DataFrame longo (suporta painel).} \\[2pt]
|
|
172
|
+
\texttt{\footnotesize compute\_complexity(data, cols, *, method='eigenvector', presence\_test='rca', threshold=1.0, iterations=20, proximity\_type='discrete', proximity\_method='max', pop=None, compute\_coi\_cog=True, trim=True, dmin=1, umin=1, time\_col=None)} & {\small Pipeline completo: todos os indicadores a partir do DataFrame longo (suporta painel).} \\[2pt]
|
|
173
173
|
\bottomrule
|
|
174
174
|
\end{longtable}
|
|
Binary file
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
\vspace*{3cm}
|
|
167
167
|
{\Huge\bfseries\color{tblhead} econcomplex}\par
|
|
168
168
|
\vspace{0.5cm}
|
|
169
|
-
{\large\bfseries Technical Documentation --- Version 1.0.
|
|
169
|
+
{\large\bfseries Technical Documentation --- Version 1.0.1}\par
|
|
170
170
|
\vspace{1cm}
|
|
171
171
|
\rule{10cm}{0.8pt}\par
|
|
172
172
|
\vspace{0.8cm}
|
|
@@ -501,7 +501,7 @@ import sys
|
|
|
501
501
|
sys.path.insert(0, "/path/to/econcomplex")
|
|
502
502
|
|
|
503
503
|
import econcomplex as ec
|
|
504
|
-
print(ec.__version__) # 1.0.
|
|
504
|
+
print(ec.__version__) # 1.0.1
|
|
505
505
|
\end{lstlisting}
|
|
506
506
|
|
|
507
507
|
% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
@@ -962,6 +962,8 @@ def compute_complexity(
|
|
|
962
962
|
proximity_method: str = "max", # 'max' | 'sqrt' | 'min'
|
|
963
963
|
pop: pd.DataFrame | None = None, # population (for 'rpop'/'both')
|
|
964
964
|
compute_coi_cog: bool = True,
|
|
965
|
+
trim: bool = True, # pre-trim degenerate units
|
|
966
|
+
dmin: int = 1, umin: int = 1, # core thresholds (use 2,2 if sparse)
|
|
965
967
|
time_col: str | None = None,
|
|
966
968
|
) -> pd.DataFrame:
|
|
967
969
|
"""
|
|
@@ -971,6 +973,16 @@ def compute_complexity(
|
|
|
971
973
|
"""
|
|
972
974
|
\end{lstlisting}
|
|
973
975
|
|
|
976
|
+
\begin{notebox}
|
|
977
|
+
\texttt{compute\_complexity} is a thin \textbf{orchestration layer}: it
|
|
978
|
+
calls the same public functions you would call by hand (\fn{rca},
|
|
979
|
+
\fn{mcp}, \fn{diversity}, \fn{ubiquity}, \fn{eci\_pci}, \fn{proximity},
|
|
980
|
+
\fn{relatedness\_density}, \fn{distance}, \fn{coi}/\fn{cog}) and merges
|
|
981
|
+
the results back into long format, looping over periods for panels. It
|
|
982
|
+
is the convenience entry point for the common case; for fine-grained
|
|
983
|
+
control, call the matrix-level functions directly.
|
|
984
|
+
\end{notebox}
|
|
985
|
+
|
|
974
986
|
\subsection{Parameters}
|
|
975
987
|
|
|
976
988
|
\begin{center}
|
|
@@ -989,6 +1001,8 @@ def compute_complexity(
|
|
|
989
1001
|
\texttt{proximity\_method} & \texttt{str} & Proximity normalization \\
|
|
990
1002
|
\texttt{pop} & \texttt{DataFrame} & Population, required for RPOP \\
|
|
991
1003
|
\texttt{compute\_coi\_cog} & \texttt{bool} & Compute COI and COG (slower) \\
|
|
1004
|
+
\texttt{trim} & \texttt{bool} & Pre-trim degenerate units (default: True) \\
|
|
1005
|
+
\texttt{dmin}, \texttt{umin} & \texttt{int} & Core thresholds forwarded to \fn{eci\_pci}; use 2 for sparse data \\
|
|
992
1006
|
\bottomrule
|
|
993
1007
|
\end{tabular}
|
|
994
1008
|
\end{center}
|
|
@@ -996,7 +1010,8 @@ def compute_complexity(
|
|
|
996
1010
|
\begin{notebox}
|
|
997
1011
|
Degenerate units (zero diversity or ubiquity) are automatically
|
|
998
1012
|
trimmed by the complexity step and returned as \texttt{NaN}
|
|
999
|
-
(see \fn{trim\_core}).
|
|
1013
|
+
(see \fn{trim\_core}). For sparse subnational data, pass
|
|
1014
|
+
\texttt{dmin=2, umin=2} to restrict to the well-connected core.
|
|
1000
1015
|
\end{notebox}
|
|
1001
1016
|
|
|
1002
1017
|
%% ============================================================
|
|
@@ -1264,7 +1279,7 @@ original papers of the indicators used (see References).
|
|
|
1264
1279
|
|
|
1265
1280
|
\begin{lstlisting}[language={}, caption={Check the library version}]
|
|
1266
1281
|
import econcomplex as ec
|
|
1267
|
-
print(ec.__version__) # 1.0.
|
|
1282
|
+
print(ec.__version__) # 1.0.1
|
|
1268
1283
|
\end{lstlisting}
|
|
1269
1284
|
|
|
1270
1285
|
\end{document}
|
|
Binary file
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
\vspace*{3cm}
|
|
167
167
|
{\Huge\bfseries\color{tblhead} econcomplex}\par
|
|
168
168
|
\vspace{0.5cm}
|
|
169
|
-
{\large\bfseries Documenta\c{c}\~{a}o T\'{e}cnica --- Vers\~{a}o 1.0.
|
|
169
|
+
{\large\bfseries Documenta\c{c}\~{a}o T\'{e}cnica --- Vers\~{a}o 1.0.1}\par
|
|
170
170
|
\vspace{1cm}
|
|
171
171
|
\rule{10cm}{0.8pt}\par
|
|
172
172
|
\vspace{0.8cm}
|
|
@@ -506,7 +506,7 @@ import sys
|
|
|
506
506
|
sys.path.insert(0, "/caminho/para/econcomplex")
|
|
507
507
|
|
|
508
508
|
import econcomplex as ec
|
|
509
|
-
print(ec.__version__) # 1.0.
|
|
509
|
+
print(ec.__version__) # 1.0.1
|
|
510
510
|
\end{lstlisting}
|
|
511
511
|
|
|
512
512
|
% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
@@ -969,6 +969,8 @@ def compute_complexity(
|
|
|
969
969
|
proximity_method: str = "max", # 'max' | 'sqrt' | 'min'
|
|
970
970
|
pop: pd.DataFrame | None = None, # populacao (para 'rpop'/'both')
|
|
971
971
|
compute_coi_cog: bool = True,
|
|
972
|
+
trim: bool = True, # poda unidades degeneradas
|
|
973
|
+
dmin: int = 1, umin: int = 1, # nucleo (use 2,2 se esparso)
|
|
972
974
|
time_col: str | None = None,
|
|
973
975
|
) -> pd.DataFrame:
|
|
974
976
|
"""
|
|
@@ -978,6 +980,17 @@ def compute_complexity(
|
|
|
978
980
|
"""
|
|
979
981
|
\end{lstlisting}
|
|
980
982
|
|
|
983
|
+
\begin{notebox}
|
|
984
|
+
\texttt{compute\_complexity} \'{e} uma fina \textbf{camada de
|
|
985
|
+
orquestra\c{c}\~{a}o}: chama as mesmas fun\c{c}\~{o}es p\'{u}blicas que
|
|
986
|
+
voc\^{e} chamaria na m\~{a}o (\fn{rca}, \fn{mcp}, \fn{diversity},
|
|
987
|
+
\fn{ubiquity}, \fn{eci\_pci}, \fn{proximity}, \fn{relatedness\_density},
|
|
988
|
+
\fn{distance}, \fn{coi}/\fn{cog}) e remonta o resultado em formato
|
|
989
|
+
longo, iterando por per\'{i}odo em pain\'{e}is. \'{E} a porta de entrada
|
|
990
|
+
para o caso comum; para controle fino, use as fun\c{c}\~{o}es de matriz
|
|
991
|
+
diretamente.
|
|
992
|
+
\end{notebox}
|
|
993
|
+
|
|
981
994
|
\subsection{Par\^{a}metros}
|
|
982
995
|
|
|
983
996
|
\begin{center}
|
|
@@ -996,6 +1009,8 @@ def compute_complexity(
|
|
|
996
1009
|
\texttt{proximity\_method} & \texttt{str} & Normaliza\c{c}\~{a}o da proximidade \\
|
|
997
1010
|
\texttt{pop} & \texttt{DataFrame} & Popula\c{c}\~{a}o, obrigat\'{o}ria para RPOP \\
|
|
998
1011
|
\texttt{compute\_coi\_cog} & \texttt{bool} & Calcular COI e COG (mais lento) \\
|
|
1012
|
+
\texttt{trim} & \texttt{bool} & Poda unidades degeneradas (padr\~{a}o: True) \\
|
|
1013
|
+
\texttt{dmin}, \texttt{umin} & \texttt{int} & Limiares do n\'{u}cleo repassados a \fn{eci\_pci}; use 2 para dados esparsos \\
|
|
999
1014
|
\bottomrule
|
|
1000
1015
|
\end{tabular}
|
|
1001
1016
|
\end{center}
|
|
@@ -1003,7 +1018,8 @@ def compute_complexity(
|
|
|
1003
1018
|
\begin{notebox}
|
|
1004
1019
|
Unidades degeneradas (diversidade ou ubiquidade zero) s\~{a}o removidas
|
|
1005
1020
|
automaticamente na etapa de complexidade e retornadas como
|
|
1006
|
-
\texttt{NaN} (ver \fn{trim\_core}).
|
|
1021
|
+
\texttt{NaN} (ver \fn{trim\_core}). Para dados subnacionais esparsos,
|
|
1022
|
+
passe \texttt{dmin=2, umin=2} para restringir ao n\'{u}cleo conectado.
|
|
1007
1023
|
\end{notebox}
|
|
1008
1024
|
|
|
1009
1025
|
%% ============================================================
|
|
@@ -1276,7 +1292,7 @@ originais dos indicadores utilizados (ver Refer\^{e}ncias).
|
|
|
1276
1292
|
|
|
1277
1293
|
\begin{lstlisting}[language={}, caption={Verificar vers\~{a}o da biblioteca}]
|
|
1278
1294
|
import econcomplex as ec
|
|
1279
|
-
print(ec.__version__) # 1.0.
|
|
1295
|
+
print(ec.__version__) # 1.0.1
|
|
1280
1296
|
\end{lstlisting}
|
|
1281
1297
|
|
|
1282
1298
|
\end{document}
|
|
@@ -55,7 +55,7 @@ the same objects as their canonical functions (see the API map in the
|
|
|
55
55
|
documentation).
|
|
56
56
|
"""
|
|
57
57
|
|
|
58
|
-
__version__ = "1.0.
|
|
58
|
+
__version__ = "1.0.1"
|
|
59
59
|
__author__ = "Elton Freitas and contributors"
|
|
60
60
|
|
|
61
61
|
# ── Core ──────────────────────────────────────────────────────────────────────
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"""
|
|
2
2
|
High-level pipeline: compute all complexity indicators in one call.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
This is a *thin orchestration layer* over the public functions of the
|
|
5
|
+
library — it does not reimplement any indicator. It only (i) pivots the
|
|
6
|
+
long-format input to a matrix, (ii) calls the same public functions a
|
|
7
|
+
user would call by hand (``rca``, ``mcp``, ``diversity``, ``ubiquity``,
|
|
8
|
+
``eci_pci``, ``proximity``, ``relatedness_density``, ``distance``,
|
|
9
|
+
``coi``/``cog``), (iii) loops over periods for panel data, and (iv)
|
|
10
|
+
merges the results back into long format.
|
|
11
|
+
|
|
12
|
+
It is the convenience entry point for the common case and for panels;
|
|
13
|
+
for fine-grained control (e.g. proximity normalisation per side, custom
|
|
14
|
+
continuous methods) call the matrix-level functions directly.
|
|
15
|
+
|
|
16
|
+
Mirrors the spirit of py-ecomplexity's pipeline.
|
|
6
17
|
"""
|
|
7
18
|
|
|
8
19
|
from __future__ import annotations
|
|
@@ -13,9 +24,10 @@ import numpy as np
|
|
|
13
24
|
import pandas as pd
|
|
14
25
|
|
|
15
26
|
from .core.rca import rca, mcp
|
|
27
|
+
from .core.diversity import diversity as compute_diversity, ubiquity as compute_ubiquity
|
|
16
28
|
from .complexity.eci_pci import eci_pci
|
|
17
29
|
from .relatedness.proximity import proximity, continuous_proximity
|
|
18
|
-
from .relatedness.density import relatedness_density
|
|
30
|
+
from .relatedness.density import relatedness_density, distance as compute_distance
|
|
19
31
|
from .outlook.coi_cog import complexity_outlook_index, complexity_outlook_gain
|
|
20
32
|
from .core.utils import pivot_to_matrix
|
|
21
33
|
|
|
@@ -32,6 +44,9 @@ def compute_complexity(
|
|
|
32
44
|
proximity_method: Literal["max", "sqrt", "min"] = "max",
|
|
33
45
|
pop: Optional[pd.DataFrame] = None,
|
|
34
46
|
compute_coi_cog: bool = True,
|
|
47
|
+
trim: bool = True,
|
|
48
|
+
dmin: int = 1,
|
|
49
|
+
umin: int = 1,
|
|
35
50
|
time_col: Optional[str] = None,
|
|
36
51
|
) -> pd.DataFrame:
|
|
37
52
|
"""
|
|
@@ -65,6 +80,13 @@ def compute_complexity(
|
|
|
65
80
|
Required when presence_test is 'rpop' or 'both'.
|
|
66
81
|
compute_coi_cog : bool
|
|
67
82
|
Whether to compute COI and COG (slower).
|
|
83
|
+
trim : bool
|
|
84
|
+
Pre-trim degenerate units before the ECI/PCI step (passed to
|
|
85
|
+
``eci_pci``); trimmed units get NaN ECI/PCI. Default True.
|
|
86
|
+
dmin, umin : int
|
|
87
|
+
Diversity/ubiquity thresholds for the trimming (passed to
|
|
88
|
+
``eci_pci`` → ``trim_core``). Default 1; use 2 for the
|
|
89
|
+
well-connected core recommended for sparse subnational data.
|
|
68
90
|
time_col : str, optional
|
|
69
91
|
Override for time column name (or use cols['time']).
|
|
70
92
|
|
|
@@ -103,6 +125,7 @@ def compute_complexity(
|
|
|
103
125
|
proximity_method=proximity_method,
|
|
104
126
|
pop=pop_period,
|
|
105
127
|
compute_coi_cog=compute_coi_cog,
|
|
128
|
+
trim=trim, dmin=dmin, umin=umin,
|
|
106
129
|
)
|
|
107
130
|
results.append(period_result)
|
|
108
131
|
return pd.concat(results, ignore_index=True)
|
|
@@ -117,6 +140,7 @@ def compute_complexity(
|
|
|
117
140
|
proximity_method=proximity_method,
|
|
118
141
|
pop=pop,
|
|
119
142
|
compute_coi_cog=compute_coi_cog,
|
|
143
|
+
trim=trim, dmin=dmin, umin=umin,
|
|
120
144
|
)
|
|
121
145
|
|
|
122
146
|
|
|
@@ -134,8 +158,11 @@ def _compute_single_period(
|
|
|
134
158
|
proximity_method: str,
|
|
135
159
|
pop: Optional[pd.DataFrame],
|
|
136
160
|
compute_coi_cog: bool,
|
|
161
|
+
trim: bool,
|
|
162
|
+
dmin: int,
|
|
163
|
+
umin: int,
|
|
137
164
|
) -> pd.DataFrame:
|
|
138
|
-
"""Compute indicators for a single time period."""
|
|
165
|
+
"""Compute indicators for a single time period (pure orchestration)."""
|
|
139
166
|
|
|
140
167
|
# --- Build pivot matrix ---
|
|
141
168
|
mat = pivot_to_matrix(data, index=loc_col, columns=act_col, values=val_col)
|
|
@@ -159,9 +186,9 @@ def _compute_single_period(
|
|
|
159
186
|
pop=pop_vec,
|
|
160
187
|
)
|
|
161
188
|
|
|
162
|
-
# --- Diversity & Ubiquity ---
|
|
163
|
-
div = mcp_mat.
|
|
164
|
-
ubi = mcp_mat
|
|
189
|
+
# --- Diversity & Ubiquity (on the chosen Mcp, via the public funcs) ---
|
|
190
|
+
div = compute_diversity(mcp_mat, use_rca=False, threshold=0.5)
|
|
191
|
+
ubi = compute_ubiquity(mcp_mat, use_rca=False, threshold=0.5)
|
|
165
192
|
|
|
166
193
|
# --- ECI / PCI ---
|
|
167
194
|
# Routed through the eci_pci dispatcher: validates the method and
|
|
@@ -169,6 +196,7 @@ def _compute_single_period(
|
|
|
169
196
|
eci_s, pci_s = eci_pci(
|
|
170
197
|
mat, use_rca=True, threshold=threshold, method=method,
|
|
171
198
|
iterations=iterations if method != "eigenvector" else None,
|
|
199
|
+
trim=trim, dmin=dmin, umin=umin,
|
|
172
200
|
)
|
|
173
201
|
if method == "fitness":
|
|
174
202
|
eci_s.name = "eci"
|
|
@@ -182,9 +210,9 @@ def _compute_single_period(
|
|
|
182
210
|
method=proximity_method, compute="product")
|
|
183
211
|
phi = phi_dict["product"]
|
|
184
212
|
|
|
185
|
-
# --- Density & Distance ---
|
|
213
|
+
# --- Density & Distance (public functions on the chosen Mcp) ---
|
|
186
214
|
dens_mat = relatedness_density(mcp_mat, phi=phi, use_rca=False, threshold=0.5)
|
|
187
|
-
dist_mat =
|
|
215
|
+
dist_mat = compute_distance(mcp_mat, phi=phi, use_rca=False, threshold=0.5)
|
|
188
216
|
|
|
189
217
|
# --- COI / COG (optional) ---
|
|
190
218
|
coi_s = None
|
|
@@ -512,3 +512,46 @@ def test_fitness_default_iterations_match_dispatcher(sample_mat):
|
|
|
512
512
|
def test_fitness_warns_when_not_converged(sample_mat):
|
|
513
513
|
with pytest.warns(RuntimeWarning, match="did not converge"):
|
|
514
514
|
ec.fitness_complexity(sample_mat, iterations=1, tol=1e-15)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
# ── Pipeline is pure orchestration of the public functions ────────────────────
|
|
518
|
+
def test_pipeline_matches_manual_indicators(sample_long):
|
|
519
|
+
"""Each column the pipeline returns must equal the value obtained by
|
|
520
|
+
calling the public functions by hand on the same matrix."""
|
|
521
|
+
res = ec.compute_complexity(
|
|
522
|
+
sample_long, cols={"loc": "region", "act": "activity", "val": "employment"},
|
|
523
|
+
compute_coi_cog=True,
|
|
524
|
+
)
|
|
525
|
+
mat = ec.pivot_to_matrix(sample_long, "region", "activity", "employment")
|
|
526
|
+
mcp = ec.mcp(mat)
|
|
527
|
+
eci, pci = ec.eci_pci(mat)
|
|
528
|
+
phi = ec.proximity(mcp, use_rca=False, threshold=0.5)["product"]
|
|
529
|
+
|
|
530
|
+
div = ec.diversity(mcp, use_rca=False, threshold=0.5)
|
|
531
|
+
dens = ec.density(mcp, phi=phi, use_rca=False, threshold=0.5)
|
|
532
|
+
dist = ec.distance(mcp, phi=phi, use_rca=False, threshold=0.5)
|
|
533
|
+
|
|
534
|
+
# one (region, activity) cell and one region-level value
|
|
535
|
+
row = res.iloc[0]
|
|
536
|
+
r, a = row["region"], row["activity"]
|
|
537
|
+
assert np.isclose(row["eci"], eci[r], equal_nan=True)
|
|
538
|
+
assert np.isclose(row["diversity"], div[r])
|
|
539
|
+
assert np.isclose(row["density"], dens.loc[r, a])
|
|
540
|
+
assert np.isclose(row["distance"], dist.loc[r, a])
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
def test_pipeline_passes_trim_params():
|
|
544
|
+
"""dmin/umin must reach eci_pci through the pipeline (was impossible
|
|
545
|
+
before 1.0.1): the (2,2) core trims at least as many units as (1,1)."""
|
|
546
|
+
long = ec.make_sample_data(n_locs=40, n_acts=25, seed=11)
|
|
547
|
+
strict = ec.compute_complexity(
|
|
548
|
+
long, cols={"loc": "loc", "act": "act", "val": "val"},
|
|
549
|
+
compute_coi_cog=False, dmin=2, umin=2,
|
|
550
|
+
)
|
|
551
|
+
loose = ec.compute_complexity(
|
|
552
|
+
long, cols={"loc": "loc", "act": "act", "val": "val"},
|
|
553
|
+
compute_coi_cog=False,
|
|
554
|
+
)
|
|
555
|
+
n_nan_strict = strict.drop_duplicates("loc")["eci"].isna().sum()
|
|
556
|
+
n_nan_loose = loose.drop_duplicates("loc")["eci"].isna().sum()
|
|
557
|
+
assert n_nan_strict >= n_nan_loose # stricter core trims at least as much
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|