SVDMethod¶
- class SVDMethod(*args)¶
Least squares solver using SVD decomposition.
This method implements a method to solve the least squares problem specified in using the SVD method.
Refer to Least squares meta models to get all the notations.
Refer to Least squares problems numerical methods to get details on the numerical method.
- Available constructors:
SVDMethod(proxy, weight, indices)
SVDMethod(proxy, indices)
SVDMethod(design)
- Parameters:
- proxy
DesignProxy The design proxy that builds the design matrix
- weightsequence of float
The output weights
- indicessequence of int
The indices allowed in the basis
- design2-d sequence of float
The known design matrix
- proxy
Methods
computeDesign([whole])Build the raw design matrix without weight scaling.
computeWeightedDesign([whole])Build the design matrix.
getBasis()Accessor to the basis.
Accessor to the object's name.
Current indices accessor.
Get the inverse of the weighted Gram matrix of the input sample.
Get the diagonal of the inverse weighted Gram matrix.
Get the trace of the inverse weighted Gram matrix.
getH()Get the symmetric weighted hat matrix H.
getHDiag()Get the diagonal of the symmetric weighted hat matrix H.
Initial indices accessor.
Input sample accessor.
getName()Accessor to the object's name.
Get the Moore-Penrose pseudo-inverse of the weighted design matrix.
Accessor to the weights.
hasName()Test if the object is named.
setName(name)Accessor to the object's name.
solve(rhs)Solve the least-squares problem.
solveNormal(rhs)Solve the least-squares problem using normal equation.
solveNormalGram(rhs)Solve the Gram system
where
is the weighted Gram matrix.
Drop the current decomposition.
update(addedIndices, conservedIndices, ...)Update the current decomposition.
See also
Examples
Solves a linear least squares problem with SVD method:
>>> import openturns as ot >>> design_matrix = ot.Matrix([[1, 1], [1, 2], [1, 3], [1, 4]]) >>> y = [6, 5, 7, 10] >>> method = ot.SVDMethod(design_matrix) >>> A = method.solve(y) >>> print(A) [3.5,1.4]
- __init__(*args)¶
- computeDesign(whole=False)¶
Build the raw design matrix without weight scaling.
- Parameters:
- wholebool, defaults to False
Whether to use the initial indices instead of the current indices
- Returns:
- design
Matrix The raw design matrix.
- design
- computeWeightedDesign(whole=False)¶
Build the design matrix.
The element of row
and column
of the returned matrix is
: the rows are scaled by the square root of the weights, and the columns are restricted to the current indices, that is, the constructor indices including any basis index added by
update(). The initial constructor indices are used only when whole is True.- Parameters:
- wholebool, defaults to False
Whether to use the initial indices instead of the current indices
- Returns:
- psiAk
Matrix The design matrix
- psiAk
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getCurrentIndices()¶
Current indices accessor.
- Returns:
- indices
Indices Indices of the current decomposition in the global basis.
- indices
- getGramInverse()¶
Get the inverse of the weighted Gram matrix of the input sample.
The weighted Gram matrix is defined as:
- Returns:
- gramInverse
CovarianceMatrix The inverse
of the weighted Gram matrix.
- gramInverse
- getGramInverseDiag()¶
Get the diagonal of the inverse weighted Gram matrix.
- Returns:
- diagGramInverse
Point The diagonal of the inverse of the weighted Gram matrix.
- diagGramInverse
- getGramInverseTrace()¶
Get the trace of the inverse weighted Gram matrix.
- Returns:
- tracefloat
The trace of the inverse of the weighted Gram matrix.
- getH()¶
Get the symmetric weighted hat matrix H.
With
the weight-scaled design and
the weighted Gram matrix, the weighted hat matrix is:
Its diagonal holds the weighted leverages
. The fitted values are
. For uniform weights this reduces to the classical hat matrix, independent of the common weight value.
- Returns:
- h
SymmetricMatrix The symmetric weighted hat matrix H.
- h
- getHDiag()¶
Get the diagonal of the symmetric weighted hat matrix H.
with
and
. Each entry is the weighted leverage
. For example, it is used by the analytical leave-one-out residual
[allen1974].
- Returns:
- diagH
Point The leverages, ie the diagonal of the symmetric weighted hat matrix.
- diagH
- getInitialIndices()¶
Initial indices accessor.
- Returns:
- indices
Indices Initial indices of the terms in the global basis.
- indices
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getPseudoInverse()¶
Get the Moore-Penrose pseudo-inverse of the weighted design matrix.
For a full-column-rank weighted design matrix
, it reads:
so that
solves the weighted least squares problem. The SVD decomposition also supports underdetermined designs of full row rank, where
is the Moore-Penrose pseudo-inverse. If a singular value is exactly zero, an exception is raised; this is an exact-zero check, not a numerical-rank test. Before a decomposition has been computed there are no singular values to check and an empty matrix is returned. Each decomposition (QR, Cholesky, SVD) evaluates it from its own factors.
- Returns:
- pseudoInverse
Matrix The Moore-Penrose pseudo-inverse of the weighted design matrix.
- pseudoInverse
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- solve(rhs)¶
Solve the least-squares problem.
The returned vector minimizes the weighted norm of the residual with respect to the right-hand side
, as described in the mathematical definition of the class:
- Parameters:
- ysequence of float
Right-hand side of the least squares equation, typically the output sample.
- Returns:
- a
Point The solution.
- a
- solveNormal(rhs)¶
Solve the least-squares problem using normal equation.
Only meaningful for uniform weights: the method rejects non-uniform weights with an exception. Use
solveNormalGramfor the general weighted case.- Parameters:
- bsequence of float
Second member of the equation.
- Returns:
- x
Point The solution.
- x
- solveNormalGram(rhs)¶
Solve the Gram system
where
is the weighted Gram matrix.
Unlike
solveNormal, this method does not apply weight multiplication to the right-hand side.- Parameters:
- rhssequence of float
Right-hand side of the equation.
- Returns:
- x
Point The solution.
- x
- trashDecomposition()¶
Drop the current decomposition.
- update(addedIndices, conservedIndices, removedIndices, row=False)¶
Update the current decomposition.
- Parameters:
- addedIndicessequence of int
Indices of added basis terms.
- conservedIndicessequence of int
Indices of conserved basis terms.
- removedIndicessequence of int
Indices of removed basis terms.
OpenTURNS