# LinearLeastSquares¶

class LinearLeastSquares(*args)

First order polynomial response surface by least squares.

Available constructors:

LinearLeastSquares(dataIn, function)

LinearLeastSquares(dataIn, dataOut)

Parameters
dataIn2-d sequence of float

Input data.

functionFunction

Function to be approximated.

dataOut2-d sequence of float

Output data. If not specified, this sample is computed such as: .

Notes

Instead of replacing the model response for a local approximation around a given set of input parameters as in Taylor approximations, one may seek a global approximation of 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 linear function:

where is a set of unknown coefficients and the family gathers the constant monomial and the monomials of degree one . Using the vector notation and , this rewrites:

A global approximation of the model response over its whole definition domain is sought. To this end, the coefficients may be computed using a least squares regression approach. In this context, an experimental design , i.e. a set of realizations of input parameters is required, as well as the corresponding model evaluations .

The following minimization problem has to be solved:

The solution is given by:

where:

Examples

>>> import openturns as ot
>>> formulas = ['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.LinearLeastSquares(data, myFunc)
>>> myLeastSquares.run()
>>> responseSurface = myLeastSquares.getMetaModel()
>>> print(responseSurface([0.1,0.1]))
[0.854471,1.06031]


Methods

 getClassName(self) Accessor to the object’s name. getConstant(self) Get the constant vector of the approximation. getDataIn(self) Get the input data. getDataOut(self) Get the output data. getId(self) Accessor to the object’s id. Get the function. getLinear(self) Get the linear matrix of the approximation. getMetaModel(self) Get an approximation of the function. getName(self) Accessor to the object’s name. getShadowedId(self) Accessor to the object’s shadowed id. getVisibility(self) Accessor to the object’s visibility state. hasName(self) Test if the object is named. hasVisibleName(self) Test if the object has a distinguishable name. run(self) Perform the least squares approximation. setDataOut(self, dataOut) Set the output data. setName(self, name) Accessor to the object’s name. setShadowedId(self, id) Accessor to the object’s shadowed id. setVisibility(self, visible) Accessor to the object’s visibility state.
__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

getClassName(self)

Accessor to the object’s name.

Returns
class_namestr

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

getConstant(self)

Get the constant vector of the approximation.

Returns
constantVectorPoint

Constant vector of the approximation, equal to .

getDataIn(self)

Get the input data.

Returns
dataInSample

Input data.

getDataOut(self)

Get the output data.

Returns
dataOutSample

Output data. If not specified in the constructor, the sample is computed such as: .

getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getInputFunction(self)

Get the function.

Returns
functionFunction

Function to be approximated.

getLinear(self)

Get the linear matrix of the approximation.

Returns
linearMatrixMatrix

Linear matrix of the approximation of the function .

getMetaModel(self)

Get an approximation of the function.

Returns
approximationFunction

An approximation of the function by Linear Least Squares.

getName(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getShadowedId(self)

Accessor to the object’s shadowed id.

Returns
idint

Internal unique identifier.

getVisibility(self)

Accessor to the object’s visibility state.

Returns
visiblebool

Visibility flag.

hasName(self)

Test if the object is named.

Returns
hasNamebool

True if the name is not empty.

hasVisibleName(self)

Test if the object has a distinguishable name.

Returns
hasVisibleNamebool

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

run(self)

Perform the least squares approximation.

setDataOut(self, dataOut)

Set the output data.

Parameters
dataOut2-d sequence of float

Output data.

setName(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setShadowedId(self, id)

Accessor to the object’s shadowed id.

Parameters
idint

Internal unique identifier.

setVisibility(self, visible)

Accessor to the object’s visibility state.

Parameters
visiblebool

Visibility flag.