Skip to content

fluxopt.leontief

Cross-effect propagation: the Leontief inverse of contribution_from.

An effect that contributes to another — CO2 priced into cost — makes the effect system a linear one, and (I - C)^-1 is what solves it. The binder hands the model the chained share it implies; the ledger and the post-solve breakdown both read that share, so nothing else inverts it.

Functions:

Name Description
leontief

Compute Leontief inverse (I - C)^-1 from cross-effect coefficients.

leontief

leontief(cf: DataArray) -> DataArray

Compute Leontief inverse (I - C)^-1 from cross-effect coefficients.

Parameters:

Name Type Description Default

cf

DataArray

Cross-effect coefficients with dims (effect, source_effect) and optionally extra batch dims (e.g. time).

required
Source code in src/fluxopt/leontief.py
def leontief(cf: xr.DataArray) -> xr.DataArray:
    """Compute Leontief inverse (I - C)^-1 from cross-effect coefficients.

    Args:
        cf: Cross-effect coefficients with dims ``(effect, source_effect)``
            and optionally extra batch dims (e.g. ``time``).
    """
    n = cf.sizes['effect']
    batch_dims = [d for d in cf.dims if d not in ('effect', 'source_effect')]
    ordered = [*batch_dims, 'effect', 'source_effect']
    mat = np.eye(n) - cf.transpose(*ordered).values  # (..., n, n)
    return xr.DataArray(_inverse_per_batch(mat), dims=ordered, coords=cf.coords).transpose(*cf.dims)