From d177e880a9290a3a5ff26d61be1284b16a582683 Mon Sep 17 00:00:00 2001 From: Kajwan Date: Wed, 16 Jul 2025 17:57:16 +0200 Subject: [PATCH 1/7] Ensuring Ghosh implementation mirrors Leontief implementation [WIP] --- pymrio/core/mriosystem.py | 26 ++++----- pymrio/tools/iomath.py | 23 ++++---- tests/test_integration.py | 110 +++++++++++++++++++------------------- tests/test_math.py | 30 +++++++---- 4 files changed, 100 insertions(+), 89 deletions(-) diff --git a/pymrio/core/mriosystem.py b/pymrio/core/mriosystem.py index 4929dc20..bbc4b816 100644 --- a/pymrio/core/mriosystem.py +++ b/pymrio/core/mriosystem.py @@ -40,7 +40,7 @@ calc_gross_trade, calc_L, calc_M, - calc_M_down, + calc_M_Ghosh, calc_S, calc_S_Y, calc_x, @@ -876,9 +876,9 @@ class Extension(_BaseSystem): S_Y : pandas.DataFrame Direct impact (extensions) coefficients of final demand. Index as F_Y M : pandas.DataFrame - Multipliers with multiindex as F - M_down : pandas.DataFrame - Downstream multipliers with multiindex as F + Leontief multipliers with multiindex as F + M_Ghosh : pandas.DataFrame + Ghosh multipliers with multiindex as F D_cba : pandas.DataFrame Footprint of consumption, further specification with _reg (per region) or _cap (per capita) possible @@ -917,7 +917,7 @@ def __init__( S=None, S_Y=None, M=None, - M_down=None, + M_Ghosh=None, D_cba=None, D_pba=None, D_imp=None, @@ -932,7 +932,7 @@ def __init__( self.S = S self.S_Y = S_Y self.M = M - self.M_down = M_down + self.M_Ghosh = M_Ghosh self.D_cba = D_cba self.D_pba = D_pba self.D_imp = D_imp @@ -975,7 +975,7 @@ def __init__( "D_exp_cap", ] - self.__coefficients__ = ["S", "S_Y", "M"] + self.__coefficients__ = ["S", "S_Y", "M", "M_Ghosh"] # check if all accounts are available for acc in self.__D_accounts__: @@ -996,7 +996,7 @@ def calc_system(self, x, Y, Y_agg=None, L=None, G=None, population=None): Calculates: - for each sector and country: - S, S_Y (if F_Y available), M, M_down, + S, S_Y (if F_Y available), M, M_Ghosh, D_cba, - for each region: D_cba_reg, D_pba_reg, D_imp_reg, D_exp_reg, @@ -1024,7 +1024,7 @@ def calc_system(self, x, Y, Y_agg=None, L=None, G=None, population=None): the extension). G : pandas.DataFrame or numpy.array, optional Ghosh input output table G. If this is not given, - M_down is not calculated. + M_Ghosh is not calculated. population : pandas.DataFrame or np.array, optional Row vector with population per region """ @@ -1073,12 +1073,12 @@ def calc_system(self, x, Y, Y_agg=None, L=None, G=None, population=None): except Exception as ex: logging.debug(f"Recalculation of M not possible - cause: {ex}") - if self.M_down is None: + if self.M_Ghosh is None: if G is not None: - self.M_down = calc_M_down(self.S, G) - logging.debug(f"{self.name} - M_down calculated based on G") + self.M_Ghosh = calc_M_Ghosh(self.S, G) + logging.debug(f"{self.name} - M_Ghosh calculated based on G") else: - logging.debug("Calculation of M_down not possible because G is not available.") + logging.debug("Calculation of M_Ghosh not possible because G is not available.") F_Y_agg = 0 if self.F_Y is not None: diff --git a/pymrio/tools/iomath.py b/pymrio/tools/iomath.py index 4b2542e4..80efa6a2 100644 --- a/pymrio/tools/iomath.py +++ b/pymrio/tools/iomath.py @@ -113,7 +113,8 @@ def calc_Z(A, x): def calc_A(Z, x): """Calculate the A matrix (coefficients) from Z and x. - A is a normalized version of the industrial flows Z + A is a normalized version of the industrial flows Z. + Also known as direct input coefficients. Parameters ---------- @@ -154,8 +155,8 @@ def calc_B(Z, x): """Calculate the B matrix (coefficients) from Z and x. B is a normalized version of the industrial flows of the - transpose of Z, which quantifies the input to downstream - sectors. + transpose of Z. + Also known as direct output coefficients. Parameters ---------- @@ -237,7 +238,7 @@ def calc_G(B, L=None, x=None): Either from B (high computation effort) or from Leontief matrix L and x (low computation effort). - G = inverse matrix of (I - B) = hat(x) * L * hat(x)^{-1} + G = inverse matrix of (I - B) = hat(x)^{-1} * L * hat(x) where I is an identity matrix of same shape as B, and hat(x) is the diagonal matrix with values of x on the diagonal. @@ -396,7 +397,7 @@ def calc_F_Y(S_Y, y): def calc_M(S, L): - """Calculate multipliers of the extensions. + """Calculate Leontief multipliers of the extensions. Parameters ---------- @@ -408,7 +409,7 @@ def calc_M(S, L): Returns ------- pandas.DataFrame or numpy.array - Multipliers M + Leontief multipliers M for the extensions. The type is determined by the type of S. If DataFrame index/columns as S @@ -416,10 +417,10 @@ def calc_M(S, L): return S.dot(L) -def calc_M_down(S, G): - """Calculate downstream multipliers of the extensions. +def calc_M_Ghosh(S, G): + """Calculate Ghosh multipliers of the extensions. - M_down = S * ( G^T - I ) + M_Ghosh = G S Where I is an identity matrix of same shape as G @@ -433,12 +434,12 @@ def calc_M_down(S, G): Returns ------- pandas.DataFrame or numpy.array - Downstream multipliers M + Ghosh multipliers M_Ghosh for the extensions. The type is determined by the type of S. If DataFrame index/columns as S """ - return S.dot(np.transpose(G) - np.eye(G.shape[0])) + return G.dot(S.T) def calc_e(M, Y): diff --git a/tests/test_integration.py b/tests/test_integration.py index e127016b..0e90ad18 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -7,7 +7,7 @@ Might be the slowest test to run - make optional if it takes to long. """ - +# %% import os import sys @@ -97,58 +97,56 @@ class factor_inputs: ] ] ) - M_down_values = np.array( + M_Ghosh_values = np.array( [ - [ - 5.63682037e-02, - 1.58826114e-01, - 2.77181617e-04, - 1.24260752e-01, - 4.73781802e-04, - 1.47221885e-04, - 5.08842766e-04, - 8.27157324e-04, - 2.58260444e-05, - 1.40935038e-01, - 7.28719271e-05, - 5.55187475e-05, - 1.31414529e-04, - 7.63356055e-05, - 3.93032602e-04, - 1.59470188e-04, - 5.44620512e-05, - 1.92986549e-03, - 6.09150229e-04, - 8.16103355e-02, - 3.49016453e-03, - 2.79285723e-03, - 3.85380897e-03, - 1.23089234e-02, - 5.14123958e-04, - 6.05570091e-02, - 7.60911713e-04, - 3.07985491e-04, - 3.42198855e-03, - 4.20922429e-04, - 2.13360046e-04, - 4.40940379e-04, - 8.09987164e-02, - 6.75547762e-02, - 7.37546870e-04, - 3.23573339e-04, - 4.90632930e-02, - 3.56147875e-04, - 3.02290799e-03, - 9.35063455e-04, - 1.90276590e-04, - 1.87421503e-01, - 4.46892122e-04, - 7.31872326e-02, - 3.39365262e-03, - 7.98904286e-04, - 7.76958438e-04, - 4.99082254e-04, - ] + [0.5225561 ], + [0.65756216], + [0.00473417], + [0.5472355 ], + [0.01772519], + [0.00568822], + [0.00922866], + [0.03440748], + [0.00188181], + [0.75013998], + [0.00203768], + [0.00142178], + [0.01295829], + [0.00541751], + [0.01268766], + [0.01271283], + [0.00210632], + [0.00713347], + [0.0071196 ], + [0.58120523], + [0.06218467], + [0.06532605], + [0.04001635], + [0.17603932], + [0.02800893], + [0.49852299], + [0.00523151], + [0.00280954], + [0.32052008], + [0.00749766], + [0.00255429], + [0.01555917], + [0.57612848], + [0.69293328], + [0.00493526], + [0.00260152], + [0.49634848], + [0.00515573], + [0.03258598], + [0.02620705], + [0.00806297], + [0.86794689], + [0.00481975], + [0.64359805], + [0.15009733], + [0.05766786], + [0.00976597], + [0.01817829] ] ) @@ -190,7 +188,7 @@ def test_all_wo_ghosh(td_testmrio): assert all(mr_nog.emissions.get_regions() == sat_new.get_regions()) assert all(mr_nog.emissions.get_sectors() == sat_new.get_sectors()) assert "M" in sat_new.get_DataFrame() - assert "M_down" not in sat_new.get_DataFrame() + assert "M_Ghosh" not in sat_new.get_DataFrame() def test_all_with_ghosh(td_testmrio): @@ -220,8 +218,8 @@ def test_all_with_ghosh(td_testmrio): rtol=1e-5, ) npt.assert_allclose( - td_testmrio.factor_inputs.M_down_values, - mr_wig.factor_inputs.M_down.values, + td_testmrio.factor_inputs.M_Ghosh_values, + mr_wig.factor_inputs.M_Ghosh.values, rtol=1e-5, ) @@ -233,7 +231,7 @@ def test_all_with_ghosh(td_testmrio): assert all(mr_wig.emissions.get_regions() == sat_new.get_regions()) assert all(mr_wig.emissions.get_sectors() == sat_new.get_sectors()) assert "M" in sat_new.get_DataFrame() - assert "M_down" in sat_new.get_DataFrame() + assert "M_Ghosh" in sat_new.get_DataFrame() def test_txt_zip_fileio(tmpdir): diff --git a/tests/test_math.py b/tests/test_math.py index 5f7b1689..039fa157 100644 --- a/tests/test_math.py +++ b/tests/test_math.py @@ -1,5 +1,5 @@ """test cases for all mathematical functions.""" - +# %% import os import sys @@ -24,14 +24,14 @@ from pymrio.tools.iomath import calc_gross_trade # noqa from pymrio.tools.iomath import calc_L # noqa from pymrio.tools.iomath import calc_M # noqa -from pymrio.tools.iomath import calc_M_down # noqa +from pymrio.tools.iomath import calc_M_Ghosh # noqa from pymrio.tools.iomath import calc_S # noqa from pymrio.tools.iomath import calc_S_Y # noqa from pymrio.tools.iomath import calc_x # noqa from pymrio.tools.iomath import calc_x_from_L # noqa from pymrio.tools.iomath import calc_Z # noqa - +# %% # test data @pytest.fixture() def td_IO_Data_Miller(): @@ -116,7 +116,6 @@ class IO_Data_Miller: return IO_Data_Miller - @pytest.fixture() def td_small_MRIO(): """Small MRIO with three sectors and two regions. @@ -428,7 +427,20 @@ class IO_Data: columns=_Z_multiindex, ) - M_down = pd.DataFrame( + M_Ghosh = pd.DataFrame( + data=( + [[0.87388465, 0.36636797], + [0.55666652, 0.52391329], + [1.473585 , 0.4772512 ], + [0.46438353, 0.3465165 ], + [0.86492491, 0.25702995], + [0.63734675, 0.50857434]] + ), # noqa + columns=["ext_type_1", "ext_type_2"], + index=_Z_multiindex, + ) + + M_Ghosh_down = pd.DataFrame( data=[ [ 0.48172779, @@ -449,7 +461,7 @@ class IO_Data: ], index=["ext_type_1", "ext_type_2"], columns=_Z_multiindex, - ) + ).T D_cba = pd.DataFrame( data=[ @@ -705,9 +717,9 @@ def test_calc_M_MRIO(td_small_MRIO): pdt.assert_frame_equal(td_small_MRIO.M, calc_M(td_small_MRIO.S, td_small_MRIO.L)) -def test_calc_M_down_MRIO(td_small_MRIO): - """Test calculation of M_down (Gosh-based) matrix in MRIO model.""" - pdt.assert_frame_equal(td_small_MRIO.M_down, calc_M_down(td_small_MRIO.S, td_small_MRIO.G)) +def test_calc_M_Ghosh_MRIO(td_small_MRIO): + """Test calculation of M_Ghosh (Ghosh-based) matrix in MRIO model.""" + pdt.assert_frame_equal(td_small_MRIO.M_Ghosh, calc_M_Ghosh(td_small_MRIO.S, td_small_MRIO.G)) def test_calc_gross_trade_MRIO(td_small_MRIO): From 017037cc97aa884bc861b5b5b677c17f227ec09c Mon Sep 17 00:00:00 2001 From: Kajwan Date: Wed, 16 Jul 2025 18:04:21 +0200 Subject: [PATCH 2/7] Tidiying up --- doc/source/api_doc/pymrio.calc_M_Ghosh.rst | 6 ++++++ doc/source/api_doc/pymrio.calc_M_down.rst | 6 ------ doc/source/api_references.rst | 2 +- doc/source/notebooks/full_tutorial.py | 4 ++-- pymrio/__init__.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 doc/source/api_doc/pymrio.calc_M_Ghosh.rst delete mode 100644 doc/source/api_doc/pymrio.calc_M_down.rst diff --git a/doc/source/api_doc/pymrio.calc_M_Ghosh.rst b/doc/source/api_doc/pymrio.calc_M_Ghosh.rst new file mode 100644 index 00000000..987df633 --- /dev/null +++ b/doc/source/api_doc/pymrio.calc_M_Ghosh.rst @@ -0,0 +1,6 @@ +pymrio.calc\_M\_Ghosh +==================== + +.. currentmodule:: pymrio + +.. autofunction:: calc_M_Ghosh \ No newline at end of file diff --git a/doc/source/api_doc/pymrio.calc_M_down.rst b/doc/source/api_doc/pymrio.calc_M_down.rst deleted file mode 100644 index ce649bf8..00000000 --- a/doc/source/api_doc/pymrio.calc_M_down.rst +++ /dev/null @@ -1,6 +0,0 @@ -pymrio.calc\_M\_down -==================== - -.. currentmodule:: pymrio - -.. autofunction:: calc_M_down \ No newline at end of file diff --git a/doc/source/api_references.rst b/doc/source/api_references.rst index 06b3813c..3e71f086 100644 --- a/doc/source/api_references.rst +++ b/doc/source/api_references.rst @@ -189,7 +189,7 @@ numpy array. calc_S calc_F calc_M - calc_M_down + calc_M_Ghosh calc_e calc_accounts diff --git a/doc/source/notebooks/full_tutorial.py b/doc/source/notebooks/full_tutorial.py index c68e2440..4d98f661 100644 --- a/doc/source/notebooks/full_tutorial.py +++ b/doc/source/notebooks/full_tutorial.py @@ -137,10 +137,10 @@ print(test_mrio) # %% [markdown] -# This also calculates downstream multipliers M_down +# This also calculates Ghosh multipliers M_Ghosh # %% -test_mrio.emissions.M_down +test_mrio.emissions.M_Ghosh # %% [markdown] # See the [math section](../math.rst) of the documentation for further details on the Ghosh calculations. diff --git a/pymrio/__init__.py b/pymrio/__init__.py index 32a28ba3..86c11489 100644 --- a/pymrio/__init__.py +++ b/pymrio/__init__.py @@ -57,7 +57,7 @@ calc_gross_trade, calc_L, calc_M, - calc_M_down, + calc_M_Ghosh, calc_S, calc_S_Y, calc_x, @@ -134,7 +134,7 @@ "calc_gross_trade", "calc_L", "calc_M", - "calc_M_down", + "calc_M_Ghosh", "calc_S", "calc_S_Y", "calc_x", From 8d2fd855e36110906c6b274dc9c280050050e370 Mon Sep 17 00:00:00 2001 From: Kajwan Date: Wed, 16 Jul 2025 18:08:24 +0200 Subject: [PATCH 3/7] Updated documentation [WIP] --- doc/source/math.rst | 159 +++++++++++++++++++++++++++++-------- doc/source/terminology.rst | 18 ++++- 2 files changed, 142 insertions(+), 35 deletions(-) diff --git a/doc/source/math.rst b/doc/source/math.rst index a2c6f69b..d945fd30 100644 --- a/doc/source/math.rst +++ b/doc/source/math.rst @@ -14,7 +14,10 @@ was available for a specific operation, resulting in a substantial speed up of t In these cases the original formula remains as comment in the source code. Basic MRIO calculations ------------------------- +======================= + +Core tables +------------ MRIO tables describe the global inter-industries flows within and across countries for :math:`k` countries with a transaction matrix :math:`Z`: @@ -31,9 +34,11 @@ MRIO tables describe the global inter-industries flows within and across countri \end{equation} Each submatrix on the main diagonal (:math:`Z_{i,i}`) represents the domestic -interactions for each industry :math:`n`. The off diagonal matrices (:math:`Z_{i,j}`) +interactions for each sector :math:`n`. The off diagonal matrices (:math:`Z_{i,j}`) describe the trade from region :math:`i` to region :math:`j` (with :math:`i, j = 1, \ldots, k`) -for each industry. Accordingly, global final demand can be represented by +for each sector. + +Global final demand can be represented by .. math:: @@ -48,44 +53,43 @@ for each industry. Accordingly, global final demand can be represented by \end{equation} with final demand satisfied by domestic production in the main diagonal -(:math:`Y_{i,i}`) and direct import to final demand from country :math:`i` to :math:`j` by +(:math:`Y_{i,i}`) and direct import to final demand from region :math:`i` to :math:`j` by :math:`Y_{i,j}`. -The global economy can thus be described by: +Similarly, the global value-added (primary inputs) can be represented by .. math:: - + \begin{equation} - x = Ze + Ye + v = + \begin{pmatrix} + V_{1} & V_{2} & \cdots & V_{k} \\ + \end{pmatrix} \end{equation} -with :math:`e` representing the summation vector (column vector with 1's of -appropriate dimension) and :math:`x` the total industry output. +with the value-added for each region :math:`i` as :math:`V_i` (with :math:`i = 1, \ldots, k`). -The direct requirement matrix :math:`A` is given by multiplication of :math:`Z` with the -diagonalised and inverted industry output :math:`x`: + +The global economy can thus be described by either: .. math:: \begin{equation} - A = Z\hat{x}^{-1} + x = Ze + Ye \end{equation} -Based on the linear economy assumption of the IO model and -the classic Leontief_ demand-style modeling -(see `Leontief 1970 `_), -total industry output :math:`x` can be calculated for any arbitrary vector of -final demand :math:`y` by multiplying with the total requirement matrix (Leontief matrix) :math:`L`. - -.. _Leontief: https://en.wikipedia.org/wiki/Wassily_Leontief +or equivalently .. math:: \begin{equation} - x = (\mathrm{I}- A)^{-1}y = Ly + x' = e'Z + v' \end{equation} -with :math:`\mathrm{I}` defined as the identity matrix with the size of :math:`A`. +with :math:`e` representing the summation vector (column vector with 1's of +appropriate dimension), and the :math:`'` indicating the transpose matrix, +and :math:`x` the total industry input/output (which are necessarily equal). + The global multi regional IO system can be extended with various factors of production :math:`f_{h,i}`. These can represent among others value added, employment @@ -112,8 +116,44 @@ with the factor of production coefficients :math:`S` given by S = F\hat{x}^{-1} \end{equation} +If the factor of production represent required environmental impacts, these can +also occur during the final use phase. In that case :math:`F_Y` describe the impacts +associated with final demand (e.g. household emissions). + -Multipliers (total, direct and indirect, requirement factors for one unit of output) are then obtained by +Leontief demand model +--------------------- + +The Leontief demand model assumes that final demand drives economic production and environmental impacts. + +To derive the model, one must first calculate the direct input requirement matrix :math:`A`. +It is given by multiplication of :math:`Z` with the +diagonalised and inverted industry output :math:`x`: + +.. math:: + + \begin{equation} + A = Z\hat{x}^{-1} + \end{equation} + +Based on the linear economy assumption of the IO model and +the classic Leontief_ demand-style modeling +(see `Leontief 1970 `_), +total industry output :math:`x` can be calculated for any arbitrary vector of +final demand :math:`y` by multiplying with the total requirement matrix (Leontief matrix) :math:`L`. + +.. _Leontief: https://en.wikipedia.org/wiki/Wassily_Leontief + +.. math:: + + \begin{equation} + x = (\mathrm{I}- A)^{-1}y = Ly + \end{equation} + +with :math:`\mathrm{I}` defined as the identity matrix with the size of :math:`A`. + + +Leontief multipliers (total direct and indirect output needed in each sector to satisfy one unit of final demand) are then obtained by .. math:: @@ -121,8 +161,8 @@ Multipliers (total, direct and indirect, requirement factors for one unit of out M = SL \end{equation} -Total requirements (footprints in case of environmental requirements) for any -given final demand vector :math:`y` are then given by +Total requirements (footprints in case of environmental requirements) +for any given final demand vector :math:`y` are then given by .. math:: @@ -151,11 +191,57 @@ other countries is given by: with the hat indicating diagonalization of the resulting column-vector of the term underneath. -If the factor of production represent required environmental impacts, these can -also occur during the final use phase. In that case :math:`F_Y` describe the impacts -associated with final demand (e.g. household emissions). -These need to be added to the total production- and consumption-based accounts to obtain the total impacts per country. +Ghosh supply model +--------------------- + +The Ghosh supply model assumes that primary inputs (value-added) drives economic production and environmental impacts. +See `Ghosh Model `_ for more information. + +To derive the model, one must first calculate the direct output requirement matrix :math:`B`. +It is given by multiplication of the diagonalised +and inverted industry output :math:`x`: with :math:`Z` + +.. math:: + + \begin{equation} + B = \hat{x}^{-1} Z + \end{equation} + + +Similarly, the Ghosh inverse matrix :math:`G` is defined as the inverse of the identity matrix minus the output requirement matrix :math:`B` + +.. math:: + + \begin{equation} + G = (\mathrm{I}- B)^{-1} = \hat{x} L \hat{x}^{-1} + \end{equation} + +with :math:`\mathrm{I}` defined as the identity matrix with the size of :math:`B`. + +Ghosh multipliers (total direct and indirect outputs generated in response to one unit of value-added supplied to a sector) are then obtained by + +.. math:: + + \begin{equation} + M_{Ghosh} = G S + \end{equation} + + +Total direct and indirect outputs generated for any value-added vector :math:`v` are then given by + +.. math:: + + \begin{equation} + D_{iba} = v M_{Ghosh} + \end{equation} + + + + +Production-, Consumption-, and Income-based accounting +====================================================== + Production-based accounts (direct territorial requirements) per region `i` are therefore given by summing over the stressors per sector (0 ... `m`) plus the stressors occurring due to the final consumption for all final demand categories (0 ... `w`) of that region. @@ -165,7 +251,8 @@ plus the stressors occurring due to the final consumption for all final demand c D_{pba}^i = \sum_{s=0}^m F^i_s + \sum_{c=0}^w F^i_{Yc} \end{equation} -Similarly, total requirements (footprints in case of environmental requirements) per region `i` are given by summing the detailed footprint accounts and adding the aggregated final demand stressors. +Consumption-based per region `i` are given by summing the total requirements (footprints) +as calculated by the Leontief demand model and adding the aggregated final demand stressors. .. math:: @@ -173,12 +260,22 @@ Similarly, total requirements (footprints in case of environmental requirements) D_{cba}^i = \sum_{s=0}^m D_{cba, s}^{i} + \sum_{c=0}^w F_{Yc}^i \end{equation} +Income-based accounts are given by summing the total requirements (footprints) +as calculated by the Ghosh supply (cost-push) model and adding the aggregated final demand stressors. + +.. math:: + + \begin{equation} + D_{iva}^i = \sum_{s=0}^m D_{iba, s}^{i} + \sum_{c=0}^w F_{Yc}^i + \end{equation} + + Internally, the summation are implemented with the `group-by `_ functionality provided by the pandas package. Upstream and Downstream scope 3 --------------------------------- +=============================== In the context of impact analyses the factors of production are often categorized into scope 1, 2 and 3, with scope 3 sub-divided into upstream and @@ -230,7 +327,7 @@ The pure downstream multiplier (excluding scope 1) is given by The sector's total impact multiplier is simply the sum of :math:`M_{up}`, :math:`S` and :math:`M_{down}`. Aggregation ------------- +=========== For the aggregation of the MRIO system the matrix :math:`B_k` defines the aggregation matrix for regions and :math:`B_n` the aggregation matrix diff --git a/doc/source/terminology.rst b/doc/source/terminology.rst index a21d96e6..6a10a05f 100644 --- a/doc/source/terminology.rst +++ b/doc/source/terminology.rst @@ -12,12 +12,18 @@ other names and abbreviations often found in the literature): +===============+==============================================+======================+====================================+=================================================================================================================================+ | Z | transaction matrix | T | flow matrix | transactions matrix, inter industry flows | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ -| A | A matrix | | | inter-industry coefficients (direct requirements matrix) | +| A | direct input requirement matrix | | | Leontief inter-industry coefficients (direct input requirements matrix) | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ -| L | Leontief inverse | B | | leontief inverse (total requirements matrix) (multi regional approach) | +| B | direct output requirement matrix | | | Ghosh inter-industry coefficients (direct output requirements matrix) | ++---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ +| L | leontief inverse | B | | leontief inverse (total input requirements matrix) | ++---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ +| G | ghosh inverse | | | ghosh inverse (total output requirement matrix) | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | Y | final demand matrix | H, y | | final demand matrix (sectors x region/countries and final demand categories) | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ +| V | value-added matrix | | | value added (value added categories and sectors x region) | ++---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | x | gross output | q | industry output | total output, defined as column vector | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | F | factor production | | extensions, stressors | Factors of productions: extensions plus value added block | @@ -30,13 +36,17 @@ other names and abbreviations often found in the literature): +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | D_cba | consumption-based accounts | fp, con | footprints, consumption footprints | footprint of consumption, further specification with reg (per region) or cap (per capita) possible | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ -| D_pba | production-based accounts | terr | territorial accoutns | territorial or domestic accounts, further specification with reg (per region) or cap (per capita) possible | +| D_iba | income-based accounts | | | | ++---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ +| D_pba | production-based accounts | terr | territorial accounts | territorial or domestic accounts, further specification with reg (per region) or cap (per capita) possible | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | D_imp | import accounts | imp | | import accounts, further specification with reg (per region) or cap (per capita) possible | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | D_exp | export accounts | exp | | export accounts, further specification with reg (per region) or cap (per capita) possible | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ -| M | multipliers | m | | total requirement factors | +| M | leontief multipliers | m | | total input requirement factors | ++---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ +| M_Ghosh | ghosh multipliers | m | | total output requirement factors | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | pxp | iosystem products x products | mxm | | | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ From a471a4a4257caf5f1a42a0b4f2d9d70d5b8ea839 Mon Sep 17 00:00:00 2001 From: Kajwan Date: Wed, 16 Jul 2025 18:18:41 +0200 Subject: [PATCH 4/7] included to-do list --- TODO.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 00000000..8c5df74c --- /dev/null +++ b/TODO.md @@ -0,0 +1,5 @@ + +- [] Finish mathematical background section +- [] Include value added as vector in core MRIO system +- [] Calculate income based accounts, and ensure they are treated the same as consumption based accounts when include_ghosh = True +- [] Potentially: Implement `M_Ghosh_downstream = M_Ghosh - S.T` and `M_Leontief_upstream = M - S`. \ No newline at end of file From 0ad7b403e7b21e2ef81981f1b167708285522353 Mon Sep 17 00:00:00 2001 From: Kajwan Date: Thu, 25 Sep 2025 15:13:38 +0100 Subject: [PATCH 5/7] Updated mathematicla background section --- doc/source/math.rst | 72 +++++++++----------------------------- doc/source/terminology.rst | 2 +- 2 files changed, 17 insertions(+), 57 deletions(-) diff --git a/doc/source/math.rst b/doc/source/math.rst index d945fd30..d4afce99 100644 --- a/doc/source/math.rst +++ b/doc/source/math.rst @@ -161,6 +161,13 @@ Leontief multipliers (total direct and indirect output needed in each sector to M = SL \end{equation} +If one wants to only extract the indirect output needed, one can calculate it as: +.. math:: + + \begin{equation} + M_{Leontief indirect} = S ( L - I ) = M - S + \end{equation} + Total requirements (footprints in case of environmental requirements) for any given final demand vector :math:`y` are then given by @@ -192,6 +199,7 @@ other countries is given by: with the hat indicating diagonalization of the resulting column-vector of the term underneath. + Ghosh supply model --------------------- @@ -227,8 +235,14 @@ Ghosh multipliers (total direct and indirect outputs generated in response to on M_{Ghosh} = G S \end{equation} +If one wants to only extract the indirect output generated in response to one unit of value-added supplied to a sector, one can calculate it as: +.. math:: + + \begin{equation} + M_{Ghosh indirect} = S ( G - I ) = M_{Ghosh} - S + \end{equation} -Total direct and indirect outputs generated for any value-added vector :math:`v` are then given by +Total requirements for any given value added vector :math:`v` are then given by .. math:: @@ -238,7 +252,6 @@ Total direct and indirect outputs generated for any value-added vector :math:`v` - Production-, Consumption-, and Income-based accounting ====================================================== @@ -266,66 +279,13 @@ as calculated by the Ghosh supply (cost-push) model and adding the aggregated fi .. math:: \begin{equation} - D_{iva}^i = \sum_{s=0}^m D_{iba, s}^{i} + \sum_{c=0}^w F_{Yc}^i + D_{iba}^i = \sum_{s=0}^m D_{iba, s}^{i} + \sum_{c=0}^w F_{Yc}^i \end{equation} Internally, the summation are implemented with the `group-by `_ functionality provided by the pandas package. - -Upstream and Downstream scope 3 -=============================== - -In the context of impact analyses the factors of production are often -categorized into scope 1, 2 and 3, with scope 3 sub-divided into upstream and -downstream. - -For a MRIO the scope 1 is the direct impact of the industries. The factors of production scope 1 associated -with some product or service in sector 'i' of monetary value 'r' is given by :math:`S e_i r``, where :math:`e_i`` is the math:`i^{th}`` unit vector. -Scope 2 is the indirect impact through directly consumed energy (mostly electricity). The precise definition of scope 2 -in an MRIO depends on the list of MRIO sectors that are classified as scope 2 energy suppliers. Scope 2 is therefore -included in the upstream scope 3, which we refer to as upstream indirect impacts. The upstream multipliers are - -.. math:: - - \begin{equation} - M_{up} = S ( L - I ) = M - S. - \end{equation} - -The downstream scope 3 consists of the factors of production associated with the sectors' output -that is input to other sectors. The downstream impact can be attributed with the Ghosh methodology -(`Lenzen, 2010 `_ ). - -The downstream attribution according to Ghosh is done by the input share matrix - -.. math:: - - \begin{equation} - B = \hat{x}^{-1} Z - \end{equation} - -Note that we have defined this matrix in analogy with :math:`A`, meaning that the factors of production coefficient -are given by :math:`S G^{T}` where - -.. math:: - - \begin{equation} - G = (\mathrm{I}- B)^{-1} = \hat{x} L \hat{x}^{-1} - \end{equation} - -is the Ghosh inverse matrix. -The pure downstream multiplier (excluding scope 1) is given by - - -.. math:: - - \begin{equation} - M_{down} = S(G^{T}-I) - \end{equation} - -The sector's total impact multiplier is simply the sum of :math:`M_{up}`, :math:`S` and :math:`M_{down}`. - Aggregation =========== diff --git a/doc/source/terminology.rst b/doc/source/terminology.rst index 6a10a05f..6d1cfbab 100644 --- a/doc/source/terminology.rst +++ b/doc/source/terminology.rst @@ -46,7 +46,7 @@ other names and abbreviations often found in the literature): +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | M | leontief multipliers | m | | total input requirement factors | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ -| M_Ghosh | ghosh multipliers | m | | total output requirement factors | +| M_Ghosh | ghosh multipliers | m_ghosh | | total output requirement factors | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ | pxp | iosystem products x products | mxm | | | +---------------+----------------------------------------------+----------------------+------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+ From 3829377777800b73774794dd401e902c6253d632 Mon Sep 17 00:00:00 2001 From: Kajwan Date: Thu, 25 Sep 2025 15:27:53 +0100 Subject: [PATCH 6/7] minor edits --- pymrio/core/mriosystem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pymrio/core/mriosystem.py b/pymrio/core/mriosystem.py index bbc4b816..a3e18dcf 100644 --- a/pymrio/core/mriosystem.py +++ b/pymrio/core/mriosystem.py @@ -296,6 +296,7 @@ def get_index(self, as_dict=False, grouping_pattern=None): "F", "F_Y", "M", + "M_Ghosh", "S", "D_cba", "D_pba", @@ -360,6 +361,7 @@ def get_regions(self, entries=None): "F", "F_Y", "M", + "M_Ghosh", "S", "D_cba", "D_pba", @@ -412,6 +414,7 @@ def get_sectors(self, entries=None): "Z", "F", "M", + "M_Ghosh", "S", "D_cba", "D_pba", @@ -1466,6 +1469,7 @@ def get_rows(self): "F", "F_Y", "M", + "M_Ghosh", "S", "D_cba", "D_pba", From 12d9c6d87356cbfc50d978db0b6ce1bfea6c02ae Mon Sep 17 00:00:00 2001 From: Kajwan Date: Thu, 25 Sep 2025 15:28:40 +0100 Subject: [PATCH 7/7] finished mathematical background section. Not sure if other to-dos are needed. --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 8c5df74c..b9724cea 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,5 @@ -- [] Finish mathematical background section +- [x] Finish mathematical background section - [] Include value added as vector in core MRIO system - [] Calculate income based accounts, and ensure they are treated the same as consumption based accounts when include_ghosh = True - [] Potentially: Implement `M_Ghosh_downstream = M_Ghosh - S.T` and `M_Leontief_upstream = M - S`. \ No newline at end of file