INPUT MODULE: MARGINALS AND GAUSSIAN COPULA¶

This example showcases how to define a probabilistic input model with or without a copula dependency.

Package imports¶

In [1]:
from uqpylab import sessions

Start a remote UQCloud session¶

In [2]:
# Start the session
mySession = sessions.cloud()
# (Optional) Get a convenient handle to the command line interface
uq = mySession.cli
# Reset the session
mySession.reset()
Processing .
.
 done!

 uqpylab.sessions :: INFO     :: This is UQ[py]Lab, version 1.00, running on https://uqcloud.ethz.ch. 
                                 UQ[py]Lab is free software, published under the open source BSD 3-clause license.
                                 To request special permissions, please contact:
                                  - Stefano Marelli (marelli@ibk.baug.ethz.ch).
                                 A new session (937a563d695b405dae96aa3c94f2ca6c) started.
 uqpylab.sessions :: INFO     :: Reset successful.

Set the random seed for reproducibility¶

In [3]:
uq.rng(100, 'twister');

Probabilistic input model (without dependency)¶

The probabilistic input model consists of two variables:

$X_1 \sim \mathcal{N}(0, 1)$

and

$X_2 \sim \mathcal{B}(1, 3)$

In [4]:
InputOpts = {
    'Marginals': [
        {
            'Type': 'Gaussian',
            'Parameters': [0,1]
        },
        {
            'Type': 'Beta',
            'Parameters': [1,3]
        }
    ]
}

By default, the variables are considered independent.

Create an INPUT object based on the specified marginals:

In [5]:
myInputIndependent = uq.createInput(InputOpts)

Print a report of the INPUT object:

In [6]:
uq.print(myInputIndependent)
==============================================================
Input object name: Input 1
Dimension(M): 2

Marginals:

Index | Name | Type     |  Parameters             | Moments              
--------------------------------------------------------------------------
1     | X1   | Gaussian |  0.000e+00, 1.000e+00   | 0.000e+00, 1.000e+00
2     | X2   | Beta     |  1.000e+00, 3.000e+00   | 2.500e-01, 1.936e-01


Copula:

Type: Independent
Dimension: 2
Variables coupled: [1 2]
==============================================================

Probabilistic input model (with dependency: Gaussian copula)¶

The marginal distributions of the probabilistic input model are already defined inside the structure InputOpts. A dependency following a Gaussian copula is added as follows:

In [7]:
InputOpts['Copula'] = {
    'Type': 'Gaussian',
    'RankCorr': [[1, 0.8],[0.8, 1]] # the Spearman corr. matrix
}

Create an INPUT object based on the specified marginals and copula:

In [8]:
myInputDependent = uq.createInput(InputOpts)

Print a report of the INPUT object:

In [9]:
uq.print(myInputDependent)
==============================================================
Input object name: Input 2
Dimension(M): 2

Marginals:

Index | Name | Type     |  Parameters             | Moments              
--------------------------------------------------------------------------
1     | X1   | Gaussian |  0.000e+00, 1.000e+00   | 0.000e+00, 1.000e+00
2     | X2   | Beta     |  1.000e+00, 3.000e+00   | 2.500e-01, 1.936e-01


Copula:

Type: Gaussian
Dimension: 2
Variables coupled: [1 2]
Parameters:
	[+1.0000 +0.8135 ;
	 +0.8135 +1.0000 ]

==============================================================

Comparison of the input models¶

Each of the generated INPUT objects can be quickly visualized using the function uq.display.

For the independent INPUT object:

In [10]:
uq.display(myInputIndependent);

For the dependent INPUT object:

In [11]:
uq.display(myInputDependent);

Terminate the remote UQCloud session¶

In [12]:
mySession.quit()
 uqpylab.sessions :: INFO     :: Session 937a563d695b405dae96aa3c94f2ca6c terminated.
Out[12]:
True