GeneralizedLinearModelAlgorithm

class GeneralizedLinearModelAlgorithm(*args)

Algorithm for the evaluation of general linear models.

Available constructors:

GeneralizedLinearModelAlgorithm(inputSample, outputSample, covarianceModel, basis, normalize=True, keepCovariance=True)

GeneralizedLinearModelAlgorithm(inputSample, inputTransformation, outputSample, covarianceModel, basis, keepCovariance=True)

GeneralizedLinearModelAlgorithm(inputSample, outputSample, covarianceModel, multivariateBasis, normalize=True, keepCovariance=True)

GeneralizedLinearModelAlgorithm(inputSample, inputTransformation, outputSample, covarianceModel, multivariateBasis, keepCovariance=True)

Parameters:

inputSample, outputSample : NumericalSample or 2d-array

The samples (\vect{x}_k)_{1 \leq k \leq N} \in \Rset^d and (\vect{y}_k)_{1 \leq k \leq N}\in \Rset^p.

inputTransformation : NumericalMathFunction

Function T that helps to normalize the input sample.

If used, the meta model is built on the transformed data.

basis : Basis

Functional basis to estimate the trend: (\varphi_j)_{1 \leq j \leq n_1}: \Rset^d \rightarrow \Rset.

If p>1, the same basis is used for each marginal output.

multivariateBasis : collection of Basis

Collection of p functional basis: one basis for each marginal output.

If the trend is not estimated, the collection must be empty.

covarianceModel : CovarianceModel

Covariance model of the normal process.

normalize : bool, optional

Indicates whether the input sample has to be normalized.

OpenTURNS uses the transformation fixed by the User in inputTransformation or the empirical mean and variance of the input sample. Default is set in resource map key GeneralizedLinearModelAlgorithm-NormalizeData

keepCovariance : bool, optional

Indicates whether the covariance matrix has to be stored in the result structure GeneralizedLinearModelResult. Default is set in resource map key GeneralizedLinearModelAlgorithm-KeepCovariance

Notes

We suppose we have a sample (\vect{x}_k, \vect{y}_k)_{1 \leq k \leq N} where \vect{y}_k = \cM(\vect{x}_k) for all k, with \cM:\Rset^d \mapsto \Rset^p the model.

The objective is to build a metamodel \tilde{\cM}, using a generalized linear model: the sample (\vect{y}_k)_{1 \leq k \leq N} is considered as the trace of a normal process \vect{Y}(\omega, \vect{x}) on (\vect{x}_k)_{1 \leq k \leq N}. The normal process \vect{Y}(\omega, \vect{x}) is defined by:

\vect{Y}(\omega, \vect{x}) = \vect{\mu}(\vect{x}) + \vect{W}(\omega, \vect{x})

where:

\vect{\mu}(\vect{x}) = \left(
  \begin{array}{l}
    \mu_1(\vect{x}) \\
    \dots  \\
    \mu_p(\vect{x}) 
   \end{array}
 \right)

with \mu_l(\vect{x}) = \sum_{j=1}^{n_l} \alpha_j^l \varphi_j^l(\vect{x}) and \varphi_j^l: \Rset^d \rightarrow \Rset the trend functions.

\vect{W} is a normal process of dimension p with zero mean and covariance function C = C(\vect{\theta}, \vect{\sigma}, \mat{R}, \vect{\lambda}) (see CovarianceModel for the notations).

We note:

\vect{\alpha}^l(\vect{x}) = \left(
  \begin{array}{l}
    \alpha_1^l \\
    \dots  \\
    \alpha_{n_l}^l
   \end{array}
 \right) \in \Rset^{n_l}
 \quad \mbox{ and } \quad 
 \vect{\alpha}(\vect{x}) = \left(
  \begin{array}{l}
     \vect{\alpha}^1\\
    \dots  \\
     \vect{\alpha}^p
   \end{array}
 \right)\in \Rset^{\sum_{l=1}^p n_l}

The GeneralizedLinearModelAlgorithm class estimates the coefficients \alpha_j^l, \vect{\theta}, \vect{\sigma} by maximizing the likelihood of the model. The values of (\vect{\theta}, \vect{\sigma}) fixed by the User at the creation of the class are used as initial values for the optimization algorithm.

Note that the parameters (\mat{R}, \vect{\lambda}) are not optimized: they are fixed to the values specified by the User.

If a normalizing transformation T has been used, the meta model is built on the inputs \vect{z}_k = T(\vect{x}_k).

Estimation of the parameters \alpha_j^l, \vect{\theta}, \vect{\sigma}

We note:

\vect{y} = \left(
     \begin{array}{l}
       \vect{y}_1 \\
       \dots  \\
       \vect{y}_N
      \end{array}
    \right) \in \Rset^{pN},
    \quad 
    \vect{m} = \left(
     \begin{array}{l}
       \vect{\mu}(\vect{x}_1) \\
       \dots  \\
       \vect{\mu}(\vect{x}_N)
      \end{array}
    \right) \in \Rset^{pN}

