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:
proxyDesignProxy

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

Methods

computeDesign([whole])

Build the raw design matrix without weight scaling.

computeWeightedDesign([whole])

Build the design matrix.

getBasis()

Accessor to the basis.

getClassName()

Accessor to the object's name.

getCurrentIndices()

Current indices accessor.

getGramInverse()

Get the inverse of the weighted Gram matrix of the input sample.

getGramInverseDiag()

Get the diagonal of the inverse weighted Gram matrix.

getGramInverseTrace()

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.

getInitialIndices()

Initial indices accessor.

getInputSample()

Input sample accessor.

getName()

Accessor to the object's name.

getPseudoInverse()

Get the Moore-Penrose pseudo-inverse of the weighted design matrix.

getWeight()

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 \mat{G} \vect{x} = \vect{rhs} where \mat{G} = \mat{M}^\top \mat{W} \mat{M} is the weighted Gram matrix.

trashDecomposition()

Drop the current decomposition.

update(addedIndices, conservedIndices, ...)

Update the current decomposition.

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:
designMatrix

The raw design matrix.

computeWeightedDesign(whole=False)

Build the design matrix.

The element of row i and column j of the returned matrix is w_i^{1/2} \psi_j(\vect{u}_i): 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:
psiAkMatrix

The design matrix

getBasis()

Accessor to the basis.

Returns:
basiscollection of Function

Basis.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getCurrentIndices()

Current indices accessor.

Returns:
indicesIndices

Indices of the current decomposition in the global basis.

getGramInverse()

Get the inverse of the weighted Gram matrix of the input sample.

The weighted Gram matrix is defined as:

\mat{G} = \mat{\Psi}^\intercal \mat{W} \, \mat{\Psi}

Returns:
gramInverseCovarianceMatrix

The inverse \mat{G}^{-1} of the weighted Gram matrix.

getGramInverseDiag()

Get the diagonal of the inverse weighted Gram matrix.

\mathrm{diag}(\mat{G}^{-1}) = \mathrm{diag}\left((\mat{\Psi}^\intercal \mat{W} \, \mat{\Psi})^{-1}\right)

Returns:
diagGramInversePoint

The diagonal of the inverse of the weighted Gram matrix.

getGramInverseTrace()

Get the trace of the inverse weighted Gram matrix.

\mathrm{Tr}(\mat{G}^{-1}) = \mathrm{Tr}\left((\mat{\Psi}^\intercal \mat{W} \, \mat{\Psi})^{-1}\right)

Returns:
tracefloat

The trace of the inverse of the weighted Gram matrix.

getH()

Get the symmetric weighted hat matrix H.

With \mat{\Psi}_w = \mat{W}^{1/2} \mat{\Psi} the weight-scaled design and \mat{G} = \mat{\Psi}^\intercal \mat{W} \, \mat{\Psi} the weighted Gram matrix, the weighted hat matrix is:

\mat{H} = \mat{\Psi}_w \mat{G}^{-1} \mat{\Psi}_w^\intercal

Its diagonal holds the weighted leverages h_i = w_i \psi(\vect{u}_i)^\intercal \mat{G}^{-1} \psi(\vect{u}_i). The fitted values are \hat{\vect{y}} = \mat{\Psi} \mat{G}^{-1} \mat{\Psi}^\intercal \mat{W} \vect{b}. For uniform weights this reduces to the classical hat matrix, independent of the common weight value.

Returns:
hSymmetricMatrix

The symmetric weighted hat matrix H.

getHDiag()

Get the diagonal of the symmetric weighted hat matrix H.

\mathrm{diag}(\mat{H}) = \mathrm{diag}\left(\mat{\Psi}_w \mat{G}^{-1} \mat{\Psi}_w^\intercal\right)

with \mat{\Psi}_w = \mat{W}^{1/2} \mat{\Psi} and \mat{G} = \mat{\Psi}^\intercal \mat{W} \, \mat{\Psi}. Each entry is the weighted leverage h_i = w_i \psi(\vect{u}_i)^\intercal \mat{G}^{-1} \psi(\vect{u}_i). For example, it is used by the analytical leave-one-out residual r_i/(1-h_i) [allen1974].

Returns:
diagHPoint

The leverages, ie the diagonal of the symmetric weighted hat matrix.

getInitialIndices()

Initial indices accessor.

Returns:
indicesIndices

Initial indices of the terms in the global basis.

getInputSample()

Input sample accessor.

Returns:
inputSampleSample

Input sample.

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 \mat{\Psi}_w = \mat{W}^{1/2} \mat{\Psi}, it reads:

\mat{B} = (\mat{\Psi}_w^\intercal \mat{\Psi}_w)^{-1} \mat{\Psi}_w^\intercal

so that \hat{\mat{\beta}} = \mat{B} \mat{W}^{1/2} \vect{y} solves the weighted least squares problem. The SVD decomposition also supports underdetermined designs of full row rank, where \mat{B} 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:
pseudoInverseMatrix

The Moore-Penrose pseudo-inverse of the weighted design matrix.

getWeight()

Accessor to the weights.

Returns:
weightPoint

Weights.

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 \vect{y}, as described in the mathematical definition of the class:

\vect{a} = \argmin_{\vect{b} \in \Rset^P}
\left\|\mat{W}^{1/2} \left(\mat{\Psi} \vect{b} - \vect{y}\right)\right\|_2^2

Parameters:
ysequence of float

Right-hand side of the least squares equation, typically the output sample.

Returns:
aPoint

The solution.

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 solveNormalGram for the general weighted case.

\mat{\Psi}^\intercal \mat{W} \, \mat{\Psi} \, \vect{x}
= \mat{\Psi}^\intercal \mat{W} \, \vect{b}

Parameters:
bsequence of float

Second member of the equation.

Returns:
xPoint

The solution.

solveNormalGram(rhs)

Solve the Gram system \mat{G} \vect{x} = \vect{rhs} where \mat{G} = \mat{M}^\top \mat{W} \mat{M} 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:
xPoint

The solution.

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.