QuadraticLeastSquares

class QuadraticLeastSquares(*args)

Second order polynomial response surface by least squares.

Available constructors:

QuadraticLeastSquares(dataIn, function)

QuadraticLeastSquares(dataIn, dataOut)

Parameters:
dataIn2-d sequence of float

Input data.

functionFunction

Function h to be approximated.

dataOut2-d sequence of float

Output data. If not specified, this sample is computed such as: dataOut = h(dataIn).

Notes

Instead of replacing the model response h(\vect{x}) for a local approximation around a given set \vect{x}_0 of input parameters as in Taylor approximations, one may seek a global approximation of h(\vect{x}) over its whole domain of definition. A common choice to this end is global polynomial approximation.

We consider here a global approximation of the model response using a quadratic function:

\vect{y} \, \approx \, \widehat{h}(\vect{x}) \,
                  = \, \sum_{j=0}^{P-1} \; a_j \; \psi_j(\vect{x})

where P = 1+2n_X +n_X (n_X -1)/2 denotes the number of terms, (a_j  \, , \, j=0, \cdots,P-1) is a set of unknown coefficients and the family (\psi_j,j=0,\cdots, P-1) gathers the constant monomial 1, the monomials of degree one x_i, the cross-terms x_i x_j as well as the monomials of degree two x_i^2. Using the vector notation \vect{a} \, = \, (a_{0} , \cdots , a_{P-1} )^{\textsf{T}} and \vect{\psi}(\vect{x}) \, = \, (\psi_0(\vect{x}), \cdots, \psi_{P-1}(\vect{x}) )^{\textsf{T}}, this rewrites:

\vect{y} \, \approx \, \widehat{h}(\vect{x}) \,
                  = \, \vect{a}^{\textsf{T}} \; \vect{\psi}(\vect{x})

A global approximation of the model response over its whole definition domain is sought. To this end, the coefficients a_j may be computed using a least squares regression approach. In this context, an experimental design \vect{\cX} =(x^{(1)},\cdots,x^{(N)}), i.e. a set of realizations of input parameters is required, as well as the corresponding model evaluations \vect{\cY} =(y^{(1)},\cdots,y^{(N)}).

The following minimization problem has to be solved:

\mbox{Find} \quad \widehat{\vect{a}} \quad \mbox{that minimizes}
  \quad \cJ(\vect{a}) \, = \, \sum_{i=1}^N \;
                            \left(
                            y^{(i)} \; - \;
                            \Tr{\vect{a}} \vect{\psi}(\vect{x}^{(i)})
                            \right)^2

The solution is given by:

\widehat{\vect{a}} \, = \, \left(
                           \Tr{\mat{\Psi}} \mat{\Psi}
                           \right)^{-1} \;
                           \Tr{\mat{\Psi}}  \; \vect{\cY}

where:

\mat{\Psi} \, = \, (\psi_{j}(\vect{x}^{(i)}) \; , \; i=1,\cdots,N \; , \; j = 0,\cdots,n_X)

Examples

>>> import openturns as ot
>>> formulas = ['x1 * sin(x2)', 'cos(x1 + x2)', '(x2 + 1) * exp(x1 - 2 * x2)']
>>> myFunc = ot.SymbolicFunction(['x1', 'x2'], formulas)
>>> data  = [[0.5,0.5], [-0.5,-0.5], [-0.5,0.5], [0.5,-0.5]]
>>> data += [[0.25,0.25], [-0.25,-0.25], [-0.25,0.25], [0.25,-0.25]]
>>> myLeastSquares = ot.QuadraticLeastSquares(data, myFunc)
>>> myLeastSquares.run()
>>> responseSurface = myLeastSquares.getMetaModel()
>>> print(responseSurface([0.1,0.1]))
[0.00960661,0.976781,1.0138]

Methods

getClassName()

Accessor to the object's name.

getConstant()

Get the constant vector of the approximation.

getDataIn()

Get the input data.

getDataOut()

Get the output data.

getId()

Accessor to the object's id.

getInputFunction()

Get the function.

getLinear()

Get the linear matrix of the approximation.

getMetaModel()

Get an approximation of the function.

getName()

Accessor to the object's name.

getQuadratic()

Get the quadratic term of the approximation.

getShadowedId()

Accessor to the object's shadowed id.

getVisibility()

Accessor to the object's visibility state.

hasName()

Test if the object is named.

hasVisibleName()

Test if the object has a distinguishable name.

run()

Perform the least squares approximation.

setDataOut(dataOut)

Set the output data.

setName(name)

Accessor to the object's name.

setShadowedId(id)

Accessor to the object's shadowed id.

setVisibility(visible)

Accessor to the object's visibility state.

__init__(*args)
getClassName()

Accessor to the object’s name.

Returns:
class_namestr

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

getConstant()

Get the constant vector of the approximation.

Returns:
constantVectorPoint

Constant vector of the approximation, equal to a_0.

getDataIn()

Get the input data.

Returns:
dataInSample

Input data.

getDataOut()

Get the output data.

Returns:
dataOutSample

Output data. If not specified in the constructor, the sample is computed such as: dataOut = h(dataIn).

getId()

Accessor to the object’s id.

Returns:
idint

Internal unique identifier.

getInputFunction()

Get the function.

Returns:
functionFunction

Function h to be approximated.

getLinear()

Get the linear matrix of the approximation.

Returns:
linearMatrixMatrix

Linear matrix of the approximation of the function h.

getMetaModel()

Get an approximation of the function.

Returns:
approximationFunction

An approximation of the function h by Quadratic Least Squares.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getQuadratic()

Get the quadratic term of the approximation.

Returns:
tensorSymmetricTensor

Quadratic term of the approximation of the function h.

getShadowedId()

Accessor to the object’s shadowed id.

Returns:
idint

Internal unique identifier.

getVisibility()

Accessor to the object’s visibility state.

Returns:
visiblebool

Visibility flag.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

hasVisibleName()

Test if the object has a distinguishable name.

Returns:
hasVisibleNamebool

True if the name is not empty and not the default one.

run()

Perform the least squares approximation.

setDataOut(dataOut)

Set the output data.

Parameters:
dataOut2-d sequence of float

Output data.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setShadowedId(id)

Accessor to the object’s shadowed id.

Parameters:
idint

Internal unique identifier.

setVisibility(visible)

Accessor to the object’s visibility state.

Parameters:
visiblebool

Visibility flag.