bw2calc.least_squares#

Module Contents#

Classes#

LeastSquaresLCA

Solve overdetermined technosphere matrix with more products than activities using least-squares approximation.

class bw2calc.least_squares.LeastSquaresLCA(demand: dict, method: Optional[tuple] = None, weighting: Optional[str] = None, normalization: Optional[str] = None, data_objs: Optional[Iterable[Union[pathlib.Path, fs.base.FS, bw_processing.DatapackageBase]]] = None, remapping_dicts: Optional[Iterable[dict]] = None, log_config: Optional[dict] = None, seed_override: Optional[int] = None, use_arrays: bool = False, use_distributions: bool = False)[source]#

Bases: bw2calc.lca.LCA

Inheritance diagram of bw2calc.least_squares.LeastSquaresLCA

Solve overdetermined technosphere matrix with more products than activities using least-squares approximation.

See also:

Create a new LCA calculation.

Args:
  • demand (dict): The demand or functional unit. Needs to be a dictionary to indicate amounts, e.g. {7: 2.5}.

  • method (tuple, optional): LCIA Method tuple, e.g. ("My", "great", "LCIA", "method"). Can be omitted if only interested in calculating the life cycle inventory.

Returns:

A new LCA object

abstract decompose_technosphere() None[source]#

Factorize the technosphere matrix into lower and upper triangular matrices, \(A=LU\). Does not solve the linear system \(Ax=B\).

Doesn’t return anything, but creates self.solver.

Warning

Incorrect results could occur if a technosphere matrix was factorized, and then a new technosphere matrix was constructed, as self.solver would still be the factorized older technosphere matrix. You are responsible for deleting self.solver when doing these types of advanced calculations.

load_lci_data() None[source]#

Load inventory data and create technosphere and biosphere matrices.

solve_linear_system(solver=lsmr) numpy.ndarray[source]#

Master solution function for linear system \(Ax=B\).

To most numerical analysts, matrix inversion is a sin.

—Nicolas Higham, Accuracy and Stability of Numerical Algorithms, Society for Industrial and Applied Mathematics, Philadelphia, PA, USA, 2002, p. 260.

We use UMFpack, which is a very fast solver for sparse matrices.

If the technosphere matrix has already been factorized, then the decomposed technosphere (self.solver) is reused. Otherwise the calculation is redone completely.