TensorProductExperiment

(Source code, png)

../../_images/TensorProductExperiment.png
class TensorProductExperiment(*args)

Tensor product experiment.

Parameters:
experimentslist of WeightedExperiment

List of n marginal experiments of the tensor product experiment. Each marginal experiment can have arbitrary dimension.

Notes

The tensor product design of experiments (DOE) is based on a collection of marginal multidimensional elementary designs of experiments. It is anisotropic in the sense that each marginal DOE does not necessarily have the same size. Using more points in one component may be useful if we want to get more accurate results in that particular direction.

Furthermore, each marginal DOE does not necessarily have a dimension equal to 1. In this sense, this is a generalization of a classical tensor product DOE.

Let \mathcal{X} \subset \mathbb{R}^{d_x} be the integration domain and let g : \mathcal{X} \rightarrow \mathbb{R}^{d_y} be an integrable function. Let f : \mathcal{X} \rightarrow \mathbb{R} be a probability density function. The tensor product experiment produces an approximation of the integral :

\int_{\mathcal{X}} g(\vect{x}) f(\vect{x}) d\vect{x} 
\approx \sum_{i = 1}^{s_t} w_i g\left(\vect{x}_i\right)

where s_t \in \mathbb{N} is the size of the tensor product design of experiments, w_1, ..., w_{s_t} \in \mathbb{R} are the weights and \vect{x}_1, ..., \vect{x}_{s_t} \in \mathbb{R}^{d_x} are the nodes.

Let n_e \in \mathbb{N} be the number of marginal DOEs. For each marginal DOE index j = 1, ..., n_e, let s_j \in \mathbb{N} be its size, representing the number of nodes in the marginal DOE, and let d_j \in \mathbb{N} be the dimension of the j-th marginal DOE. Let \left\{ Q_{s_j}^{(d_j)} \right\}_{j = 1, ..., n_e} be the collection of marginal DOEs. The dimension of the tensor product experiment is equal to the sum of the dimensions of the marginal DOEs:

d_x = \sum_{j = 1}^{n_e} d_j.

The size of the tensor product experiment is equal to the product of the marginal DOE sizes:

s_t = \prod_{j = 1}^{n_e} s_j.

Let \vect{k} = \left(k_1, ..., k_{n_e}\right) \in (\mathbb{N}^\star)^{n_e} be a multi-index where \mathbb{N}^\star = \{1, 2, ..., \} is the set of positive integers. For any marginal DOE j = 1,..., n_e, let \left\{w_{s_j, k_j} \right\}_{k_j = 1, ..., s_j} be its weights and let \left\{ \vect{x}_{s_j, k_j} \in \mathbb{R}^{d_j} \right\}_{k_j = 1, ..., s_j} be its nodes.

The tensor product quadrature is ([gerstner1998] page 214):

Q^{(d_x)}_{s_t} = Q_{s_1}^{(d_1)} \otimes \cdots \otimes Q_{s_{n_e}}^{(d_{n_e})}

where:

Q_{s_1}^{(d_1)} \otimes \cdots \otimes Q_{s_{n_e}}^{(d_{n_e})} (g) 
= \sum_{k_1 = 1}^{s_1} \cdots \sum_{k_{n_e} = 1}^{s_{n_e}} 
w_{s_1, k_1} \cdots w_{s_{n_e}, k_{n_e}}  
g\left(\vect{x}_{s_1, k_1}, \ldots, \vect{x}_{s_{n_e}, k_{n_e}}\right).

For any multi-index \vect{k} = (k_1, ..., k_{n_e}) \in (\mathbb{N}^\star)^{n_e}, we write

\vect{k} \leq \left(s_1, ..., s_{n_e}\right)

if and only if k_j \leq s_j for j = 1, ..., n_e. This means that each component of the multi-index is less than or equal to its corresponding marginal size. The set of multi-indices such that \vect{k} \leq \left(s_1, ..., s_{n_e}\right) is produced using all possible combinations of the indices with the Tuples class.

The tensor product experiment is:

Q_{s_1}^{(d_1)} \otimes \cdots \otimes Q_{s_{n_e}}^{(d_{n_e})} (g) 
= \sum_{\vect{k} \leq \left(s_1, ..., s_{n_e}\right)}  
w_{\vect{k}} g\left(\vect{x}_{\vect{k}}\right),

where each weight is equal to the product of the marginal elementary weights:

w_{\vect{k}} = \prod_{j = 1}^{n_e} w_{s_j, k_j} \in \mathbb{R}

and each node is equal to the agregation of the marginal elementary nodes:

\vect{x}_{\vect{k}}
= \left(\vect{x}_{s_1, k_1}, \ldots, \vect{x}_{s_{n_e}, k_{n_e}}\right) \in \mathbb{R}^{d_x}.

Examples

In the following example, we tensorize two Gauss-Legendre quadratures, using 3 nodes in the first dimension and 5 nodes in the second.