and

\mat{C} = \left(
  \begin{array}{lcl}
    \mat{C}_{11} & \dots &  \mat{C}_{1N}\\
    \dots & \dots & \\
    \mat{C}_{N1} & \dots &  \mat{C}_{NN}
   \end{array}
 \right) \in \cS_{pN}^+(\Rset)

where \mat{C}_{ij} = C(\vect{x}_i, \vect{x}_j).

The model likelihood writes:

p((\vect{x}_k, \vect{y}_k)_{1 \leq k \leq N}) = \dfrac{1}{(2\pi)^{pN/2} |\det \mat{C}|^{1/2}} \exp\left[ -\dfrac{1}{2}\Tr{\left( \vect{y}-\vect{m} \right)} \mat{C}^{-1}  \left( \vect{y}-\vect{m} \right)  \right]

With \mat{L} the inferior triangular matrix such that \mat{L}\Tr{\mat{L}} = \mat{C}, then:

(1)\log p((\vect{x}_k, \vect{y}_k)_{1 \leq k \leq N}) = cste -\dfrac{1}{2} \log \det \mat{L} -\dfrac{1}{2}  \| \mat{L}^{-1}(\vect{y}-\vect{m}) \|^2

OpenTURNS proceeds as follows:

  • maximization of (1) with respect to \vect{\alpha} where (\vect{\theta}, \vect{\sigma}) are fixed: it is equivalent to minimizing the term \| \mat{L}^{-1}(\vect{y}-\vect{m}) \|^2 (the optimization problem is a least square problem). Then \vect{\alpha} = \vect{\alpha}(\vect{\theta}, \vect{\sigma});
  • maximization of (1) with respect to \vect{\theta}, \vect{\sigma} where \vect{\alpha} has been replaced by \vect{\alpha} = \vect{\alpha}(\vect{\theta}, \vect{\sigma}).
  • then, we obtain the optimal values (\vect{\theta}^*, \vect{\sigma}^*) and \vect{\theta}^* = \vect{\alpha}(\vect{\theta}^*, \vect{\sigma}^*).

In the particular case where p=1, the first step introduces the additional relation \vect{\sigma} = \vect{\sigma}(\vect{\theta}). Thus, the second step is optimized with respect to the only parameter \vect{\theta} and the optimized values write \vect{\sigma}^* = \vect{\sigma}(\vect{\theta}^*) and \vect{\alpha}^* = \vect{\alpha}(\vect{\theta}^*).

Default optimizer is TNC and can be changed thanks to the setOptimizationSolver method. User could also change the default optimization solver by setting the GeneralizedLinearModelAlgorithm-DefaultOptimizationSolver resource map key to NELDER-MEAD or LBFGS respectively for Nelder-Mead and LBFGS-B solvers.

It is also possible to proceed as follows:

  • ask for the log-likelihood function of the GeneralizedLinearModelAlgorithm thanks to the getObjectiveFunction() method
  • optimize it with respect to the parameters \vect{\theta} and \vect{\sigma} using any optimisation algorithms (that can take into account some additional constraints if needed)
  • fulfill the GeneralizedLinearModelAlgorithm with the optimized value of these parameters.

With huge samples, the hierarchical matrix implementation could be used if OpenTURNS had been compiled with hmat-oss support.

This implementation, which is based on a sparse representation of an approximated covariance matrix (and its Cholesky factor), has a better complexity both in terms of memory requirements and floating point operations. To use it, the GeneralizedLinearModelAlgorithm-LinearAlgebra resource map key should be instancied to HMAT. Default value of the key is LAPACK.

A known centered gaussian observation noise \epsilon_k can be taken into account with setNoise():

\hat{\vect{y}}_k = \vect{y}_k + \epsilon_k, \epsilon_k \sim \mathcal{N}(0, \tau_k^2)

Examples

Create the model \cM: \Rset \mapsto \Rset and the samples:

>>> import openturns as ot
>>> f = ot.NumericalMathFunction(['x'], ['x * sin(x)'])
>>> inputSample = ot.NumericalSample([[1.0], [3.0], [5.0], [6.0], [7.0], [8.0]])
>>> outputSample = f(inputSample)

Create the algorithm:

>>> basis = ot.ConstantBasisFactory().build()
>>> covarianceModel = ot.SquaredExponential(1)
>>> algo = ot.GeneralizedLinearModelAlgorithm(inputSample, outputSample, covarianceModel, basis)
>>> algo.run()

Get the resulting meta model:

>>> result = algo.getResult()
>>> metamodel = result.getMetaModel()

Methods

