bw2calc.least_squares
#
Module Contents#
Classes#
Solve overdetermined technosphere matrix with more products than activities using least-squares approximation. |
- class bw2calc.least_squares.LeastSquaresLCA(demand: dict, method: tuple | None = None, weighting: str | None = None, normalization: str | None = None, data_objs: Iterable[pathlib.Path | fs.base.FS | bw_processing.DatapackageBase] | None = None, remapping_dicts: Iterable[dict] | None = None, log_config: dict | None = None, seed_override: int | None = None, use_arrays: bool | None = False, use_distributions: bool | None = False, selective_use: dict | None = False)[source]#
Bases:
bw2calc.lca.LCA
Solve overdetermined technosphere matrix with more products than activities using least-squares approximation.
See also:
Create a new LCA calculation object.
Compatible with Brightway2 and 2.5 semantics. Can be static, stochastic, or iterative (scenario-based), depending on the
data_objs
input data..This class supports both stochastic and static LCA, and can use a variety of ways to describe uncertainty. The input flags use_arrays and use_distributions control some of this stochastic behaviour. See the [documentation for matrix_utils](brightway-lca/matrix_utils) for more information on the technical implementation.
Parameters#
- demanddict[object: float]
The demand for which the LCA will be calculated. The keys can be Brightway Node instances, (database, code) tuples, or integer ids.
- methodtuple
Tuple defining the LCIA method, such as (‘foo’, ‘bar’). Only needed if not passing data_objs.
- weightingtuple
Tuple defining the LCIA weighting, such as (‘foo’, ‘bar’). Only needed if not passing data_objs.
- weightingstring
String defining the LCIA normalization, such as ‘foo’. Only needed if not passing data_objs.
- data_objslist[bw_processing.Datapackage]
List of bw_processing.Datapackage objects. Can be loaded via bw2data.prepare_lca_inputs or constructed manually. Should include data for all needed matrices.
- remapping_dictsdict[str, dict]
Dict of remapping dictionaries that link Brightway Node ids to (database, code) tuples. remapping_dicts can provide such remapping for any of activity, product, biosphere.
- log_configdict
Optional arguments to pass to logging. Not yet implemented.
- seed_overrideint
RNG seed to use in place of Datapackage seed, if any.
- use_arraysbool
Use arrays instead of vectors from the given data_objs
- use_distributionsbool
Use probability distributions from the given data_objs
- selective_usedict[str, dict]
Dictionary that gives more control on whether use_arrays or use_distributions should be used. Has the form {matrix_label: {“use_arrays”|”use_distributions”: bool}. Standard matrix labels are technosphere_matrix, biosphere_matrix, and characterization_matrix.
- 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 deletingself.solver
when doing these types of advanced calculations.
- 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 pypardiso or 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.