RELIABILITY: ASYNCHRONOUS ACTIVE LEARNING¶

This example showcases asynchronous learning in UQ[py]Lab. This feature is useful when the user wishes to carry out the required model evaluations outside of UQ[py]Lab.

In this example, active learning is carried out without the definition of a computational model. UQ[py]Lab therefore only returns the model evaluations required to enrich the experimental design, without executing them. The user can perform their evaluation outside UQ[py]Lab and/or python, and resume the analysis once they become available.

Package imports¶

In [1]:
from uqpylab import sessions
import numpy as np

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 (05c1f45fed224dff824417c42f047374) started.
 uqpylab.sessions :: INFO     :: Reset successful.

Set the random seed for reproducibility¶

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

PROBABILISTIC INPUT MODEL¶

The probabilistic input model consists of two independent and identically-distributed standard Gaussian random variables:

$$X_i \sim \mathcal{N}(0, 1), \quad i = 1, 2$$

Specify the probabilistic model for the two input random variables

In [4]:
InputOpts = {
    "Marginals": [
        {"Name": "X1",               
         "Type": "Gaussian",
         "Parameters": [0, 1]
        },
        {"Name": "X2",
         "Type": "Gaussian",
         "Parameters": [0, 1]
        }
    ]
}

Create the INPUT object based on the specified marginals:

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

STRUCTURAL RELIABILITY¶

Failure event is defined as $g(\mathbf{x}) \leq 0$. The failure probability is then defined as $P_f = P[g(\mathbf{x})\leq 0]$.

In this example, the limit-state function g is not defined in UQLab. Instead, the samples to evaluate to enrich the experimental design $x^\ast$ are returned by the active learning algorithm. The user then evaluates them externally before resuming the analysis. For illustration purposes, only 3 iterations of the algorithm are performed here.

Initial set-up¶

Select the Reliability module and the active learning method

In [6]:
ALROptions = {
    "Type": "Reliability",
    "Method": "ALR"
}

Specify the size of the iniitial experimental design

In [7]:
ALROptions["ALR"] = {
    "IExpDesign": {
        "N": 4
    }
} 

Enable the asynchronous learning feature

In [8]:
ALROptions["Async"] = {
    "Enable": True
}

Allow asynchronous learning also for the initial experimental design

In [9]:
ALROptions["Async"]["InitED"] = True

Run the active learning reliability analysis

In [10]:
myALRAnalysis = uq.createAnalysis(ALROptions)

The execution stops right before the initial experimental design is evaluated

Evaluating the initial ED¶

This first set of samples consists in the 4 initial experimental design points.
They are saved in myALRAnalysis["Results"]["NextSample"].

In [11]:
Xnext = np.array(myALRAnalysis["Results"]["NextSample"])
Ynext = 2.5 - (Xnext[:,0]+ Xnext[:,1])/np.sqrt(2) + 0.1 * (Xnext[:,0] - Xnext[:,1])**2 

Resume the analysis by submitting the newly evaluated samples

In [12]:
myALRAnalysis = uq.resumeAnalysis(Ynext.tolist())
Processing .
 done!

Resuming the analysis¶

The next sample is retrieved and evaluted again

In [13]:
Xnext = np.array(myALRAnalysis["Results"]["NextSample"], ndmin=2)
Ynext = 2.5 - (Xnext[:,0]+ Xnext[:,1])/np.sqrt(2) + 0.1 * (Xnext[:,0] - Xnext[:,1])**2 

Resume the analysis by submitting the newly evaluated samples

In [14]:
myALRAnalysis = uq.resumeAnalysis(Ynext.tolist())
Processing .
 done!

Retrieve the next sample to evalute

In [15]:
Xnext = np.array(myALRAnalysis["Results"]["NextSample"], ndmin=2)
Ynext = 2.5 - (Xnext[:,0]+ Xnext[:,1])/np.sqrt(2) + 0.1 * (Xnext[:,0] - Xnext[:,1])**2 

Resume the analysis by submitting the newly evaluated samples

In [16]:
myALRAnalysis = uq.resumeAnalysis(Ynext.tolist())
Processing .
 done!

In this example, convergence has not yet been achieved. However, it is possible to print and display the current state of the analysis.

Print out a report of the results

In [17]:
uq.print(myALRAnalysis)
---------------------------------------------------
Active learning reliability
---------------------------------------------------
Pf               1.3546e-03       
Beta             2.9989           
CoV              0.0194           
ModelEvaluations 6                
PfCI             [1.3032e-03 1.4060e-03]
BetaCI           [2.9876e+00 3.0107e+00]
PfMinus/Plus     [1.2186e-03 1.5154e-03]
---------------------------------------------------


Visualize the results of the analysis

In [18]:
uq.display(myALRAnalysis);

Terminate the remote UQCloud session¶

In [19]:
mySession.quit()
 uqpylab.sessions :: INFO     :: Session 05c1f45fed224dff824417c42f047374 terminated.
Out[19]:
True