>>> import openturns as ot
>>> experiment1 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0), [3])
>>> experiment2 = ot.GaussProductExperiment(ot.Uniform(0.0, 1.0), [5])
>>> collection = [experiment1, experiment2]
>>> multivariate_experiment = ot.TensorProductExperiment(collection)
>>> nodes, weights = multivariate_experiment.generateWithWeights()

Marginal DOEs do not necessarily have dimension 1. In the following example, we tensorize two DOEs, where the first one has dimension 2, and the second one has dimension 3.

>>> # Experiment 1 : Uniform * 2 with 3 and 2 nodes.
>>> marginal_sizes_1 = [3, 2]
>>> dimension_1 = len(marginal_sizes_1)
>>> distribution_1 = ot.JointDistribution([ot.Uniform()] * dimension_1)
>>> experiment_1 = ot.GaussProductExperiment(distribution_1, marginal_sizes_1)
>>> # Experiment 2 : Normal * 3 with 2, 2 and 1 nodes.
>>> marginal_sizes_2 = [2, 2, 1]
>>> dimension_2 = len(marginal_sizes_2)
>>> distribution_2 = ot.JointDistribution([ot.Normal()] * dimension_2)
>>> experiment_2 = ot.GaussProductExperiment(distribution_2, marginal_sizes_2)
>>> # Tensor product
>>> collection = [experiment_1, experiment_2]
>>> multivariate_experiment = ot.TensorProductExperiment(collection)
>>> nodes, weights = multivariate_experiment.generateWithWeights()

Methods

generate()

Generate points according to the type of the experiment.

generateWithWeights()

Generate points and their associated weight according to the type of the experiment.

getClassName()

Accessor to the object's name.

getDistribution()

Accessor to the distribution.

getName()

Accessor to the object's name.

getSize()

Accessor to the size of the generated sample.

getWeightedExperimentCollection()

Get the marginals of the experiment.

hasName()

Test if the object is named.

hasUniformWeights()

Ask whether the experiment has uniform weights.

isRandom()

Accessor to the randomness of quadrature.

setDistribution(distribution)

Accessor to the distribution.

setName(name)

Accessor to the object's name.

setSize(size)

Accessor to the size of the generated sample.

setWeightedExperimentCollection(coll)

Set the marginals of the experiment.

__init__(*args)
generate()

Generate points according to the type of the experiment.

Returns:
sampleSample

Points (\inputReal_i)_{i = 1, ..., \sampleSize} of the design of experiments. The sampling method is defined by the type of the weighted experiment.

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> myExperiment = ot.MonteCarloExperiment(ot.Normal(2), 5)
>>> sample = myExperiment.generate()
>>> print(sample)
    [ X0        X1        ]
0 : [  0.608202 -1.26617  ]
1 : [ -0.438266  1.20548  ]
2 : [ -2.18139   0.350042 ]
3 : [ -0.355007  1.43725  ]
4 : [  0.810668  0.793156 ]
generateWithWeights()

Generate points and their associated weight according to the type of the experiment.

Returns:
sampleSample

The points of the design of experiments. The sampling method is defined by the nature of the experiment.

weightsPoint of size \sampleSize

Weights (w_i)_{i = 1, ..., \sampleSize} associated with the points. By default, all the weights are equal to \frac{1}{\sampleSize}.

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> myExperiment = ot.MonteCarloExperiment(ot.Normal(2), 5)
>>> sample, weights = myExperiment.generateWithWeights()
>>> print(sample)
    [ X0        X1        ]
0 : [  0.608202 -1.26617  ]
1 : [ -0.438266  1.20548  ]
2 : [ -2.18139   0.350042 ]
3 : [ -0.355007  1.43725  ]
4 : [  0.810668  0.793156 ]
>>> print(weights)
[0.2,0.2,0.2,0.2,0.2]
getClassName()

Accessor to the object’s name.

Returns:
class_namestr

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

getDistribution()

Accessor to the distribution.

Returns:
distributionDistribution

Distribution of the input random vector.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getSize()

Accessor to the size of the generated sample.

Returns:
sizepositive int

Number \sampleSize of points constituting the design of experiments.

getWeightedExperimentCollection()

Get the marginals of the experiment.

Returns:
colllist of WeightedExperiment

List of the marginals of the experiment.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

hasUniformWeights()

Ask whether the experiment has uniform weights.

Returns:
hasUniformWeightsbool

Whether the experiment has uniform weights.

isRandom()

Accessor to the randomness of quadrature.

Parameters:
isRandombool

Is true if the design of experiments is random. Otherwise, the design of experiment is assumed to be deterministic.

setDistribution(distribution)

Accessor to the distribution.

Parameters:
distributionDistribution

Distribution of the input random vector.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setSize(size)

Accessor to the size of the generated sample.

Parameters:
sizepositive int

Number \sampleSize of points constituting the design of experiments.

setWeightedExperimentCollection(coll)

Set the marginals of the experiment.

Parameters:
colllist of WeightedExperiment

List of the marginals of the experiment.