INVERSION: SAMPLING FREE INVERSION¶

In this example, we use sampling-free approaches to solve again the problem from |01-Beam|. The two approaches we compare are spectral likelihood expansions (SLE) and Stochastic spectral likelihood embedding (SSLE).

References:

  • Wagner, P.-R., Marelli, S., Sudret, B., Bayesian model inversion using stochastic spectral embedding, Journal of Computational Physics, 436:110141(2021). DOI: <https://doi.org/10.1016/j.jcp.2021.110141 10.1016/j.jcp.2021.110141>
  • Marelli, S., Wagner, P.-R., Lataniotis, C., Sudret, B., Stochastic spectral embedding, International Journal for Uncertainty Quantification, 11(2):25–47(2021). DOI: <https://doi.org/10.1615/Int.J.UncertaintyQuantification.2020034395 10.1615/Int.J.UncertaintyQuantification.2020034395>
  • Nagel, J., Sudret, B., Spectral likelihood expansions for Bayesian inference, Journal of Computational Physics, 309:267-294(2016). DOI: <https://doi.org/10.1016/j.jcp.2015.12.047 10.1016/j.jcp.2015.12.047>

Package imports¶

In [1]:
from uqpylab import sessions
import numpy as np
from IPython.display import Image

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

Set the random seed for reproducibility¶

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

Setting up inverse problem¶

The model setup is identical to |01-Beam|. For further details, refer to the original example.

Forward model¶

Define the forward model as a UQ[py]Lab MODEL object:

In [4]:
ModelOpts = {
    'Type' : 'Model',
    'mString': '(5/32)*(X(:, 5).*X(:, 3).^4)./(X(:, 4).*X(:, 1).*X(:, 2).^3)',
    'isVectorized': True
}
In [5]:
myForwardModel = uq.createModel(ModelOpts)

Prior distribution¶

Specify these distributions as an INPUT object:

In [6]:
PriorOpts = {
  "Marginals": [
    {
      "Name": "b", # beam width
      "Type": "Constant",
      "Parameters": [0.15], # (m)
    },
    {
      "Name": "h", # beam height
      "Type": "Constant",
      "Parameters": [0.3], # (m)
    },
    {
      "Name": "L", # beam length
      "Type": "Constant",
      "Parameters": [5], # (m) 
    },
    {
      "Name": "E", # Young's modulus
      "Type": "LogNormal",
      "Moments": [30e9,4.5e9] # (MPa)
    },
    {
      "Name": "p",           # uniform load
      "Type": "Gaussian",
      "Moments": [12000,600] # (kN/m)
    }
  ]
}
In [7]:
myPriorDist = uq.createInput(PriorOpts)

Measurement data¶

The data is stored in the column vector y:

In [8]:
myData = {
    "y": (np.array([12.84, 13.12, 12.13, 12.19, 12.67])/1000).tolist(),
    "Name": "Mid-span deflection",
}

Discrepancy model¶

We use the default discrepancy model set up by UQ[py]Lab.

Assign Bayesian options¶

To initialize the Bayesian analysis, explicitly assign the following options to the |BayesOpts| dictionary:

In [9]:
BayesOpts = {
    "Type" : "Inversion",
    "Data" : myData,
}

Spectral likelihood expansion (SLE)¶

The first sampling free approach we test here is SLE proposed by Nagel and Sudret (2016). In this approach, the likelihood function is approximated with a PCE constructed with the PCE module of UQ[py]Lab.

Specify SLE as the solver:

In [10]:
SLESolver = {
    'Type': 'SLE',
}

BayesOpts['Solver'] = SLESolver

The BayesOpts['Solver']['SLE'] key-value pair then accepts further PCE-specific options. To set the experimental design size to 1000, the following should be specified:

In [11]:
BayesOpts['Solver']['SLE'] = {
    'ExpDesign': {
        'NSamples': 1000
    }
}

Run the Bayesian inversion analysis:

In [12]:
myBayesianAnalysis_SLE = uq.createAnalysis(BayesOpts)
Processing .
 done!

Print out a report of the results:

In [13]:
uq.print(myBayesianAnalysis_SLE)
%----------------------- Inversion output -----------------------%
   Number of calibrated model parameters:         2
   Number of non-calibrated model parameters:     3

   Number of calibrated discrepancy parameters:   1

%------------------- Data and Discrepancy
%  Data-/Discrepancy group 1:
   Number of independent observations:            5

   Discrepancy:
      Type:                                       Gaussian
      Discrepancy family:                         Scalar
      Discrepancy parameters known:               No

   Associated outputs:
      Model 1: 
         Output dimensions:                       1

%------------------- Solver
   Solution method:                               SLE

%------------------- Evidence
   Evidence:                                      8.446214e+09

%------------------- Point estimate
----------------------------------------
| Parameter | Mean    | Parameter Type |
----------------------------------------
| E         | 2.5e+10 | Model          |
| p         | 1.2e+04 | Model          |
| Sigma2    | 1.7e-05 | Discrepancy    |
----------------------------------------




A graphical representation of the results is expected to be released soon.

Stochastic spectral likelihood embedding (SSLE)¶

% The second sampling free approach we test here is SSLE proposed by Wagner (2021). In this approach, the likelihood function is approximated with a SSE constructed with the SSE module of UQ[py]Lab.

Specify SSLE as the solver:

In [14]:
SSLESolver = {
    'Type': 'SSLE',
}

BayesOpts['Solver'] = SSLESolver

The BayesOpts['Solver']['SSLE'] key-value pair then accepts further SSE-specific options. To set the experimental design size to 1000, with sequential sample enrichment of 50 samples per refinement step, the following should be specified:

In [15]:
BayesOpts['Solver']['SSLE'] = {
    'ExpDesign': {
        'NSamples': 1000,
        'NEnrich': 50
    }
}
In [16]:
BayesOpts['Solver']['SSLE']
Out[16]:
{'ExpDesign': {'NSamples': 1000, 'NEnrich': 50}}

Specify the adaptive polynomial degree of the residual expansions:

In [17]:
BayesOpts['Solver']['SSLE']['ExpOptions'] = {
    'Degree': [0, 1, 2]
}

Run the Bayesian inversion analysis:

In [18]:
myBayesianAnalysis_SSLE = uq.createAnalysis(BayesOpts)
Processing .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
 done!

Print out a report of the results:

In [19]:
uq.print(myBayesianAnalysis_SSLE)
%----------------------- Inversion output -----------------------%
   Number of calibrated model parameters:         2
   Number of non-calibrated model parameters:     3

   Number of calibrated discrepancy parameters:   1

%------------------- Data and Discrepancy
%  Data-/Discrepancy group 1:
   Number of independent observations:            5

   Discrepancy:
      Type:                                       Gaussian
      Discrepancy family:                         Scalar
      Discrepancy parameters known:               No

   Associated outputs:
      Model 1: 
         Output dimensions:                       1

%------------------- Solver
   Solution method:                               SSLE

%------------------- Evidence
   Evidence:                                      1.017576e+10

%------------------- Point estimate
----------------------------------------
| Parameter | Mean    | Parameter Type |
----------------------------------------
| E         | 2.4e+10 | Model          |
| p         | 1.2e+04 | Model          |
| Sigma2    | 2.8e-06 | Discrepancy    |
----------------------------------------




A graphical representation of the results is expected to be released soon.

Terminate the remote UQCloud session¶

In [20]:
mySession.quit()
 uqpylab.sessions :: INFO     :: Session 7247e6c6879743798994906dafd64203 terminated.
Out[20]:
True