getClassName() Accessor to the object’s name.
getDistribution() Accessor to the joint probability density function of the physical input vector.
getId() Accessor to the object’s id.
getInputSample() Accessor to the input sample.
getInputTransformation() Get the function normalizing the input.
getName() Accessor to the object’s name.
getNoise() Observation noise variance accessor.
getObjectiveFunction() Accessor to the log-likelihood function that writes as argument of the covariance’s model parameters.
getOptimizationSolver() Accessor to solver used to optimize the covariance model parameters.
getOptimizeParameters() Accessor to the covariance model parameters optimization flag.
getOutputSample() Accessor to the output sample.
getResult() Get the results of the metamodel computation.
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() Compute the response surface.
setDistribution(distribution) Accessor to the joint probability density function of the physical input vector.
setInputTransformation(inputTransformation) Set the function normalizing the input.
setName(name) Accessor to the object’s name.
setNoise(noise) Observation noise variance accessor.
setOptimizationSolver(solver) Accessor to the solver used to optimize the covariance model parameters.
setOptimizeParameters(optimizeParameters) Accessor to the covariance model parameters optimization flag.
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_name : str

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

getDistribution()

Accessor to the joint probability density function of the physical input vector.

Returns:

distribution : Distribution

Joint probability density function of the physical input vector.

getId()

Accessor to the object’s id.

Returns:

id : int

Internal unique identifier.

getInputSample()

Accessor to the input sample.

Returns:

inputSample : NumericalSample

The input sample (\vect{x}_k)_{1 \leq k \leq N}.

getInputTransformation()

Get the function normalizing the input.

Returns:

transformation : NumericalMathFunction

Function T that normalizes the input.

getName()

Accessor to the object’s name.

Returns:

name : str

The name of the object.

getNoise()

Observation noise variance accessor.

Parameters:

noise : sequence of positive float

The noise variance \tau_k^2 of each output value.

getObjectiveFunction()

Accessor to the log-likelihood function that writes as argument of the covariance’s model parameters.

Returns:

logLikelihood : NumericalMathFunction

The log-likelihood function degined in (1) as a function of (\vect{\theta}, \vect{\sigma}).

Notes

The log-likelihood function may be useful for some postprocessing: maximization using external optimizers for example.

Examples

Create the model \cM: \Rset \mapsto \Rset and the samples:

>>> import openturns as ot
>>> f = ot.NumericalMathFunction(['x0'], ['f0'], ['x0 * sin(x0)'])
>>> inputSample = ot.NumericalSample([[1.0], [3.0], [5.0], [6.0], [7.0], [8.0]])
>>> outputSample = f(inputSample)

Create the algorithm:

>>> basis = ot.ConstantBasisFactory().build()
>>> covarianceModel = ot.SquaredExponential(1)
>>> algo = ot.GeneralizedLinearModelAlgorithm(inputSample, outputSample, covarianceModel, basis)
>>> algo.run()

Get the log-likelihood function:

>>> likelihoodFunction = algo.getObjectiveFunction()
getOptimizationSolver()

Accessor to solver used to optimize the covariance model parameters.

Returns:

algorithm : OptimizationSolver

Solver used to optimize the covariance model parameters. Default optimizer is TNC

getOptimizeParameters()

Accessor to the covariance model parameters optimization flag.

Returns:

optimizeParameters : bool

Whether to optimize the covariance model parameters.

getOutputSample()

Accessor to the output sample.

Returns:

outputSample : NumericalSample

The output sample (\vect{y}_k)_{1 \leq k \leq N} .

getResult()

Get the results of the metamodel computation.

Returns:

result : GeneralizedLinearModelResult

Structure containing all the results obtained after computation and created by the method run().

getShadowedId()

Accessor to the object’s shadowed id.

Returns:

id : int

Internal unique identifier.

getVisibility()

Accessor to the object’s visibility state.

Returns:

visible : bool

Visibility flag.

hasName()

Test if the object is named.

Returns:

hasName : bool

True if the name is not empty.

hasVisibleName()

Test if the object has a distinguishable name.

Returns:

hasVisibleName : bool

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

run()

Compute the response surface.

Notes

It computes the response surface and creates a GeneralizedLinearModelResult structure containing all the results.

setDistribution(distribution)

Accessor to the joint probability density function of the physical input vector.

Parameters:

distribution : Distribution

Joint probability density function of the physical input vector.

setInputTransformation(inputTransformation)

Set the function normalizing the input.

Parameters:

transformation : NumericalMathFunction

Function that normalizes the input. The input dimension should be the same as input’s sample dimension, output dimension should be output sample’s dimension

setName(name)

Accessor to the object’s name.

Parameters:

name : str

The name of the object.

setNoise(noise)

Observation noise variance accessor.

Parameters:

noise : sequence of positive float

The noise variance \tau_k^2 of each output value.

setOptimizationSolver(solver)

Accessor to the solver used to optimize the covariance model parameters.

Parameters:

algorithm : OptimizationSolver

Solver used to optimize the covariance model parameters.

setOptimizeParameters(optimizeParameters)

Accessor to the covariance model parameters optimization flag.

Parameters:

optimizeParameters : bool

Whether to optimize the covariance model parameters.

setShadowedId(id)

Accessor to the object’s shadowed id.

Parameters:

id : int

Internal unique identifier.

setVisibility(visible)

Accessor to the object’s visibility state.

Parameters:

visible : bool

Visibility flag.