LatentVariableModel¶
- class LatentVariableModel(*args)¶
Latent variable covariance function.
- Parameters:
- nLevelsint
Number of levels
characterizing the categorical variable.
- latentDimint
The dimension
of the latent space onto which the categorical variable levels are projected.
Methods
activateAmplitude(isAmplitudeActive)Activate/deactivate the amplitude parameters.
activateNuggetFactor(isNuggetFactorActive)Activate/deactivate the nugget factor.
activateScale(isScaleActive)Activate/deactivate the scale parameters.
computeAsScalar(*args)Compute the covariance function for scalar model.
computeCrossCovariance(*args)Compute the covariance function on two given meshes.
discretize(*args)Discretize the covariance function on a given mesh.
discretizeAndFactorize(*args)Discretize and factorize the covariance function on a given mesh.
Discretize and factorize the covariance function on a given mesh using HMatrix.
Discretize and factorize the covariance function on a given mesh using HODLRMatrix.
discretizeHMatrix(*args)Discretize the covariance function on a given mesh using HMatrix.
discretizeHODLRMatrix(*args)Discretize the covariance function on a given mesh using HODLRMatrix.
discretizeRow(vertices, p)Discretize the covariance function on a given mesh for a specific row.
draw(*args)Not yet implemented
fourthOrderPartial(s, t)Compute the fourth-order spatial derivatives of the
output component of the covariance function.
Active latent variables accessor.
Accessor to the active parameter set.
Get the amplitude parameter
of the covariance function.
Accessor to the object's name.
Latent variables accessor.
Get the full parameters of the covariance function.
Get the description of the full parameters of the covariance function.
Get the input dimension of the covariance function.
Latent dimension accessor.
Level number accessor.
getMarginal(*args)Get the marginal covariance model.
getName()Accessor to the object's name.
Accessor to the nugget factor.
Get the spatial correlation matrix
of the covariance function.
Get the output dimension of the covariance function.
Get the values of the active parameters of the covariance function.
Get the description of the active parameters of the covariance function.
getScale()Get the scale parameter
of the covariance function.
hasName()Test if the object is named.
Test whether the model is diagonal.
Accessor to the parallel flag.
Test whether the model is stationary.
parameterGradient(s, t)Compute the gradient of the covariance function with respect to the active parameters.
parameterHessian(s, t)Compute the mixed parameter-spatial Hessian of the
output component of the covariance function.
partialGradient(s, t)Compute the gradient of the covariance function with respect to the first index
.
partialHessian(s, t)Compute the Hessian of the
output component of the covariance function with respect to the first index
.
setActiveParameter(active)Accessor to the active parameter set.
setAmplitude(amplitude)Set the amplitude parameter
of the covariance function.
setFullParameter(parameter)Set the full parameters of the covariance function.
setLatentVariables(latentVariablesCoordinates)Number of levels accessor.
setName(name)Accessor to the object's name.
setNuggetFactor(nuggetFactor)Set the nugget factor for the variance of the observation error.
setOutputCorrelation(correlation)Set the spatial correlation matrix
of the covariance function.
setParameter(parameter)Set the values of the active parameters of the covariance function.
setScale(scale)Set the scale parameter
of the covariance function.
thirdOrderPartial(s, t)Compute the third-order spatial derivatives of the
output component of the covariance function.
See also
Notes
The Latent variable covariance function is a covariance model allowing to compute the covariance between different unordered values (or levels) of a categorical variable
.
The underlying idea is that each categorical level is mapped onto a distinct point in a
-dimensional latent space. The covariance between the various levels is then computed as the
SquaredExponentialcovariance between the mappings in the latent space. Letbe the mapping function, the covariance function between two discrete values
and
is computed as:
The coordinates of the mapping points are part of the covariance model parameters, together with the latent squared exponential model scale and amplitude. It is important to note that in order to compensate for possible rotations and translations of the mapping points, the coordinates of the first level mapping are fixed to the latent space origin, whereas all of the coordinates of the second level mapping are fixed to
, except for the first one. As a result, the number of active latent variable coordinates is equal to:
In practice, the class distinguishes between the fullLatentVariables attribute, which contains the actual latent variables coordinates, and the activeLatentVariables attribute, which contains only the coordinates that can be modified. Additional information can be found in [zhang2020].
Is is important to note that for the sake of simplicity, the categorical variable levels must be represented as integers, ranging from
to
. However, this representation is purely practical, and the actual values assigned to each level have no practical meaning or effect: only the latent variables coordinates have an effect on the covariance value. Moreover, these categorical variables, which are encoded using numerical values, can be of a non-numerical nature (e.g., types of material, architectural choices, colors, etc.).
Finally, for a similar reason, when using this type of kernel when defining a Gaussian process, it is suggested to rely on a constant functional basis: please use the
ConstantBasisFactoryclass.Examples
Create a latent model covariance function with a latent space of dimension 2, for a categorical variable characterized by 3 levels:
>>> import openturns as ot >>> covModel = ot.LatentVariableModel(3, 2) >>> activeCoordinates = [0.1, 0.3, -0.4] >>> covModel.setLatentVariables(activeCoordinates) >>> print(covModel(1, 2)) [[ 0.904837 ]] >>> print(covModel(0, 2)) [[ 0.882497 ]] >>> print(covModel(1, 1)) [[ 1 ]]
- __init__(*args)¶
- activateAmplitude(isAmplitudeActive)¶
Activate/deactivate the amplitude parameters.
In the context of kriging, defines whether the amplitude parameters should be tuned.
- Parameters:
- isAmplitudeActivebool
If
True, all the amplitude parameters are tuned. IfFalse, none of them is tuned.
- activateNuggetFactor(isNuggetFactorActive)¶
Activate/deactivate the nugget factor.
In the context of kriging, defines whether the nugget factor should be tuned.
- Parameters:
- isNuggetFactorActivebool
If
True(respectivelyFalse), the nugget factor is (respectively is not) tuned.
- activateScale(isScaleActive)¶
Activate/deactivate the scale parameters.
In the context of kriging, defines whether the scale parameters should be tuned.
- Parameters:
- isScaleActivebool
If
True, all the scale parameters are tuned. IfFalse, none of them is tuned.
- computeAsScalar(*args)¶
Compute the covariance function for scalar model.
- Parameters:
- s, tfloats
Must have integer values between
and
- Returns:
- covariancefloat
Covariance.
Notes
The method makes sense only if the dimension of the process is
. It evaluates
.
- computeCrossCovariance(*args)¶
Compute the covariance function on two given meshes.
- Parameters:
- Returns:
- crossCovariance
Matrix Cross-covariance matrix of size
, where
and
are the numbers of vertices in firstVertices and secondVertices.
- crossCovariance
Notes
The cross-covariance matrix is the evaluation of the covariance model on both firstVertices and secondVertices.
The result is a
matrix, i.e. a block matrix whose
block is
, where
are the points of firstVertices and
are the points of secondVertices. When
, this is the
matrix with entries
.
- discretize(*args)¶
Discretize the covariance function on a given mesh.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- where
- Returns:
- covarianceMatrix
CovarianceMatrix Covariance matrix
of size
, where
is the number of vertices.
- covarianceMatrix
Notes
Let
be the vertices of the given mesh. The method returns the block covariance matrix
- discretizeAndFactorize(*args)¶
Discretize and factorize the covariance function on a given mesh.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- where
- Returns:
- choleskyFactor
TriangularMatrix Lower triangular Cholesky factor
of the covariance matrix, of size
, such that
, where
is the number of vertices.
- choleskyFactor
Notes
This method discretizes the model on the given
Mesh,RegularGridorSamplewith thediscretize()method and returns its Cholesky factor.
- discretizeAndFactorizeHMatrix(*args)¶
Discretize and factorize the covariance function on a given mesh using HMatrix.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- hmatParam
HMatrixParameters Parameter values for the HMatrix.
- where
- Returns:
- choleskyFactor
HMatrix Lower triangular Cholesky factor
of the covariance matrix, of size
, such that
when the factorization method is
LLt(default), stored in hierarchical format (H-Matrix). With theLUorLDLtmethod, the result holds the factorization computed by that method instead.
- choleskyFactor
Notes
This method is similar to the
discretizeAndFactorize()method. It requires that the library has been compiled with HMAT support. It is helpful for very large discretization sizes because it compresses the data.
- discretizeAndFactorizeHODLRMatrix(*args)¶
Discretize and factorize the covariance function on a given mesh using HODLRMatrix.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- hodlrParam
HODLRMatrixParameters Parameter values for the HODLR matrix.
- where
- Returns:
- choleskyFactor
HODLRMatrix Lower triangular Cholesky factor
of the covariance matrix, of size
, such that
, stored in hierarchical format (HODLR), where
is the number of vertices.
- choleskyFactor
Notes
This method is similar to the
discretizeAndFactorize()method, but stores the result in aHODLRMatrixinstead of a denseTriangularMatrix. It does not require any external library. It is helpful for very large discretization sizes because it compresses the data.
- discretizeHMatrix(*args)¶
Discretize the covariance function on a given mesh using HMatrix.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- hmatParam
HMatrixParameters Parameter values for the HMatrix.
- where
- Returns:
- covarianceMatrix
HMatrix Covariance matrix
of size
, stored in hierarchical format (H-Matrix), where
is the number of vertices.
- covarianceMatrix
Notes
This method is similar to the
discretize()method. It requires that the library has been compiled with HMAT support. It is helpful for very large discretization sizes because it compresses the data.
- discretizeHODLRMatrix(*args)¶
Discretize the covariance function on a given mesh using HODLRMatrix.
- Parameters:
- where
MeshorRegularGridorSample Container of the discretization vertices.
- hodlrParam
HODLRMatrixParameters Parameter values for the HODLR matrix.
- where
- Returns:
- covarianceMatrix
HODLRMatrix Covariance matrix
of size
, stored in hierarchical format (HODLR), where
is the number of vertices.
- covarianceMatrix
Notes
This method is similar to the
discretize()method, but stores the result in aHODLRMatrixinstead of a denseCovarianceMatrix. It is helpful for very large discretization sizes because it compresses the data. It does not require any external library. The result must be factorized with thefactorize()method before being used bysolve()orlogDeterminant().
- discretizeRow(vertices, p)¶
Discretize the covariance function on a given mesh for a specific row.
- Parameters:
- vertices
Sample Container of the discretization vertices
.
- pint,
Row index of the covariance matrix to discretize.
- vertices
- Returns:
- result
Sample Sample of size
and dimension
, whose
-th block of
rows contains the covariance matrix
, for
.
- result
Notes
When
, the result is a sample of size
and dimension 1 with entries
.
- draw(*args)¶
Not yet implemented
- fourthOrderPartial(s, t)¶
Compute the fourth-order spatial derivatives of the
output component of the covariance function.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- fourth
Point Fourth-order derivatives of the
output component
with respect to
, stored as a flat point of size
; for
, index
holds
.
- fourth
- getActiveLatentVariables()¶
Active latent variables accessor.
- Parameters:
- activeLatentVariables
Point Active coordinates of the categorical levels in the latent space. The inactive coordinates are set to 0 (i.e., the first latent variable is projected onto the Euclidean space origin, and the second latent variable can only be located along the first axis).
- activeLatentVariables
- getActiveParameter()¶
Accessor to the active parameter set.
In the context of kriging, it allows one to choose which hyperparameters are tuned.
- Returns:
- active
Indices Indices of the active parameters among the full parameter vector.
- active
- getAmplitude()¶
Get the amplitude parameter
of the covariance function.
- Returns:
- amplitude
Point Amplitude parameter
. Its components are positive.
- amplitude
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getFullLatentVariables()¶
Latent variables accessor.
- Returns:
- activeLatentVariables
Point Coordinates of the categorical levels in the latent space.
- activeLatentVariables
- getFullParameter()¶
Get the full parameters of the covariance function.
- Returns:
- parameter
Point List of the full parameter of the covariance function i.e. the scale parameter
, the the amplitude parameter
, and the latent variables coordinates,
- parameter
- getFullParameterDescription()¶
Get the description of the full parameters of the covariance function.
- Returns:
- description
Description Description of the full parameter vector, in the order returned by
getFullParameter().
- description
- getInputDimension()¶
Get the input dimension of the covariance function.
- Returns:
- inputDimensionint
Dimension
of the index domain
. It is such that
.
- getLatentDimension()¶
Latent dimension accessor.
- Returns:
- latentDimensionint
Dimension of the latent space.
- getLevelNumber()¶
Level number accessor.
- Returns:
- nLevelsint
Number of levels
characterizing the categorical variable.
- getMarginal(*args)¶
Get the marginal covariance model.
- Parameters:
- indexint or sequence of int
Index or indices of the components of the process to keep.
- Returns:
- marginal
CovarianceModel Covariance model restricted to the selected components.
- marginal
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getNuggetFactor()¶
Accessor to the nugget factor.
The nugget factor
is a dimensionless nonnegative parameter which models a noise on the observed values of the process. At
, it replaces the covariance matrix
by
.
- Returns:
- nuggetFactorfloat
Nugget factor
.
- getOutputCorrelation()¶
Get the spatial correlation matrix
of the covariance function.
- Returns:
- spatialCorrelation
CorrelationMatrix Spatial correlation matrix
of size
.
- spatialCorrelation
- getOutputDimension()¶
Get the output dimension of the covariance function.
- Returns:
- outputDimensionint
Dimension
of the process
. It is such that
.
- getParameter()¶
Get the values of the active parameters of the covariance function.
- Returns:
- parameter
Point Values of the
active parameters, in the order given by
getParameterDescription().
- parameter
Notes
The active parameters are selected by
setActiveParameter()among the full parameters returned bygetFullParameter().
- getParameterDescription()¶
Get the description of the active parameters of the covariance function.
- Returns:
- descriptionParam
Description Description of the active parameters, i.e. the components of
getFullParameterDescription()selected bygetActiveParameter().
- descriptionParam
- getScale()¶
Get the scale parameter
of the covariance function.
- Returns:
- scale
Point Scale parameter
used in the covariance function. Its components are positive. For
IsotropicCovarianceModel, the scale has a single component.
- scale
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- isDiagonal()¶
Test whether the model is diagonal.
- Returns:
- isDiagonalbool
Trueif the covariance matrix is diagonal, i.e.
- isParallel()¶
Accessor to the parallel flag.
- Returns:
- isParallelbool
Whether the object is considered thread-safe.
- isStationary()¶
Test whether the model is stationary.
- Returns:
- isStationarybool
Trueif the covariance function is invariant by translation.
Notes
The covariance function is stationary when it depends only on the lag
:
In that case, we note
for
.
- parameterGradient(s, t)¶
Compute the gradient of the covariance function with respect to the active parameters.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- gradient
Matrix Gradient of the covariance function
with respect to the
active parameters
, in the order given by
getParameterDescription(). Its size is. For
and
, row
and column
hold
. The
matrix
associated with each row is thus flattened column by column.
- gradient
- parameterHessian(s, t)¶
Compute the mixed parameter-spatial Hessian of the
output component of the covariance function.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- hessian
Matrix Derivatives of the partial Hessian
of the
output component with respect to the
active parameters
, in the order given by
getParameterDescription(). Its size is. For
and
, row
and column
hold
. The
partial Hessian associated with each row is thus flattened column by column.
- hessian
- partialGradient(s, t)¶
Compute the gradient of the covariance function with respect to the first index
.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- gradient
Matrix Gradient of the covariance function
with respect to
. Its size is
. For
and
, row
and column
hold
. The
matrix
associated with each row is thus flattened column by column.
- gradient
- partialHessian(s, t)¶
Compute the Hessian of the
output component of the covariance function with respect to the first index
.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- hessian
SymmetricMatrix Hessian of the
output component
with respect to
. Its size is
; entry
holds
. The other output components are not differentiated.
- hessian
- setActiveParameter(active)¶
Accessor to the active parameter set.
This method defines which hyperparameters are tuned.
- Parameters:
- activesequence of int
Indices of the active parameters among the full parameter vector.
Notes
The indices refer to the full parameter vector returned by
getFullParameter(). In order to get the position of a parameter known by its name, first call the methodgetFullParameterDescription()and then use the index method of the returnedDescription, as shown in the following example.Examples
For example, we create a
MaternModelcovariance model. By default, only the scale and the amplitude parameters are active and will be estimated. We want to add the estimation of theparameter.
>>> import openturns as ot >>> covModel = ot.MaternModel()
We get the default active parameters description: we can see that the
parameter is not included in the list.
>>> covModel.getParameterDescription() [scale_0,amplitude_0]
We now get the active parameters. The parameter
is not in the list.
>>> active = covModel.getActiveParameter() >>> print(active) [0,2]
We want to search the index associated to the parameter
in the full list of the parameters indices.
>>> activeDesc = covModel.getFullParameterDescription() >>> print(activeDesc) [scale_0,nuggetFactor,amplitude_0,nu] >>> index = activeDesc.index('nu') >>> print(index) 3
Now, we add the index of
in the initial list of active parameters. We sort the active indices by increasing order. Then we update the list of the active parameters.
>>> active = covModel.getActiveParameter() >>> active.add(index) >>> covModel.setActiveParameter(sorted(active))
Check that the parameter
is in the active parameters list!
>>> covModel.getActiveParameter() [0,2,3]
>>> covModel.getFullParameterDescription() [scale_0,nuggetFactor,amplitude_0,nu]
- setAmplitude(amplitude)¶
Set the amplitude parameter
of the covariance function.
- Parameters:
- amplitude
Point Amplitude parameter
to be used in the covariance function. Its size must be equal to
and its components must be positive.
- amplitude
- setFullParameter(parameter)¶
Set the full parameters of the covariance function.
- Parameters:
- parameter
Point List of the full parameter of the covariance function i.e. the scale parameter
, the the amplitude parameter
, and the latent variables coordinates,
- parameter
- setLatentVariables(latentVariablesCoordinates)¶
Number of levels accessor.
- Parameters:
- LatentVariablessequence of float
Active coordinates of the categorical levels in the latent space.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- setNuggetFactor(nuggetFactor)¶
Set the nugget factor for the variance of the observation error.
- Parameters:
- nuggetFactorfloat,
Nugget factor.
- nuggetFactorfloat,
Notes
The nugget factor represents a noise observed in the output values of the process. At
, it replaces the covariance matrix
by
.
Refer to Covariance models to get more details on covariance models and the introduction of a nugget factor, and in particular see equation (5).
- setOutputCorrelation(correlation)¶
Set the spatial correlation matrix
of the covariance function.
- Parameters:
- spatialCorrelation
CorrelationMatrix Spatial correlation matrix
.
- spatialCorrelation
- setParameter(parameter)¶
Set the values of the active parameters of the covariance function.
- Parameters:
- parameter
Point Values of the
active parameters, in the order given by
getParameterDescription().
- parameter
- setScale(scale)¶
Set the scale parameter
of the covariance function.
- Parameters:
- scale
Point Scale parameter
to be used in the covariance function. Its size must be equal to
and its components must be positive.
- scale
- thirdOrderPartial(s, t)¶
Compute the third-order spatial derivatives of the
output component of the covariance function.
- Parameters:
- s, tfloat or sequence of float
Multivariate index
. Each vector has dimension
. Scalars are accepted only if
.
- Returns:
- third
Point Third-order derivatives of the
output component
with respect to
, stored as a flat point of size
; for
, index
holds
.
- third
Examples using the class¶
Gaussian Process Regression: surrogate model with continuous and categorical variables
OpenTURNS